Commits

Yohan Boniface  committed 21626c6

Add PictrogramJsonList view (cf #22)

  • Participants
  • Parent commits 2bbd6f1

Comments (0)

Files changed (4)

File leaflet_storage/base_models.py

     attribution = models.CharField(max_length=300)
     pictogram = models.ImageField(upload_to="pictogram")
 
+    @property
+    def json(self):
+        return {
+            "id": self.pk,
+            "attribution": self.attribution,
+            "name": self.name,
+            "src": self.pictogram.url
+        }
+
 
 class Category(NamedModel):
     """
         choices=ICON_CLASS,
         max_length=32,
         default="Default",
-        verbose_name="icon type"
+        verbose_name=_("icon type"),
+        help_text=_("Choose the style of the marker.")
     )
     display_on_load = models.BooleanField(
         default=False,

File leaflet_storage/forms.py

     class Meta:
         model = Category
         widgets = {
-            "map": forms.HiddenInput()
+            "map": forms.HiddenInput(),
+            "icon_class": forms.HiddenInput(),
+            "pictogram": forms.HiddenInput()
         }
 
 

File leaflet_storage/urls.py

     url(r'^polygon/json/(?P<pk>[\d]+)/$', views.PolygonGeoJSON.as_view(), name='polygon_geojson'),
     url(r'^map/(?P<map_id>[\d]+)/export/iframe/$', views.EmbedMap.as_view(), name='map_embed'),
     url(r'^map/(?P<map_id>[\d]+)/infos/caption/$', views.MapInfos.as_view(), name='map_infos'),
+    url(r'^pictogram/json/$', views.PictogramJsonList.as_view(), name='pictogram_list_json'),
 )
 urlpatterns += decorated_patterns('', login_required,
     url(r'^map/add/$', views.QuickMapCreate.as_view(), name='map_add'),

File leaflet_storage/views.py

 from django.contrib.gis.geos import GEOSGeometry
 from django.core.urlresolvers import reverse_lazy
 from django.utils.translation import ugettext as _
-from django.views.generic.list import BaseListView
+from django.views.generic.list import BaseListView, ListView
 from django.views.generic.base import TemplateView
 from django.contrib.auth import logout as do_logout
 from django.template.loader import render_to_string
 from vectorformats.formats import django, geojson
 
 from .models import (Map, Marker, Category, Polyline, TileLayer,
-                     MapToTileLayer, Polygon)
+                     MapToTileLayer, Polygon, Pictogram)
 from .utils import get_uri_template
 from .forms import (QuickMapCreateForm, UpdateMapExtentForm, CategoryForm,
                     UploadDataForm, UpdateMapPermissionsForm, MapSettingsForm,
 
 
 # ############## #
+#     Picto      #
+# ############## #
+
+class PictogramJsonList(ListView):
+    model = Pictogram
+
+    def render_to_response(self, context, **response_kwargs):
+        content = [p.json for p in Pictogram.objects.all()]
+        return simple_json_response(pictogram_list=content)
+
+
+# ############## #
 #     Generic    #
 # ############## #