agendas: set proper exception source when duplicating (#47916)
This commit is contained in:
parent
fba6eff780
commit
f880490e00
|
@ -1184,7 +1184,7 @@ class Desk(models.Model):
|
|||
# clone related objects
|
||||
for time_period in self.timeperiod_set.all():
|
||||
time_period.duplicate(desk_target=new_desk)
|
||||
for time_period_exception in self.timeperiodexception_set.all():
|
||||
for time_period_exception in self.timeperiodexception_set.filter(source__isnull=True):
|
||||
time_period_exception.duplicate(desk_target=new_desk)
|
||||
for time_period_exception_source in self.timeperiodexceptionsource_set.all():
|
||||
time_period_exception_source.duplicate(desk_target=new_desk)
|
||||
|
@ -1451,6 +1451,9 @@ class TimePeriodExceptionSource(models.Model):
|
|||
new_source.ics_file.save(self.ics_filename, ics_file, save=False)
|
||||
# store new source
|
||||
new_source.save()
|
||||
# clone related objects
|
||||
for time_period_exception in self.timeperiodexception_set.all():
|
||||
time_period_exception.duplicate(desk_target=desk_target, source_target=new_source)
|
||||
|
||||
return new_source
|
||||
|
||||
|
@ -1620,12 +1623,14 @@ class TimePeriodException(models.Model):
|
|||
'update_datetime': export_datetime(self.update_datetime),
|
||||
}
|
||||
|
||||
def duplicate(self, desk_target=None):
|
||||
def duplicate(self, desk_target=None, source_target=None):
|
||||
# clone current exception
|
||||
new_exception = copy.deepcopy(self)
|
||||
new_exception.pk = None
|
||||
# set desk
|
||||
new_exception.desk = desk_target or self.desk
|
||||
# set source
|
||||
new_exception.source = source_target or self.source
|
||||
# store new exception
|
||||
new_exception.save()
|
||||
|
||||
|
|
|
@ -970,6 +970,27 @@ def test_desk_duplicate():
|
|||
assert new_desk.slug == 'new-desk-1'
|
||||
|
||||
|
||||
def test_desk_duplicate_exception_sources():
|
||||
agenda = Agenda.objects.create(label='Agenda')
|
||||
desk = Desk.objects.create(label='Desk', agenda=agenda)
|
||||
exceptions_count = desk.import_timeperiod_exceptions_from_ics_file(
|
||||
ContentFile(ICS_SAMPLE, name='sample.ics')
|
||||
)
|
||||
source = desk.timeperiodexceptionsource_set.get(ics_filename='sample.ics')
|
||||
assert exceptions_count == 2
|
||||
assert TimePeriodException.objects.filter(desk=desk).count() == 2
|
||||
|
||||
new_desk = desk.duplicate(label="New Desk")
|
||||
new_source = new_desk.timeperiodexceptionsource_set.get(ics_filename='sample.ics')
|
||||
assert new_desk.timeperiodexception_set.count() == exceptions_count
|
||||
|
||||
source.delete()
|
||||
assert new_desk.timeperiodexception_set.count() == exceptions_count
|
||||
|
||||
new_source.delete()
|
||||
assert not new_desk.timeperiodexception_set.exists()
|
||||
|
||||
|
||||
def test_agenda_meetings_duplicate():
|
||||
group = Group(name=u'Group')
|
||||
group.save()
|
||||
|
|
Loading…
Reference in New Issue