parent
2237774cf8
commit
adf7cd9d71
|
@ -57,14 +57,18 @@ class SyncFromThemis(UtilityView):
|
|||
objects = self.request.form.get('objects', '').split(',')
|
||||
log.info('sync: start [%r] [%r]' % (timestamp, objects))
|
||||
for object in ('deputies', 'ministries', 'commissions', 'documents',
|
||||
'blocked_documents'):
|
||||
'blocked_documents', 'deleted_documents'):
|
||||
if not 'all' in objects:
|
||||
if not object in objects:
|
||||
continue
|
||||
t0 = time.time()
|
||||
result = getattr(self, 'sync_'+object)(timestamp)
|
||||
duration = time.time() - t0
|
||||
log.info('sync: %-14s: %6s [%s]' % (object, result, format_duration(duration)))
|
||||
|
||||
# when deleted docs sync called, return its result
|
||||
if object in ('deleted_documents',):
|
||||
return result
|
||||
log.info('sync: %-14s: %6s [%s]' % (object, str(result)[:20], format_duration(duration)))
|
||||
|
||||
return 'OK'
|
||||
|
||||
|
@ -426,3 +430,23 @@ class SyncFromThemis(UtilityView):
|
|||
transaction.commit()
|
||||
|
||||
log.info('blocked documents done')
|
||||
|
||||
def sync_deleted_documents(self, *args):
|
||||
remote_documents = json.load(self.urlopen('%s/@@listDocuments' % self.src_url))
|
||||
|
||||
remote_document_ids = []
|
||||
for remote_document_url in remote_documents:
|
||||
remote_document_ids.append(remote_document_url.split('/')[-1])
|
||||
|
||||
local_document_ids = [doc_id for doc_id in self.documents_folder]
|
||||
documents_to_purge = set(local_document_ids) - set(remote_document_ids)
|
||||
|
||||
if self.request.form.get('delete') == 'yes':
|
||||
log.info('deleted documents sync')
|
||||
for doc_id in documents_to_purge:
|
||||
self.documents_folder.manage_delObjects([doc_id])
|
||||
|
||||
log.info('deleted documents sync done')
|
||||
return 'OK'
|
||||
|
||||
return json.dumps(list(documents_to_purge))
|
||||
|
|
Reference in New Issue