|
@@ -3,9 +3,10 @@
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
from django.db import models
|
|
|
+from django.utils import timezone
|
|
|
|
|
|
from .fields import CommaSeparatedCharField
|
|
|
-from .utils import ANGLES, merge_intervals
|
|
|
+from .utils import add_one_year, ANGLES, merge_intervals
|
|
|
|
|
|
|
|
|
class Contrib(models.Model):
|
|
@@ -66,6 +67,9 @@ class Contrib(models.Model):
|
|
|
'commentaire public',
|
|
|
default=False)
|
|
|
date = models.DateTimeField(auto_now_add=True)
|
|
|
+ expiration_date = models.DateTimeField(
|
|
|
+ "date d'expiration",
|
|
|
+ null=True, blank=True)
|
|
|
|
|
|
STATUS_TOSTUDY = 'TOSTUDY'
|
|
|
STATUS_TOCONNECT = 'TOCONNECT'
|
|
@@ -122,6 +126,28 @@ class Contrib(models.Model):
|
|
|
angles.sort(key=lambda i: i[0]) # sort by x
|
|
|
return merge_intervals(angles)
|
|
|
|
|
|
+ def get_postponed_expiration_date(self, from_date):
|
|
|
+ """ Computes the new expiration date
|
|
|
+
|
|
|
+ :param from_date: reference datetime frow where we add our extra delay.
|
|
|
+ """
|
|
|
+ return add_one_year(from_date)
|
|
|
+
|
|
|
+ def clean(self):
|
|
|
+ # usefull only for data imported from bottle version
|
|
|
+ if not self.date:
|
|
|
+ self.date = timezone.now()
|
|
|
+ if not self.expiration_date:
|
|
|
+ self.expiration_date = self.get_postponed_expiration_date(
|
|
|
+ self.date)
|
|
|
+
|
|
|
+ def save(self, *args, **kwargs):
|
|
|
+ if not self.pk: # New instance
|
|
|
+ self.date = timezone.now()
|
|
|
+ self.expiration_date = self.get_postponed_expiration_date(
|
|
|
+ self.date)
|
|
|
+ super().save(*args, **kwargs)
|
|
|
+
|
|
|
def is_public(self):
|
|
|
return self.privacy_coordinates
|
|
|
|