summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2014-11-18 13:58:14 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2014-11-18 13:58:14 (GMT)
commit8a419c6c7714bc6e6d55004178a19ed584e89e43 (patch)
tree4c749cac9abe692358853de9812b78404172fd74
parent04506ca8502230342821463368dab715947e9730 (diff)
downloadpfwbged.tabellio-8a419c6c7714bc6e6d55004178a19ed584e89e43.zip
pfwbged.tabellio-8a419c6c7714bc6e6d55004178a19ed584e89e43.tar.gz
pfwbged.tabellio-8a419c6c7714bc6e6d55004178a19ed584e89e43.tar.bz2
add new portal type for tabellio documents
-rw-r--r--src/pfwbged/tabellio/__init__.py4
-rw-r--r--src/pfwbged/tabellio/configure.zcml1
-rw-r--r--src/pfwbged/tabellio/documents.py59
-rw-r--r--src/pfwbged/tabellio/profiles/default/types.xml1
-rw-r--r--src/pfwbged/tabellio/profiles/default/types/pfwbged.tabellio.document.xml47
5 files changed, 97 insertions, 15 deletions
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"
/>
-
</configure>
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 @@
<object name="portal_types" meta_type="Plone Types Tool">
<property name="title">Controls the available content types in your portal</property>
<object name="pfwbged.tabellio.documentsfolder" meta_type="Dexterity FTI"/>
+ <object name="pfwbged.tabellio.document" meta_type="Dexterity FTI"/>
</object>
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 @@
+<?xml version="1.0"?>
+<object name="pfwbged.tabellio.document" meta_type="Dexterity FTI" i18n:domain="plone"
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n">
+ <property name="title" i18n:translate="">Document from Tabellio</property>
+ <property name="icon_expr">string:${portal_url}/++resource++pfwbged.tabellio.document_icon.png</property>
+ <!--<property name="factory">pfwbged.tabellio.document</property>-->
+ <property name="add_view_expr">string:${folder_url}/++add++pfwbged.tabellio.document</property>
+ <property name="link_target"></property>
+ <property name="immediate_view">view</property>
+ <property name="global_allow">False</property>
+ <property name="filter_content_types">True</property>
+ <property name="allow_discussion">False</property>
+ <property name="default_view">view</property>
+ <property name="view_methods">
+ <element value="view"/>
+ </property>
+ <property name="default_view_fallback">False</property>
+ <property name="add_permission">cmf.AddPortalContent</property>
+ <property name="klass">pfwbged.tabellio.documents.Document</property>
+ <property name="behaviors">
+ <element value="plone.app.content.interfaces.INameFromTitle"/>
+ <element value="plone.app.dexterity.behaviors.metadata.IBasic"/>
+ </property>
+
+ <!-- Contained Types -->
+ <property name="filter_content_types">True</property>
+ <property name="allowed_content_types" purge="False">
+ </property>
+
+ <!-- DO NOT use a model_source or it removes manually added fields while reapplying the profile -->
+ <!--property name="model_source" /-->
+ <property name="schema">pfwbged.tabellio.documents.IDocument</property>
+ <alias from="(Default)" to="(dynamic view)"/>
+ <alias from="edit" to="@@edit"/>
+ <alias from="sharing" to="@@sharing"/>
+ <alias from="view" to="(selected layout)"/>
+ <action title="View" action_id="view" category="object" condition_expr=""
+ description="" icon_expr="" link_target="" url_expr="string:${object_url}"
+ visible="True">
+ <permission value="View"/>
+ </action>
+ <action title="Edit" action_id="edit" category="object" condition_expr=""
+ description="" icon_expr="" link_target=""
+ url_expr="string:${object_url}/edit" visible="True">
+ <permission value="Modify portal content"/>
+ </action>
+</object>