Revision 5f3ce603
Added by Benjamin Dauvergne over 12 years ago
calebasse/agenda/models.py | ||
---|---|---|
344 | 344 |
assert self.start_datetime is not None |
345 | 345 |
self.sanitize() # init periodicity fields |
346 | 346 |
super(Event, self).save(*args, **kwargs) |
347 |
self.acts_cleaning() |
|
347 | 348 |
|
348 | 349 |
def delete(self, *args, **kwargs): |
349 |
# never delete, only cancel |
|
350 |
from ..actes.models import Act |
|
351 |
for a in Act.objects.filter(parent_event=self): |
|
352 |
if len(a.actvalidationstate_set.all()) > 1: |
|
353 |
a.parent_event = None |
|
354 |
a.save() |
|
355 |
else: |
|
356 |
a.delete() |
|
357 | 350 |
self.canceled = True |
358 |
self.save() |
|
351 |
# save will clean acts |
|
352 |
self.save(*args, **kwargs) |
|
353 |
|
|
354 |
def acts_cleaning(self): |
|
355 |
# list of occurences may have changed |
|
356 |
from ..actes.models import Act |
|
357 |
if self.exception_to: |
|
358 |
# maybe a new exception, so look for parent acts with same date |
|
359 |
# as exception date |
|
360 |
acts = Act.objects.filter(models.Q(parent_event=self) |
|
361 |
|models.Q(parent_event=self.exception_to, |
|
362 |
date=self.exception_date)) |
|
363 |
else: |
|
364 |
acts = Act.objects.filter(parent_event=self) |
|
365 |
acts = acts.prefetch_related('actvalidationstate_set') |
|
366 |
if acts: |
|
367 |
eventwithact = self.eventwithact |
|
368 |
for act in acts: |
|
369 |
if act.is_new(): |
|
370 |
if self.match_date(act.date): |
|
371 |
if self.canceled: |
|
372 |
act.delete() |
|
373 |
else: |
|
374 |
eventwithact.update_act(act) |
|
375 |
else: |
|
376 |
act.delete() |
|
359 | 377 |
|
360 | 378 |
def to_interval(self): |
361 | 379 |
return Interval(self.start_datetime, self.end_datetime) |
Also available in: Unified diff
agenda: clean acts as part of the Event.save method
Detec when the event is really an EventWithAct and update or delete linked acts