From 212b91ed9dda8bdc3b5ea6af3d184aeeec07ba18 Mon Sep 17 00:00:00 2001 From: Aman Khantaal Date: Tue, 28 Mar 2017 12:24:13 +0530 Subject: [PATCH] Fix/#1267 Add detail table to resource-detail page. --- cadasta/core/static/css/resources.scss | 12 ++++++ cadasta/resources/models.py | 32 ++++++++++++++++ .../templates/resources/project_detail.html | 38 ++++++++++++++++--- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/cadasta/core/static/css/resources.scss b/cadasta/core/static/css/resources.scss index 8e03337bb..17f569198 100644 --- a/cadasta/core/static/css/resources.scss +++ b/cadasta/core/static/css/resources.scss @@ -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; +} diff --git a/cadasta/resources/models.py b/cadasta/resources/models.py index 0662836de..1919eb68c 100644 --- a/cadasta/resources/models.py +++ b/cadasta/resources/models.py @@ -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 @@ -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): diff --git a/cadasta/templates/resources/project_detail.html b/cadasta/templates/resources/project_detail.html index 398c7f481..efe339a77 100644 --- a/cadasta/templates/resources/project_detail.html +++ b/cadasta/templates/resources/project_detail.html @@ -28,18 +28,44 @@

{% trans "Resource detail" %}

- -

+

{% trans "RESOURCE" %}
+

{{ resource.name }} {% if resource.archived %} {% trans "Deleted" %} {% endif %} -

-

{{ resource.description }}
{{ resource.original_file }}

-

{% blocktrans with date=resource.last_updated user=resource.contributor.full_name %}Added on {{ date }} by {{ user }}{% endblocktrans %}

+ + +

{{ resource.description }}


+ + + + + + + + + + + + + + + {% if 'image' in resource.mime_type and 'tif' not in resource.mime_type %} + + + + + {% endif %} + + + + + +
File name:{{ resource.file_name }}
File type:{{ resource.file_type }}
File size:{{ resource.file_size }}
Dimensions:{{ resource.image_dimensions.0 }} x {{ resource.image_dimensions.1 }}
Uploaded on:{% blocktrans with date=resource.last_updated user=resource.contributor.full_name %}Added on {{ date }} by {{ user }}{% endblocktrans %}