add new portal type for tabellio documents
This commit is contained in:
parent
04506ca850
commit
8a419c6c77
|
@ -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."""
|
||||
|
|
|
@ -18,5 +18,4 @@
|
|||
provides="Products.GenericSetup.interfaces.EXTENSION"
|
||||
/>
|
||||
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -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 []
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
Reference in New Issue