From ac1939190fc23b397bbbbc59c1d95ceea639097d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Avil=C3=A9s?= Date: Tue, 4 Nov 2014 17:30:04 +0100 Subject: [PATCH] Add iter_subentries to generate nested entries --- livesync/indico_livesync/models/queue.py | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/livesync/indico_livesync/models/queue.py b/livesync/indico_livesync/models/queue.py index 31230df..d3508e3 100644 --- a/livesync/indico_livesync/models/queue.py +++ b/livesync/indico_livesync/models/queue.py @@ -139,3 +139,29 @@ class LiveSyncQueueEntry(db.Model): entry = cls(agent=agent, change=change, **obj_ref) db.session.add(entry) db.session.flush() + + def iter_subentries(self): + """Iterates through all children""" + if self.type not in {'category', 'event', 'contribution'}: + return + data = {'change': self.change, + 'category_id': self.category_id, 'event_id': self.event_id, + 'contrib_id': self.contrib_id, 'subcontrib_id': self.subcontrib_id} + if self.type == 'category': + for event in self.object.iterAllConferences(): + new_data = dict(data) + new_data['type'] = 'event' + new_data['event_id'] = event.getId() + yield LiveSyncQueueEntry(**new_data) + elif self.type == 'event': + for contrib in self.object.iterContributions(): + new_data = dict(data) + new_data['type'] = 'contribution' + new_data['contrib_id'] = contrib.getId() + yield LiveSyncQueueEntry(**new_data) + elif self.type == 'contribution': + for subcontrib in self.object.iterSubContributions(): + new_data = dict(data) + new_data['type'] = 'subcontribution' + new_data['subcontrib_id'] = subcontrib.getId() + yield LiveSyncQueueEntry(**new_data)