0002-agendas-do-not-import-exception-from-settings-when-d.patch
chrono/agendas/models.py | ||
---|---|---|
1132 | 1132 |
ordering = ['label'] |
1133 | 1133 |
unique_together = ['agenda', 'slug'] |
1134 | 1134 | |
1135 |
def save(self, *args, **kwargs): |
|
1135 |
def save(self, *args, import_exceptions=True, **kwargs):
|
|
1136 | 1136 |
assert self.agenda.kind != 'virtual', "a desk can't reference a virtual agenda" |
1137 | 1137 |
first_created = not self.pk |
1138 | 1138 |
if not self.slug: |
1139 | 1139 |
self.slug = generate_slug(self, agenda=self.agenda) |
1140 | 1140 |
super(Desk, self).save(*args, **kwargs) |
1141 |
if first_created: |
|
1141 |
if first_created and import_exceptions:
|
|
1142 | 1142 |
self.import_timeperiod_exceptions_from_settings(enable=True) |
1143 | 1143 | |
1144 | 1144 |
@property |
... | ... | |
1179 | 1179 |
if agenda_target: |
1180 | 1180 |
new_desk.agenda = agenda_target |
1181 | 1181 |
# store new desk |
1182 |
new_desk.save() |
|
1182 |
new_desk.save(import_exceptions=False)
|
|
1183 | 1183 | |
1184 | 1184 |
# clone related objects |
1185 | 1185 |
for time_period in self.timeperiod_set.all(): |
tests/test_agendas.py | ||
---|---|---|
991 | 991 |
assert not new_desk.timeperiodexception_set.exists() |
992 | 992 | |
993 | 993 | |
994 |
@override_settings( |
|
995 |
EXCEPTIONS_SOURCES={'holidays': {'class': 'workalendar.europe.France', 'label': 'Holidays'},} |
|
996 |
) |
|
997 |
def test_desk_duplicate_exception_source_from_settings(): |
|
998 |
agenda = Agenda.objects.create(label='Agenda') |
|
999 |
desk = Desk.objects.create(label='Desk', agenda=agenda) |
|
1000 | ||
1001 |
source = desk.timeperiodexceptionsource_set.get(settings_slug='holidays') |
|
1002 |
assert source.enabled |
|
1003 |
exceptions_count = desk.timeperiodexception_set.count() |
|
1004 | ||
1005 |
new_desk = desk.duplicate(label="New Desk") |
|
1006 |
assert new_desk.timeperiodexceptionsource_set.filter(settings_slug='holidays').count() == 1 |
|
1007 |
assert new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled |
|
1008 |
assert new_desk.timeperiodexception_set.count() == exceptions_count |
|
1009 | ||
1010 |
source.enabled = False |
|
1011 |
source.save() |
|
1012 | ||
1013 |
new_desk = desk.duplicate(label="New Desk") |
|
1014 |
assert not new_desk.timeperiodexceptionsource_set.get(settings_slug='holidays').enabled |
|
1015 |
assert not new_desk.timeperiodexception_set.exists() |
|
1016 | ||
1017 | ||
994 | 1018 |
def test_agenda_meetings_duplicate(): |
995 | 1019 |
group = Group(name=u'Group') |
996 | 1020 |
group.save() |
997 |
- |