Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added endpoint to persist and return layer styles #1756

Merged
merged 5 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions mapstory/mapstories/migrations/0006_auto_20181018_1233.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mapstories', '0005_auto_20180928_1218'),
]

operations = [
migrations.CreateModel(
name='LayerStyle',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('style_id', models.TextField()),
('style', models.TextField()),
('map_story', models.ForeignKey(to='mapstories.MapStory')),
],
),
migrations.AlterUniqueTogether(
name='layerstyle',
unique_together=set([('style_id', 'map_story')]),
),
]
9 changes: 9 additions & 0 deletions mapstory/mapstories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,12 @@ class Meta:
signals.post_init.connect(default_is_published, sender=MapStory)
signals.post_init.connect(default_is_published, sender=Map)
db.models.signals.post_save.connect(mapstory_map_post_save, sender=Map)


class LayerStyle(models.Model):
class Meta:
unique_together = (("style_id", "map_story"),)

style_id = models.TextField()
map_story = models.ForeignKey(MapStory, on_delete=models.CASCADE)
style = models.TextField()
7 changes: 6 additions & 1 deletion mapstory/mapstories/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from geonode.maps.views import new_map

from .views import (composer_new_view, delete_mapstory, map_detail,
mapstory_view, save_mapstory, story_generate_thumbnail)
mapstory_view, save_mapstory, story_generate_thumbnail, style_view)

urlpatterns = [
url(r'^mapstories/save$', save_mapstory, name='save_mapstory'),
Expand All @@ -20,6 +20,11 @@
url(r'^story/(?P<slug>[-\w]+)/embed$',
mapstory_view, name='mapstory_view'),

# Style
url(r'^style/(?P<story_id>[^/]+)/(?P<style_id>[^/]+)$',
style_view, name='style_view'),


# Composer
url(r'^story/(?P<slug>[-\w]+)/draft$',
composer_new_view, {'template': 'composer_new/composer.html'}, name='composer-view'),
Expand Down
24 changes: 22 additions & 2 deletions mapstory/mapstories/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.urlresolvers import reverse
from django.db import transaction
from django.db.models import F
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.shortcuts import render, render_to_response
from django.template import RequestContext
from django.views.decorators.clickjacking import xframe_options_exempt
Expand All @@ -31,7 +31,7 @@
from mapstory.search.utils import update_es_index
from mapstory.thumbnails.tasks import create_mapstory_thumbnail_tx_aware

from .models import Map, MapStory, StoryFrame, StoryPin
from .models import Map, MapStory, StoryFrame, StoryPin, LayerStyle
from .utils import datetime_to_seconds, parse_date_time


Expand Down Expand Up @@ -378,3 +378,23 @@ def map_detail(request, slug, snapshot=None, template='maps/map_detail.html'):
request.user, map_obj)

return render(request, template, context=context_dict)


def style_view(request, story_id, style_id):
map_story = MapStory.objects.get(pk=story_id)
if request.method == 'GET':
layer_style = LayerStyle.objects.filter(map_story=map_story, style_id=style_id)
if layer_style.exists():
return HttpResponse(layer_style[0].style)

return HttpResponseNotFound()

layer_style = LayerStyle.objects.filter(map_story=map_story, style_id=style_id)
if not layer_style.exists():
LayerStyle(style_id=style_id, map_story=map_story, style=request.body).save()
return HttpResponse(json.dumps({'success': True}))

layer_style = layer_style[0]
layer_style.style = request.body
layer_style.save()
return HttpResponse(json.dumps({'success': True}))