Project

General

Profile

« Previous | Next » 

Revision b8a9f824

Added by Benjamin Dauvergne over 12 years ago

agenda: upgrade exceptions to EventWithAct model only if needed

View differences:

calebasse/agenda/models.py
225 225
            return self if date == self.start_datetime.date() else None
226 226

  
227 227

  
228
    def today_occurrence(self, today=None, match=False):
228
    def today_occurrence(self, today=None, match=False, upgrade=True):
229 229
        '''For a recurring event compute the today 'Event'.
230 230

  
231 231
           The computed event is the fake one that you cannot save to the database.
......
246 246
                return None
247 247
            if exception_or_self != self:
248 248
                return exception_or_self.today_occurrence(today)
249
        if self.event_type_id == 1 and type(self) != EventWithAct and upgrade:
250
           self = self.eventwithact
249 251
        if self.recurrence_periodicity is None:
250 252
            return self
251 253
        start_datetime = datetime.combine(today, self.start_datetime.timetz())
......
287 289
        if not hasattr(self, 'exceptions_dict'):
288 290
            self.exceptions_dict = dict()
289 291
            if self.exception_to_id is None:
290
                for exception in self.exceptions.select_subclasses():
292
                for exception in self.exceptions.all():
291 293
                    self.exceptions_dict[exception.exception_date] = exception
292 294
        return self.exceptions_dict
293 295

  
......
328 330
                    day += delta
329 331
            for exception in self.exceptions.all():
330 332
                if exception.exception_date != exception.start_datetime.date():
331
                    occurrences.append(exception)
333
                    occurrences.append(exception.eventwithact if exception.event_type_id == 1 else exception)
332 334
            return sorted(occurrences, key=lambda o: o.start_datetime)
333 335
        else:
334 336
            return [self]
......
455 457
                continue
456 458
            o.get_or_create_act()
457 459

  
458
    def today_occurrence(self, today=None, match=False):
460
    def today_occurrence(self, today=None, match=False, upgrade=True):
459 461
        '''For virtual occurrences reset the event_ptr_id'''
460
        occurrence = super(EventWithAct, self).today_occurrence(today, match)
462
        occurrence = super(EventWithAct, self).today_occurrence(today, match, upgrade)
461 463
        if hasattr(occurrence, 'parent'):
462 464
            old_save = occurrence.save
463 465
            def save(*args, **kwargs):

Also available in: Unified diff