Package madrona :: Package manipulators :: Module models
[hide private]

Source Code for Module madrona.manipulators.models

 1  from django.db import models 
 2  from django.contrib.gis.db import models 
 3   
 4   
5 -class BaseManipulatorGeometryManager(models.GeoManager):
6 """Returns the currently active data layer (determined by the active attribute). 7 """
8 - def current(self):
9 return self.get(active=True)
10
11 -class BaseManipulatorGeometry(models.Model):
12 """Abstract Model in which an inheriting subclass can be used for storing a data layer used by a Manipulator 13 14 ====================== ============================================== 15 Attribute Description 16 ====================== ============================================== 17 ``creation_date`` When the layer was created. Is not changed on 18 updates. 19 20 ``active`` Whether this layer represents the current 21 data layer. If set to true and and another 22 layer is active, that old layer will be 23 deactivated. 24 ====================== ============================================== 25 """ 26 creation_date = models.DateTimeField(auto_now=True) 27 28 active = models.BooleanField(default=True, help_text=""" 29 Checking here indicates that this layer list should be the one used in 30 the application. Copies of other layer lists are retained in the 31 system so you can go back to an old version if necessary. 32 """) 33 34 objects = BaseManipulatorGeometryManager() 35
36 - def save(self, *args, **kwargs):
37 super(BaseManipulatorGeometry, self).save(*args, **kwargs) 38 if self.active and self.__class__.objects.filter(active=True).count() > 1: 39 # Ensure that any previously active layer is deactivated -- There can be only one! 40 self.__class__.objects.filter(active=True).exclude(pk=self.pk).update(active=False)
41
42 - class Meta:
43 abstract = True
44