0001-agendas-fix-duplication-of-desk-with-external-except.patch
chrono/agendas/models.py | ||
---|---|---|
1137 | 1137 |
first_created = not self.pk |
1138 | 1138 |
if not self.slug: |
1139 | 1139 |
self.slug = generate_slug(self, agenda=self.agenda) |
1140 |
import_exceptions = kwargs.pop('import_exceptions', True) |
|
1140 | 1141 |
super(Desk, self).save(*args, **kwargs) |
1141 |
if first_created: |
|
1142 |
if first_created and import_exceptions:
|
|
1142 | 1143 |
self.import_timeperiod_exceptions_from_settings(enable=True) |
1143 | 1144 | |
1144 | 1145 |
@property |
... | ... | |
1179 | 1180 |
if agenda_target: |
1180 | 1181 |
new_desk.agenda = agenda_target |
1181 | 1182 |
# store new desk |
1182 |
new_desk.save() |
|
1183 |
new_desk.save(import_exceptions=False)
|
|
1183 | 1184 | |
1184 | 1185 |
# clone related objects |
1185 | 1186 |
for time_period in self.timeperiod_set.all(): |
1186 | 1187 |
time_period.duplicate(desk_target=new_desk) |
1187 |
for time_period_exception in self.timeperiodexception_set.all():
|
|
1188 |
for time_period_exception in self.timeperiodexception_set.exclude(external=True):
|
|
1188 | 1189 |
time_period_exception.duplicate(desk_target=new_desk) |
1189 | 1190 |
for time_period_exception_source in self.timeperiodexceptionsource_set.all(): |
1190 | 1191 |
time_period_exception_source.duplicate(desk_target=new_desk) |
... | ... | |
1451 | 1452 |
new_source.ics_file.save(self.ics_filename, ics_file, save=False) |
1452 | 1453 |
# store new source |
1453 | 1454 |
new_source.save() |
1455 |
# create related exceptions |
|
1456 |
if self.settings_slug and self.enabled: |
|
1457 |
new_source.enable() |
|
1454 | 1458 | |
1455 | 1459 |
return new_source |
1456 | 1460 |
tests/test_agendas.py | ||
---|---|---|
970 | 970 |
assert new_desk.slug == 'new-desk-1' |
971 | 971 | |
972 | 972 | |
973 |
@override_settings( |
|
974 |
EXCEPTIONS_SOURCES={'holidays': {'class': 'workalendar.europe.France', 'label': 'Holidays'},} |
|
975 |
) |
|
976 |
def test_desk_duplicate_external_exception_sources(): |
|
977 |
agenda = Agenda.objects.create(label='Agenda') |
|
978 |
desk = Desk.objects.create(label='Desk', agenda=agenda) |
|
979 | ||
980 |
source = desk.timeperiodexceptionsource_set.get(settings_slug='holidays') |
|
981 |
assert source.enabled |
|
982 |
exceptions_count = desk.timeperiodexception_set.count() |
|
983 | ||
984 |
new_desk = desk.duplicate(label="New Desk") |
|
985 |
assert new_desk.timeperiodexceptionsource_set.filter(settings_slug='holidays').count() == 1 |
|
986 |
assert new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled |
|
987 |
assert new_desk.timeperiodexception_set.count() == exceptions_count |
|
988 | ||
989 |
source.enabled = False |
|
990 |
source.save() |
|
991 | ||
992 |
new_desk = desk.duplicate(label="New Desk") |
|
993 |
assert not new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled |
|
994 |
assert not new_desk.timeperiodexception_set.exists() |
|
995 | ||
996 | ||
973 | 997 |
def test_agenda_meetings_duplicate(): |
974 | 998 |
group = Group(name=u'Group') |
975 | 999 |
group.save() |
976 |
- |