move source bounds to BoundsMixin
This commit is contained in:
parent
a60a333f42
commit
b7333bba52
2 changed files with 30 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
EDITOR_FORM_MODELS = OrderedDict()
|
||||
|
||||
|
@ -38,3 +39,30 @@ class EditorFormMixin(SerializableMixin, models.Model):
|
|||
@property
|
||||
def title(self):
|
||||
return self._meta.verbose_name+' '+str(self.id)
|
||||
|
||||
|
||||
class BoundsMixin(SerializableMixin, models.Model):
|
||||
bottom = models.DecimalField(_('bottom coordinate'), max_digits=6, decimal_places=2)
|
||||
left = models.DecimalField(_('left coordinate'), max_digits=6, decimal_places=2)
|
||||
top = models.DecimalField(_('top coordinate'), max_digits=6, decimal_places=2)
|
||||
right = models.DecimalField(_('right coordinate'), max_digits=6, decimal_places=2)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@classmethod
|
||||
def max_bounds(cls):
|
||||
result = cls.objects.all().aggregate(models.Min('bottom'), models.Min('left'),
|
||||
models.Max('top'), models.Max('right'))
|
||||
return ((float(result['bottom__min']), float(result['left__min'])),
|
||||
(float(result['top__max']), float(result['right__max'])))
|
||||
|
||||
def _serialize(self, section=True, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['bounds'] = self.bounds
|
||||
return result
|
||||
|
||||
@property
|
||||
def bounds(self):
|
||||
# noinspection PyTypeChecker
|
||||
return (float(self.bottom), float(self.left)), (float(self.top), float(self.right))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue