summaryrefslogtreecommitdiffstats
path: root/tabellio
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-11-07 12:28:57 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-11-07 12:28:57 (GMT)
commit206758175275b1fd0259b0b07651137dc2182ddc (patch)
treec92e4b003570435c090abedf64cc3bcff72b56e8 /tabellio
parent7da319130cb33155ef2f33a8499075448e2938fd (diff)
downloadtabellio.pcfdb-206758175275b1fd0259b0b07651137dc2182ddc.zip
tabellio.pcfdb-206758175275b1fd0259b0b07651137dc2182ddc.tar.gz
tabellio.pcfdb-206758175275b1fd0259b0b07651137dc2182ddc.tar.bz2
improve import of chronology
Diffstat (limited to 'tabellio')
-rw-r--r--tabellio/pcfdb/sync.py49
1 files changed, 28 insertions, 21 deletions
diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py
index 817d96e..b92f399 100644
--- a/tabellio/pcfdb/sync.py
+++ b/tabellio/pcfdb/sync.py
@@ -673,7 +673,10 @@ class SyncFromPcfDbView(BrowserView):
where_ts = ''
if timestamp:
- where_ts = cursor.mogrify('AND t_dossier.ts > %s', (timestamp,))
+ where_ts = cursor.mogrify('''AND (t_dossier.ts > %s OR
+ EXISTS (SELECT ts FROM t_histoline
+ WHERE idhisto = t_histo.id
+ AND ts > %s))''', (timestamp, timestamp))
### Handle t_dossiers
cursor.execute('''SELECT t_histo.id, t_dossier.st, t_dossier.type,
@@ -684,8 +687,6 @@ class SyncFromPcfDbView(BrowserView):
ON (t_dossier.id = t_histo.objid)
WHERE t_dossier.intit IS NOT NULL
%s''' % where_ts)
- ### XXX: is a dossier timestamp updated when a related history line is
- ### added?
while True:
row = cursor.fetchone()
@@ -736,7 +737,10 @@ class SyncFromPcfDbView(BrowserView):
### Handle t_qx
where_ts = ''
if timestamp:
- where_ts = cursor.mogrify('AND t_qx.ts > %s', (timestamp,))
+ where_ts = cursor.mogrify('''AND (t_qx.ts > %s OR
+ EXISTS (SELECT ts FROM t_histoline
+ WHERE idhisto = t_histo.id
+ AND ts > %s))''', (timestamp, timestamp))
cursor.execute('''SELECT t_histo.id, t_qx.st, classname, t_qx.sess,
objet, auteur, dateenvoi, t_histo.comppols
@@ -784,7 +788,10 @@ class SyncFromPcfDbView(BrowserView):
### Handle t_qe
where_ts = ''
if timestamp:
- where_ts = cursor.mogrify('AND t_qe.ts > %s', (timestamp,))
+ where_ts = cursor.mogrify('''AND (t_qe.ts > %s OR
+ EXISTS (SELECT ts FROM t_histoline
+ WHERE idhisto = t_histo.id
+ AND ts > %s))''', (timestamp, timestamp))
cursor.execute('''SELECT t_histo.id, t_histo.st, t_histo.sess, t_qe.no,
objet, t_qe.auteurs, date, t_histo.comppols
@@ -837,26 +844,26 @@ class SyncFromPcfDbView(BrowserView):
# timestamp is not considered here as the field value is
# reconstructured anew.
hist_cursor.execute('''SELECT t_histoline.date, t_histoline.descr,
- t_histoline.auteurs, t_document.id, docpages
- FROM t_histoline, t_histo, t_document
- WHERE t_histoline.idhisto = t_histo.id
- AND t_histo.objid = %(objid)s
- AND t_histoline.docno = t_document.no
- AND t_histoline.docsess = t_document.sess
- AND (t_histoline.docnodoc = t_document.nodoc
- OR (t_histoline.docnodoc is NULL AND
- t_document.nodoc is NULL))
- AND (t_histoline.docanx = t_document.anx
- OR (t_histoline.docanx is NULL AND
- t_document.anx is NULL))
- ORDER BY date, t_histoline.ts''',
+ t_histoline.auteurs, t_document.id, docpages,
+ t_histoline.comment, t_histoline.com
+ FROM t_histoline LEFT JOIN t_document
+ ON (t_histoline.docno = t_document.no AND
+ t_histoline.docsess = t_document.sess AND
+ t_histoline.doctype = t_document.type AND
+ ((t_histoline.docnodoc = t_document.nodoc) OR
+ (t_histoline.docnodoc is NULL AND
+ t_document.nodoc is NULL)) AND
+ ((t_histoline.docanx = t_document.anx) OR
+ (t_histoline.docanx is NULL AND t_document.anx is NULL)))
+ WHERE t_histoline.idhisto = %(objid)s
+ ORDER BY t_histoline.date, t_histoline.ordre, t_histoline.id''',
{'objid': object.id})
object.reset_histolines()
while True:
histo_row = hist_cursor.fetchone()
if histo_row is None:
break
- date, desc, authors, docid, docpages = histo_row
+ date, desc, authors, docid, docpages, comment, commission = histo_row
if authors:
authors = [self.get_author_intid(x) for x in authors]
authors = [RelationValue(x) for x in authors if x]
@@ -865,8 +872,8 @@ class SyncFromPcfDbView(BrowserView):
if docid:
document, docintid = self.get_document_and_intid(docid)
else:
- document, docintid = None
- object.add_histoline(date, desc, authors, docintid, document, docpages)
+ document, docintid = (None, None)
+ object.add_histoline(date, comment or desc, authors, docintid, document, docpages)
def sync_reunions(self, timestamp=None):
cursor = self.db_connection.cursor()