diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-04-06 21:08:39 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-04-06 21:09:26 +0200 |
commit | 1d03951916abe35062d16336f6cf80c989004493 (patch) | |
tree | fb18a55495f1bbf3cd181f912ec3bee6ce94ade4 /chimere/models.py | |
parent | 2f843cc211968c135bd33ffa8838f5cf2d2b3129 (diff) | |
download | Chimère-1d03951916abe35062d16336f6cf80c989004493.tar.bz2 Chimère-1d03951916abe35062d16336f6cf80c989004493.zip |
Add public polygon edition form - import public edition forms
Diffstat (limited to 'chimere/models.py')
-rw-r--r-- | chimere/models.py | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/chimere/models.py b/chimere/models.py index f27562b..5d0b93c 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -494,8 +494,8 @@ class ImporterKeyCategories(models.Model): class GeographicItem(models.Model): - name = models.TextField(_(u"Name")) categories = SelectMultipleField(SubCategory) + name = models.TextField(_(u"Name")) submiter_session_key = models.CharField( _(u"Submitter session key"), blank=True, null=True, max_length=40) submiter_name = models.CharField(_(u"Submitter name or nickname"), @@ -664,6 +664,16 @@ class GeographicItem(models.Model): def all_properties(cls): return [pm for pm in PropertyModel.objects.all()] + def get_init_multi(self): + multis = [forms.model_to_dict(multi) + for multi in self.multimedia_files.all()] + return multis + + def get_init_picture(self): + picts = [forms.model_to_dict(pict) + for pict in self.pictures.all()] + return picts + def property_setter(cls, propertymodel): def setter(self, value): @@ -697,16 +707,6 @@ class Marker(GeographicItem): ordering = ('status', 'name') verbose_name = _(u"Point of interest") - def get_init_multi(self): - multis = [forms.model_to_dict(multi) - for multi in self.multimedia_files.all()] - return multis - - def get_init_picture(self): - picts = [forms.model_to_dict(pict) - for pict in self.pictures.all()] - return picts - @property def multimedia_items(self): pict = list(self.pictures.filter(miniature=False).all()) @@ -864,6 +864,47 @@ def marker_post_save(sender, **kwargs): post_save.connect(marker_post_save, sender=Marker) +class Polygon(GeographicItem): + '''Polygon on the map + ''' + ref_item = models.ForeignKey( + "Polygon", blank=True, null=True, verbose_name=_(u"Reference polygon"), + related_name='submited_polygon') + polygon = PolygonField( + _(u"Polygon"), srid=settings.CHIMERE_EPSG_DISPLAY_PROJECTION) + picture = models.ImageField( + _(u"Image"), upload_to='upload', blank=True, null=True, + height_field='height', width_field='width') + height = models.IntegerField(_(u"Height"), blank=True, null=True) + width = models.IntegerField(_(u"Width"), blank=True, null=True) + color = models.CharField( + _(u"Color"), max_length=200, help_text=_(u"HTML code/name"), + blank=True, null=True) + inner_color = models.CharField( + _(u"Inner color"), max_length=200, + help_text=_(u"HTML code/name"), blank=True, null=True) + objects = models.GeoManager() + + class Meta: + ordering = ('status', 'name') + verbose_name = _(u"Polygon") + + @property + def geom_attr(self): + return 'polygon' + + def getGeoJSON(self, color="#000", inner_color='#0F0'): + '''Return a GeoJSON string + ''' + attributes = {"type": "Feature", + "geometry": json.loads(self.polygon.geojson), + "properties": {"pk": self.id, "name": self.name, + 'key': "polygon-{}".format(self.pk), + "color": color, + "inner_color": inner_color}} + return json.dumps(attributes) + + class MultimediaType(models.Model): MEDIA_TYPES = (('A', _(u"Audio")), ('V', _(u"Video")), @@ -937,7 +978,10 @@ class MultimediaFile(models.Model): miniature = models.BooleanField( _(u"Display inside the description?"), default=settings.CHIMERE_MINIATURE_BY_DEFAULT) - marker = models.ForeignKey(Marker, related_name='multimedia_files') + marker = models.ForeignKey(Marker, related_name='multimedia_files', + blank=True, null=True) + polygon = models.ForeignKey(Polygon, related_name='multimedia_files', + blank=True, null=True) class Meta: verbose_name = _(u"Multimedia file") @@ -1011,7 +1055,10 @@ class PictureFile(models.Model): thumbnailfile_width = models.IntegerField(_(u"Thumbnail width"), blank=True, null=True) order = models.IntegerField(_(u"Order"), default=1) - marker = models.ForeignKey(Marker, related_name='pictures') + marker = models.ForeignKey(Marker, related_name='pictures', blank=True, + null=True) + polygon = models.ForeignKey(Polygon, related_name='pictures', blank=True, + null=True) def __unicode__(self): return self.name or u"" @@ -1352,47 +1399,6 @@ class AggregatedRoute(models.Model): return json.dumps(attributes) -class Polygon(GeographicItem): - '''Polygon on the map - ''' - ref_item = models.ForeignKey( - "Polygon", blank=True, null=True, verbose_name=_(u"Reference polygon"), - related_name='submited_polygon') - polygon = PolygonField( - _(u"Polygon"), srid=settings.CHIMERE_EPSG_DISPLAY_PROJECTION) - picture = models.ImageField( - _(u"Image"), upload_to='upload', blank=True, null=True, - height_field='height', width_field='width') - height = models.IntegerField(_(u"Height"), blank=True, null=True) - width = models.IntegerField(_(u"Width"), blank=True, null=True) - color = models.CharField( - _(u"Color"), max_length=200, help_text=_(u"HTML code/name"), - blank=True, null=True) - inner_color = models.CharField( - _(u"Inner color"), max_length=200, - help_text=_(u"HTML code/name"), blank=True, null=True) - objects = models.GeoManager() - - class Meta: - ordering = ('status', 'name') - verbose_name = _(u"Polygon") - - @property - def geom_attr(self): - return 'polygon' - - def getGeoJSON(self, color="#000", inner_color='#0F0'): - '''Return a GeoJSON string - ''' - attributes = {"type": "Feature", - "geometry": json.loads(self.polygon.geojson), - "properties": {"pk": self.id, "name": self.name, - 'key': "polygon-{}".format(self.pk), - "color": color, - "inner_color": inner_color}} - return json.dumps(attributes) - - class SimplePoint: """ Point in the map (not in the database) |