Skip to content

Commit

Permalink
Fix/Cadasta#1267 Add detail table to resource-detail page.
Browse files Browse the repository at this point in the history
  • Loading branch information
khantaalaman committed Mar 28, 2017
1 parent 378ea3a commit 212b91e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
12 changes: 12 additions & 0 deletions cadasta/core/static/css/resources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@ ul.resource-actions > li {
border-left: 1px solid $table-border-color;
}
}

table.resource-description {
width: 50%;
}

table.resource-description > tbody > tr > td {
padding: 5px 5px;
}

h2.resource-heading {
color: #0e3o5e;
}
32 changes: 32 additions & 0 deletions cadasta/resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from jsonattrs.fields import JSONAttributeField
from simple_history.models import HistoricalRecords
from tutelary.decorators import permissioned_model
from PIL import Image

from . import messages
from .exceptions import InvalidGPXFile
Expand Down Expand Up @@ -138,6 +139,37 @@ def get_absolute_url(self):
},
))

@property
def file_size(self):
"""
this function will return the file size
"""
file_name = self.file.url.split('/')[-1]
name = file_name[:file_name.rfind('.')]
ext = file_name.split('.')[-1]
url = os.path.join(settings.MEDIA_ROOT,
's3', 'uploads', 'resources',
name + '.' + ext)
file_info = os.stat(url)
size = file_info.st_size
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if size < 1024.0:
return "%3.1f %s" % (size, x)
size /= 1024.0
return size

@property
def image_dimensions(self):
file_name = self.file.url.split('/')[-1]
name = file_name[:file_name.rfind('.')]
ext = file_name.split('.')[-1]
url = os.path.join(settings.MEDIA_ROOT,
's3', 'uploads', 'resources',
name + '.' + ext)
im = Image.open(url)
self._image_dimensions = list(im.size)
return self._image_dimensions


@receiver(models.signals.pre_save, sender=Resource)
def archive_file(sender, instance, **kwargs):
Expand Down
38 changes: 32 additions & 6 deletions cadasta/templates/resources/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,44 @@ <h2 class="short">{% trans "Resource detail" %}</h2>
</div>
<div class="panel panel-default">
<div class="panel-body">
<img src="{{ resource.thumbnail }}" class="thumb-128">
<h4>
<h5 class="short" style="margin-top: 0px; margin-bottom: 0px;">{% trans "RESOURCE" %}</h5>
<h2 class="resource-heading">
{{ resource.name }}
{% if resource.archived %}
<span class="label label-danger">{% trans "Deleted" %}</span>
{% endif %}
</h4>
<p>{{ resource.description }}<br><strong>{{ resource.original_file }}</strong></p>
<p class="small">{% blocktrans with date=resource.last_updated user=resource.contributor.full_name %}Added on {{ date }} by {{ user }}{% endblocktrans %}</p>
</h2>
<img src="{{ resource.thumbnail }}" class="thumb-128">
<h4>{{ resource.description }}</h4><br>
<table class="table resource-description">
<tbody>
<tr>
<td>File name:</td>
<td>{{ resource.file_name }}</td>
</tr>
<tr>
<td>File type:</td>
<td>{{ resource.file_type }}</td>
</tr>
<tr>
<td>File size:</td>
<td>{{ resource.file_size }}</td>
</tr>
{% if 'image' in resource.mime_type and 'tif' not in resource.mime_type %}
<tr>
<td>Dimensions:</td>
<td>{{ resource.image_dimensions.0 }} x {{ resource.image_dimensions.1 }}</td>
</tr>
{% endif %}
<tr>
<td>Uploaded on:</td>
<td>{% blocktrans with date=resource.last_updated user=resource.contributor.full_name %}Added on {{ date }} by {{ user }}{% endblocktrans %}</td>
</tr>
</tbody>
</table>
</div>
<div class="panel-footer panel-buttons">
<a href="{{ resource.file.url }}" class="btn btn-primary" download="{{ resource.original_file }}">{% trans "Download" %}</a>
<a href="{{ resource.file.url }}" class="btn btn-primary" download="{{ resource.original_file }}">{% trans "Download file" %} ({{ resource.file_size }})</a>
</div>
</div>

Expand Down

0 comments on commit 212b91e

Please sign in to comment.