diff --git a/src/pfwbged/tabellio/__init__.py b/src/pfwbged/tabellio/__init__.py
index dd071ff..93c83d9 100644
--- a/src/pfwbged/tabellio/__init__.py
+++ b/src/pfwbged/tabellio/__init__.py
@@ -1,5 +1,9 @@
# -*- coding: utf-8 -*-
"""Init and utils."""
+from zope.i18nmessageid import MessageFactory
+
+_ = MessageFactory('pfwbged.tabellio')
+
def initialize(context):
"""Initializer called when used as a Zope 2 product."""
diff --git a/src/pfwbged/tabellio/configure.zcml b/src/pfwbged/tabellio/configure.zcml
index 15d1239..548ad16 100644
--- a/src/pfwbged/tabellio/configure.zcml
+++ b/src/pfwbged/tabellio/configure.zcml
@@ -18,5 +18,4 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
-
diff --git a/src/pfwbged/tabellio/documents.py b/src/pfwbged/tabellio/documents.py
index 336d303..2cad618 100644
--- a/src/pfwbged/tabellio/documents.py
+++ b/src/pfwbged/tabellio/documents.py
@@ -1,14 +1,22 @@
import datetime
+import psycopg2.extras
+from Acquisition import aq_chain
from plone import api
from five import grok
from zope.interface import implements
from AccessControl import ClassSecurityInfo, getSecurityManager
from AccessControl.Permissions import access_contents_information
-from plone.dexterity.content import Container
+from zope import schema
+from plone.dexterity.content import Container, Item
from plone.supermodel import model
+from collective.dms.basecontent.dmsdocument import IDmsDocument, DmsDocument
+
+from . import _
+
+
class IDocumentsFolder(model.Schema):
pass
@@ -27,7 +35,7 @@ class DocumentsFolder(Container):
if not self._v_dbcache:
self._v_dbcache = {}
- cursor = self.db_connection.cursor()
+ cursor = self.db_connection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
cursor.execute('''SELECT id, ts, intit, textdefts
FROM t_document''')
while True:
@@ -46,21 +54,16 @@ class DocumentsFolder(Container):
except ValueError:
pass
else:
- cursor = self.db_connection.cursor()
- cursor.execute('''SELECT id, intit, sess
+ cursor = self.db_connection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
+ cursor.execute('''SELECT id, st, ts, type, no, sess, nodoc, anx, date, intit
FROM t_document
WHERE id = %(id)s''', {'id': id})
row = cursor.fetchone()
- if row is None:
- return super(DocumentsFolder, self).__getitem__(id)
cursor.close()
-
- row_id, intit, sess = row
- from collective.dms.basecontent.dmsfile import DmsFile
- t = DmsFile(id=row_id, title=intit, label=sess)
- t.portal_type = 'dmsmainfile'
- from Acquisition import aq_chain
- return aq_chain(t.__of__(self))[0]
+ if row is not None:
+ t = Document.from_named_row(row)
+ t.portal_type = Document._v_portal_type
+ return aq_chain(t.__of__(self))[0]
return super(DocumentsFolder, self).__getitem__(id)
def keys(self):
@@ -78,7 +81,7 @@ class DocumentsFolder(Container):
self.getId = object_id
self.getObjSize = 0
self.is_folderish = True
- self.portal_type = 'dmsmainfile'
+ self.portal_type = Document._v_portal_type
self.Creator = 'Tabellio'
def Type(self):
@@ -173,3 +176,31 @@ class DocumentsFolder(Container):
return self.iteritems()
grok.context(DocumentsFolder)
+
+
+class IDocument(IDmsDocument):
+ doctype = schema.TextLine(title=_('Document Type'), required=False)
+ no = schema.TextLine(title=_('Number'), required=False)
+ session = schema.TextLine(title=_('Session'), required=False)
+ nodoc = schema.TextLine(title=_('Secondary Number'), required=False)
+ noannexe = schema.TextLine(title=_('Appendix Number'), required=False)
+
+
+class Document(DmsDocument):
+ implements(IDocument)
+ _v_portal_type = 'pfwbged.tabellio.document'
+
+ @classmethod
+ def from_named_row(cls, row):
+ obj = cls()
+ obj.id = row.id
+ obj.title = row.intit
+ obj.doctype = row.type
+ obj.no = row.no
+ obj.session = row.sess
+ obj.nodoc = row.nodoc
+ obj.noannexe = row.anx
+ return obj
+
+ def getFolderContents(self, *args, **kwargs):
+ return []
diff --git a/src/pfwbged/tabellio/profiles/default/types.xml b/src/pfwbged/tabellio/profiles/default/types.xml
index 13c4681..e8ef49f 100644
--- a/src/pfwbged/tabellio/profiles/default/types.xml
+++ b/src/pfwbged/tabellio/profiles/default/types.xml
@@ -2,4 +2,5 @@
diff --git a/src/pfwbged/tabellio/profiles/default/types/pfwbged.tabellio.document.xml b/src/pfwbged/tabellio/profiles/default/types/pfwbged.tabellio.document.xml
new file mode 100644
index 0000000..27973a8
--- /dev/null
+++ b/src/pfwbged/tabellio/profiles/default/types/pfwbged.tabellio.document.xml
@@ -0,0 +1,47 @@
+
+
+ Document from Tabellio
+ string:${portal_url}/++resource++pfwbged.tabellio.document_icon.png
+
+ string:${folder_url}/++add++pfwbged.tabellio.document
+
+ view
+ False
+ True
+ False
+ view
+
+
+
+ False
+ cmf.AddPortalContent
+ pfwbged.tabellio.documents.Document
+
+
+
+
+
+
+ True
+
+
+
+
+
+ pfwbged.tabellio.documents.IDocument
+
+
+
+
+
+
+
+
+
+
+