Show More
@@ -89,26 +89,7 b' class Command(BaseCommand):' | |||||
89 |
|
89 | |||
90 | models = root.findall('models')[0] |
|
90 | models = root.findall('models')[0] | |
91 | for model in models: |
|
91 | for model in models: | |
92 | tag_id = model.find(TAG_ID) |
|
92 | self.add_to_sync_list(ids_to_sync, logger, model) | |
93 | global_id, exists = GlobalId.from_xml_element(tag_id) |
|
|||
94 |
|
||||
95 | from_this_board = self._is_from_this_board(global_id) |
|
|||
96 |
|
||||
97 | if from_this_board: |
|
|||
98 | # If the post originates from this board, no need to process |
|
|||
99 | # it again, nobody else could modify it |
|
|||
100 | logger.debug('* Processed (-) post {}'.format(global_id)) |
|
|||
101 | else: |
|
|||
102 | tag_update_time = model.find(TAG_UPDATE_TIME) |
|
|||
103 | if tag_update_time: |
|
|||
104 | update_time = tag_update_time.text |
|
|||
105 | else: |
|
|||
106 | update_time = None |
|
|||
107 | if not exists or update_time is None or global_id.post.last_edit_time < parse_datetime(update_time): |
|
|||
108 | logger.debug('Processed (+) post {}'.format(global_id)) |
|
|||
109 | ids_to_sync.append(global_id) |
|
|||
110 | else: |
|
|||
111 | logger.debug('* Processed (-) post {}'.format(global_id)) |
|
|||
112 | logger.info('Starting sync...') |
|
93 | logger.info('Starting sync...') | |
113 |
|
94 | |||
114 | if len(ids_to_sync) > 0: |
|
95 | if len(ids_to_sync) > 0: | |
@@ -128,6 +109,27 b' class Command(BaseCommand):' | |||||
128 | else: |
|
109 | else: | |
129 | raise Exception('Invalid response status') |
|
110 | raise Exception('Invalid response status') | |
130 |
|
111 | |||
|
112 | def add_to_sync_list(self, ids_to_sync, logger, model): | |||
|
113 | tag_id = model.find(TAG_ID) | |||
|
114 | global_id, exists = GlobalId.from_xml_element(tag_id) | |||
|
115 | from_this_board = self._is_from_this_board(global_id) | |||
|
116 | if from_this_board: | |||
|
117 | # If the post originates from this board, no need to process | |||
|
118 | # it again, nobody else could modify it | |||
|
119 | logger.debug('NO SYNC Processed post {}'.format(global_id)) | |||
|
120 | else: | |||
|
121 | tag_update_time = model.find(TAG_UPDATE_TIME) | |||
|
122 | if tag_update_time: | |||
|
123 | update_time = tag_update_time.text | |||
|
124 | else: | |||
|
125 | update_time = None | |||
|
126 | if not exists or update_time is None or global_id.post.last_edit_time < parse_datetime( | |||
|
127 | update_time): | |||
|
128 | logger.debug('SYNC Processed post {}'.format(global_id)) | |||
|
129 | ids_to_sync.append(global_id) | |||
|
130 | else: | |||
|
131 | logger.debug('NO SYNC Processed post {}'.format(global_id)) | |||
|
132 | ||||
131 | def _is_from_this_board(self, global_id): |
|
133 | def _is_from_this_board(self, global_id): | |
132 | from_this_board = KeyPair.objects.filter( |
|
134 | from_this_board = KeyPair.objects.filter( | |
133 | key_type=global_id.key_type, |
|
135 | key_type=global_id.key_type, |
General Comments 0
You need to be logged in to leave comments.
Login now