Skip to content

Commit

Permalink
Implement GNIP curated-thumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Aug 14, 2019
1 parent fd69f9e commit e7dcab4
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 445 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/usage/managing_layers/layer_editing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ Setting the Layer Thumbnail

*The Layer Editing panel*

It is also possible to manually upload a thumbnail by using the :guilabel:`Upload` button of the *Layer Editing* panel.
Using the "Upload Thumbnail" page it is possible to enable the automatically generated thumbnail or upload an image to be used in place of it.

.. figure:: img/upload_thumbnail.png
:align: center

*The Upload Thumbnail panel*


Replacing the Layer
-------------------

Expand Down
13 changes: 13 additions & 0 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,10 @@ def format_objects(self, objects):

formatted_obj['gtype'] = self.dehydrate_gtype(bundle)

# replace thumbnail_url with curated_thumbs
if hasattr(obj, 'curatedthumbnail'):
formatted_obj['thumbnail_url'] = obj.curatedthumbnail.img_thumbnail.url

# put the object on the response stack
formatted_objects.append(formatted_obj)
return formatted_objects
Expand Down Expand Up @@ -982,6 +986,11 @@ def format_objects(self, objects):
layer, fields=map_layer_fields)
formatted_layers.append(formatted_map_layer)
formatted_obj['layers'] = formatted_layers

# replace thumbnail_url with curated_thumbs
if hasattr(obj, 'curatedthumbnail'):
formatted_obj['thumbnail_url'] = obj.curatedthumbnail.img_thumbnail.url

formatted_objects.append(formatted_obj)
return formatted_objects

Expand Down Expand Up @@ -1032,6 +1041,10 @@ def format_objects(self, objects):
formatted_obj['store_type'] = 'dataset'
formatted_obj['online'] = True

# replace thumbnail_url with curated_thumbs
if hasattr(obj, 'curatedthumbnail'):
formatted_obj['thumbnail_url'] = obj.curatedthumbnail.img_thumbnail.url

formatted_objects.append(formatted_obj)
return formatted_objects

Expand Down
9 changes: 8 additions & 1 deletion geonode/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
HierarchicalKeyword,
MenuPlaceholder,
Menu,
MenuItem
MenuItem,
CuratedThumbnail,
)
from django.http import HttpResponseRedirect

Expand Down Expand Up @@ -266,6 +267,11 @@ class MenuItemAdmin(admin.ModelAdmin):
list_display = ('title', 'menu', 'order', 'blank_target', 'url')


class CuratedThumbnailAdmin(admin.ModelAdmin):
model = CuratedThumbnail
list_display = ('id', 'resource', 'img', 'img_thumbnail')


admin.site.register(TopicCategory, TopicCategoryAdmin)
admin.site.register(Region, RegionAdmin)
admin.site.register(SpatialRepresentationType, SpatialRepresentationTypeAdmin)
Expand All @@ -278,6 +284,7 @@ class MenuItemAdmin(admin.ModelAdmin):
admin.site.register(MenuPlaceholder, MenuPlaceholderAdmin)
admin.site.register(Menu, MenuAdmin)
admin.site.register(MenuItem, MenuItemAdmin)
admin.site.register(CuratedThumbnail, CuratedThumbnailAdmin)


class ResourceBaseAdminForm(ModelForm):
Expand Down
10 changes: 9 additions & 1 deletion geonode/base/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from django.conf import settings
from django.core import validators
from django.forms import models
from django.forms import ModelForm
from django.forms.fields import ChoiceField
from django.forms.utils import flatatt
from django.utils.html import format_html
Expand All @@ -41,7 +42,7 @@
from bootstrap3_datetime.widgets import DateTimePicker
from modeltranslation.forms import TranslationModelForm

from geonode.base.models import HierarchicalKeyword, TopicCategory, Region, License
from geonode.base.models import HierarchicalKeyword, TopicCategory, Region, License, CuratedThumbnail
from geonode.people.models import Profile
from geonode.base.enumerations import ALL_LANGUAGES
from django.contrib.auth.models import Group
Expand Down Expand Up @@ -510,3 +511,10 @@ class BatchEditForm(forms.Form):
choices=LANGUAGES,
)
keywords = forms.CharField(required=False)


class CuratedThumbnailForm(ModelForm):

class Meta:
model = CuratedThumbnail
fields = ['img']
24 changes: 24 additions & 0 deletions geonode/base/migrations/0028_curatedthumbnail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-08-14 14:10
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('base', '0027_auto_20170801_1228_squashed_0037_auto_20190222_1347'),
]

operations = [
migrations.CreateModel(
name='CuratedThumbnail',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('img', models.ImageField(upload_to=b'curated_thumbs')),
('resource', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='base.ResourceBase')),
],
),
]
12 changes: 12 additions & 0 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
from polymorphic.models import PolymorphicModel
from polymorphic.managers import PolymorphicManager
from agon_ratings.models import OverallRating
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill

from geonode.base.enumerations import ALL_LANGUAGES, \
HIERARCHY_LEVELS, UPDATE_FREQUENCIES, \
Expand Down Expand Up @@ -1409,6 +1411,16 @@ class Meta:
ordering = ['order']


class CuratedThumbnail(models.Model):
resource = models.OneToOneField(ResourceBase)
img = models.ImageField(upload_to='curated_thumbs')
# TOD read thumb size from settings
img_thumbnail = ImageSpecField(source='img',
processors=[ResizeToFill(240, 180)],
format='PNG',
options={'quality': 60})


def resourcebase_post_save(instance, *args, **kwargs):
"""
Used to fill any additional fields after the save.
Expand Down
47 changes: 47 additions & 0 deletions geonode/base/templates/base/thumbnail_upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends "geonode_base.html" %}
{% load i18n %}


{% block body_class %}{% trans "Upload a Thumbnail" %}{% endblock %}

{% block body_outer %}
{% if error %}
<div class="alert alert-error">{{ error }}</div>
{% endif %}

<div class="page-header">
<h2>{% trans "Upload a Thumbnail" %}</h2>
</div>

<div class="row">

<div class="col-md-4">

<!-- current uploaded thumb -->
{% if resource.curatedthumbnail %}
<h5>Current thumbnail</h5>
<img src='{{ resource.curatedthumbnail.img_thumbnail.url }}'></img>
<form method="POST" class="post-form">
{% csrf_token %}
<button type="submit" class="save btn btn-default" name="remove-thumb">
{% trans "Remove (and use auto generated thumbnail)" %}</button>
</form>
{% endif %}

<!-- upload form -->
<form method="POST" enctype="multipart/form-data" class="post-form">
{% csrf_token %}
{{ form.img }}
<button type="submit" class="save btn btn-default" name="upload-thumb">{% trans "Upload" %}</button>
</form>

</div>

<div class="col-md-4">
<h5>Auto generated thumbnail</h5>
<img src='{{ resource.thumbnail_url }}'></img>
</div>

</div>

{% endblock %}

0 comments on commit e7dcab4

Please sign in to comment.