summaryrefslogtreecommitdiffstats
path: root/tabellio
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2011-08-19 16:54:50 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2011-08-19 16:54:50 (GMT)
commit1d1391ccd0931859584d03076efea569ab42b597 (patch)
treee53e06f1eb5770fddeea1d2a106f795f148e2387 /tabellio
parent19e51385b80c98fd9af29934d43a0f9f4d214233 (diff)
downloadtabellio.pcfdb-1d1391ccd0931859584d03076efea569ab42b597.zip
tabellio.pcfdb-1d1391ccd0931859584d03076efea569ab42b597.tar.gz
tabellio.pcfdb-1d1391ccd0931859584d03076efea569ab42b597.tar.bz2
Add import of questions, as dossiers
Diffstat (limited to 'tabellio')
-rw-r--r--tabellio/pcfdb/sync.py150
1 files changed, 112 insertions, 38 deletions
diff --git a/tabellio/pcfdb/sync.py b/tabellio/pcfdb/sync.py
index 7deedcd..de42f34 100644
--- a/tabellio/pcfdb/sync.py
+++ b/tabellio/pcfdb/sync.py
@@ -399,20 +399,21 @@ class SyncFromPcfDbView(BrowserView):
cursor = self.db_connection.cursor()
where_ts = ''
if timestamp:
- where_ts = cursor.mogrify('AND t_dossier.ts > %s', (timestamp,))
- cursor.execute('''SELECT id, st, sess, no, intit, auteurs, datedep
+ where_ts = cursor.mogrify('AND ts > %s', (timestamp,))
+
+ ### Handle t_dossiers
+ cursor.execute('''SELECT id, st, type, sess, no, intit, auteurs, datedep
FROM t_dossier
WHERE intit IS NOT NULL
%s''' % where_ts)
### XXX: is a dossier timestamp updated when a related history line is
### added?
- type_info = self.portal_types.getTypeInfo('tabellio.documents.dossier')
while True:
row = cursor.fetchone()
if row is None:
break
- dos_id, state, sess, no, intit, authors, datedep = row
+ dos_id, state, dostype, sess, no, intit, authors, datedep = row
print 'dos id:', dos_id
@@ -424,6 +425,7 @@ class SyncFromPcfDbView(BrowserView):
object.session = sess
object.no = no
object.date = datedep
+ object.dostype = dostype
if authors:
authors = [self.get_author_intid(x) for x in authors]
object.authors = [RelationValue(x) for x in authors if x]
@@ -432,44 +434,116 @@ class SyncFromPcfDbView(BrowserView):
else:
object.authors = []
- hist_cursor = self.db_connection.cursor()
- # 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''',
- {'objid': dos_id})
- object.reset_histolines()
- while True:
- histo_row = hist_cursor.fetchone()
- if histo_row is None:
- break
- date, desc, authors, docid, docpages = histo_row
- if authors:
- authors = [self.get_author_intid(x) for x in authors]
- authors = [RelationValue(x) for x in authors if x]
- else:
- authors = []
- if docid:
- docintid = self.get_document_intid(docid)
- else:
- docintid = None
- object.add_histoline(date, desc, authors, docintid, docpages)
+ self.sync_dossier_history(object)
notify(ObjectModifiedEvent(object))
self.publish(object)
+ ### Handle t_qx
+ cursor.execute('''SELECT id, st, classname, sess, objet, auteur, dateenvoi
+ FROM t_qx
+ WHERE objet IS NOT NULL
+ %s''' % where_ts)
+
+ while True:
+ row = cursor.fetchone()
+ if row is None:
+ break
+ dos_id, state, dostype, sess, intit, author, date = row
+ print 't_qx/dos id:', dos_id
+ if not hasattr(self.dossiers_folder, dos_id):
+ self.dossiers_folder.invokeFactory('tabellio.documents.dossier', dos_id)
+ object = getattr(self.dossiers_folder, dos_id)
+ object.title = intit
+ object.session = sess
+ object.no = no
+ object.date = date
+ object.dostype = dostype
+ if author:
+ authors = [self.get_author_intid(author)]
+ object.authors = [RelationValue(x) for x in authors if x]
+ if len(object.authors) != len(authors):
+ print ' different number of authors'
+ else:
+ object.authors = []
+
+ self.sync_dossier_history(object)
+
+ notify(ObjectModifiedEvent(object))
+ self.publish(object)
+
+ ### Handle t_qe
+ cursor.execute('''SELECT id, st, sess, objet, auteurs, date
+ FROM t_qe
+ WHERE objet IS NOT NULL
+ %s''' % where_ts)
+
+ while True:
+ row = cursor.fetchone()
+ if row is None:
+ break
+ dos_id, state, sess, intit, authors, date = row
+ print 't_qe/dos id:', dos_id
+ if not hasattr(self.dossiers_folder, dos_id):
+ self.dossiers_folder.invokeFactory('tabellio.documents.dossier', dos_id)
+ object = getattr(self.dossiers_folder, dos_id)
+ object.title = intit
+ object.session = sess
+ object.no = no
+ object.date = date
+ object.dostype = 'QE'
+ if authors:
+ authors = [self.get_author_intid(x) for x in authors]
+ object.authors = [RelationValue(x) for x in authors if x]
+ if len(object.authors) != len(authors):
+ print ' different number of authors'
+ else:
+ object.authors = []
+
+ self.sync_dossier_history(object)
+
+ notify(ObjectModifiedEvent(object))
+ self.publish(object)
+
+
+
+
+ def sync_dossier_history(self, object):
+ hist_cursor = self.db_connection.cursor()
+ # 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''',
+ {'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
+ if authors:
+ authors = [self.get_author_intid(x) for x in authors]
+ authors = [RelationValue(x) for x in authors if x]
+ else:
+ authors = []
+ if docid:
+ docintid = self.get_document_intid(docid)
+ else:
+ docintid = None
+ object.add_histoline(date, desc, authors, docintid, docpages)
+
def sync_reunions(self, timestamp=None):
cursor = self.db_connection.cursor()
where_ts = ''