Skip to content
Snippets Groups Projects
Commit 0676ae03 authored by jan.bednarik's avatar jan.bednarik
Browse files

calendar utils: Delete orphaned callendars when updating

parent 173d5a55
No related branches found
No related tags found
2 merge requests!706Release,!705Upgrade
Pipeline #11304 failed
......@@ -9,9 +9,25 @@ logger = logging.getLogger(__name__)
class Command(BaseCommand):
def handle(self, *args, **options):
self.stdout.write("Removing orphaned calendars...")
for cal in Calendar.objects.filter(
districtcenterpage=None,
districthomepage=None,
elections2021calendarpage=None,
senatcampaignhomepage=None,
uniwebhomepage=None,
):
try:
self.stdout.write(f"- {cal.id} | {cal.url}")
cal.delete()
except Exception as e:
logger.error("Calendar delete failed for %s", cal.url, exc_info=True)
self.stdout.write(" - failed")
self.stdout.write(str(e))
self.stdout.write("Updating calendars...")
for cal in Calendar.objects.all():
self.stdout.write(f"\n@ {cal.url}")
self.stdout.write(f"\n@ {cal.id} | {cal.url}")
try:
cal.update_source()
self.stdout.write("+ ok")
......
......@@ -99,8 +99,6 @@ class CalendarMixin(models.Model):
# delete related Calendar when URL is cleared
if not self.calendar_url and self.calendar:
# TODO handle revisions and maybe other live pages with the same calendar
# self.calendar.delete()
self.calendar = None
super().save(*args, **kwargs)
......@@ -145,4 +145,3 @@ def test_calendar_mixin__clear_calendar_url(mocker):
assert obj.calendar_url is None
assert obj.calendar is None
assert m_update.call_count == 0
assert Calendar.objects.count() == 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment