2011-11-02 10:07:34 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2011-08-09 16:57:12 +02:00
|
|
|
from five import grok
|
|
|
|
from zope import schema
|
|
|
|
from zope.interface import implements
|
|
|
|
|
|
|
|
from plone.directives import form, dexterity
|
|
|
|
from plone.dexterity.content import Item
|
2011-08-11 17:26:07 +02:00
|
|
|
from z3c.relationfield.schema import RelationChoice, RelationList
|
|
|
|
from plone.formwidget.contenttree import ObjPathSourceBinder
|
|
|
|
from z3c.relationfield.interfaces import IHasRelations
|
2011-10-19 19:09:19 +02:00
|
|
|
from plone.namedfile.field import NamedBlobFile
|
2011-08-09 16:57:12 +02:00
|
|
|
|
|
|
|
from themis.fields import LegisSession
|
|
|
|
|
|
|
|
from tabellio.documents.interfaces import MessageFactory as _
|
2011-08-24 13:36:03 +02:00
|
|
|
from tabellio.config.utils import get_documents_path
|
2011-08-09 16:57:12 +02:00
|
|
|
|
2011-11-03 16:33:17 +01:00
|
|
|
import typenames
|
|
|
|
|
2011-11-11 17:19:14 +01:00
|
|
|
from common import BasePublication
|
|
|
|
|
2011-08-09 16:57:12 +02:00
|
|
|
class IDocument(form.Schema):
|
|
|
|
title = schema.TextLine(title=_(u'Title'))
|
2011-10-19 19:09:19 +02:00
|
|
|
no = schema.TextLine(title=_('Number'), required=False)
|
2011-08-09 16:57:12 +02:00
|
|
|
session = LegisSession(title=_(u'Session'))
|
2011-10-19 19:09:19 +02:00
|
|
|
nodoc = schema.TextLine(title=_('Secondary Number'), required=False)
|
2011-11-18 15:31:52 +01:00
|
|
|
noannexe = schema.TextLine(title=_('Appendix Number'), required=False)
|
2011-08-09 16:57:12 +02:00
|
|
|
date = schema.Date(title=_(u'Date'))
|
2011-08-11 17:26:07 +02:00
|
|
|
authors = RelationList(title=_(u'Authors'), default=[], required=False,
|
|
|
|
value_type=RelationChoice(title=_(u'Author'),
|
|
|
|
source=ObjPathSourceBinder()))
|
2011-11-11 14:30:30 +01:00
|
|
|
topics = schema.Set(title=_(u'Topics'), required=False,
|
|
|
|
value_type=schema.TextLine(title=_(u'Topic')))
|
2011-11-03 10:57:55 +01:00
|
|
|
polgroups = RelationList(title=_(u'Political Groups'), default=[], required=False,
|
2011-11-03 14:47:50 +01:00
|
|
|
value_type=RelationChoice(title=_(u'Political Group'),
|
2011-11-03 10:57:55 +01:00
|
|
|
source=ObjPathSourceBinder()))
|
2011-10-19 19:09:19 +02:00
|
|
|
doctype = schema.TextLine(title=_('Document Type'))
|
|
|
|
file = NamedBlobFile(title=_('File'), required=False)
|
2011-11-03 14:08:09 +01:00
|
|
|
file_image_id = schema.TextLine(title=_('File Image Id'), required=False)
|
2011-08-09 16:57:12 +02:00
|
|
|
|
2011-11-03 14:46:40 +01:00
|
|
|
parent_dossier = RelationChoice(title=_(u'Parent File'), required=False,
|
|
|
|
source=ObjPathSourceBinder())
|
2011-11-16 19:40:24 +01:00
|
|
|
final_version = schema.Bool(title=_(u'Final Version'), required=False, default=False)
|
2011-11-21 13:42:11 +01:00
|
|
|
publication_date = schema.Date(title=_(u'Publication Date'), required=False)
|
|
|
|
adoption_date = schema.Date(title=_(u'Adoption Date'), required=False)
|
|
|
|
moniteur_date = schema.Date(title=_(u'Moniteur Date'), required=False)
|
2011-11-03 14:46:40 +01:00
|
|
|
|
2011-12-04 14:53:11 +01:00
|
|
|
# reserved for PFB
|
|
|
|
adopted = schema.Bool(title=_(u'Adopted'), required=False, default=False)
|
|
|
|
related_docs = RelationList(title=_(u'Related Documents'), default=[], required=False,
|
|
|
|
value_type=RelationChoice(title=_(u'Related Document'), source=ObjPathSourceBinder()))
|
2012-04-17 10:45:01 +02:00
|
|
|
sanction_date = schema.Date(title=_(u'Sanction Date'), required=False)
|
|
|
|
commission_status = schema.TextLine(title=_('Commission Status', required=False)
|
|
|
|
seance_vote = schema.TextLine(title=_('Seance Vote', required=False)
|
|
|
|
|
2011-11-23 17:34:24 +01:00
|
|
|
|
2011-11-11 17:19:14 +01:00
|
|
|
class Document(Item, BasePublication):
|
2011-08-11 17:26:07 +02:00
|
|
|
implements(IDocument, IHasRelations)
|
2011-08-24 13:36:03 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def canonical_path(self):
|
|
|
|
return '/' + get_documents_path() + '/' + self.id
|
2011-10-21 15:25:22 +02:00
|
|
|
|
2011-11-02 10:07:34 +01:00
|
|
|
@property
|
|
|
|
def doctype_str(self):
|
2011-12-04 13:06:54 +01:00
|
|
|
if self.doctype is None: return _('Unknown')
|
|
|
|
return typenames.MAPPING.get(self.doctype, self.doctype)
|
2011-11-02 10:07:34 +01:00
|
|
|
|
|
|
|
@property
|
2011-12-05 19:21:29 +01:00
|
|
|
def refno(self):
|
2011-12-04 13:16:40 +01:00
|
|
|
if not self.no:
|
2011-12-05 19:21:29 +01:00
|
|
|
return '(%s)' % self.session
|
2011-11-07 14:11:17 +01:00
|
|
|
if self.nodoc:
|
2011-11-18 16:25:58 +01:00
|
|
|
if self.noannexe:
|
2011-12-05 19:21:29 +01:00
|
|
|
return u'%s (%s) - N° %s (Annexe %s)' % (
|
|
|
|
self.no, self.session, self.nodoc, self.noannexe)
|
2011-11-18 16:25:58 +01:00
|
|
|
else:
|
2011-12-05 19:21:29 +01:00
|
|
|
return u'%s (%s) - N° %s' % (self.no, self.session, self.nodoc)
|
2011-11-07 14:11:17 +01:00
|
|
|
else:
|
2011-11-18 16:25:58 +01:00
|
|
|
if self.noannexe:
|
2011-12-05 19:21:29 +01:00
|
|
|
return '%s (%s) (Annexe %s)' % (self.no, self.session, self.noannexe)
|
2011-11-18 16:25:58 +01:00
|
|
|
else:
|
2011-12-05 19:21:29 +01:00
|
|
|
return '%s (%s)' % (self.no, self.session)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def reftitle(self):
|
|
|
|
if not self.no:
|
|
|
|
return '%s (%s)' % (self.doctype_str, self.session)
|
|
|
|
return u'%s - %s' % (self.doctype_str, self.refno)
|
2011-11-11 22:34:00 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def associated_docs(self):
|
|
|
|
if not self.parent_dossier:
|
|
|
|
return []
|
|
|
|
docs = []
|
|
|
|
dossier = self.parent_dossier.to_object
|
|
|
|
if not dossier:
|
|
|
|
return None
|
|
|
|
doc_ids = [self.id]
|
|
|
|
for histoline in dossier.histolines:
|
|
|
|
if not histoline.document: continue
|
|
|
|
if histoline.document.to_object.getId() in doc_ids: continue
|
|
|
|
doc = histoline.document.to_object
|
|
|
|
docs.append(histoline.document.to_object)
|
|
|
|
doc_ids.append(histoline.document.to_object.getId())
|
|
|
|
return docs
|
|
|
|
|
2011-11-11 23:38:33 +01:00
|
|
|
def related_elements(self, max_items=5, closeness=0.5):
|
|
|
|
r = BasePublication.related_elements(self, max_items, closeness)
|
2011-12-06 21:45:02 +01:00
|
|
|
doc_ids = [x.id for x in (self.associated_docs or [])]
|
2011-11-21 18:09:45 +01:00
|
|
|
return [x for x in r if ((type(x.getId) is str) and x.getId or x.getId()) not in doc_ids]
|
2011-11-16 20:13:27 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def publication_date_str(self):
|
|
|
|
return self.publication_date.strftime('%d/%m/%Y')
|
2011-11-21 13:58:48 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def adoption_date_str(self):
|
|
|
|
return self.adoption_date.strftime('%d/%m/%Y')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def moniteur_date_str(self):
|
|
|
|
return self.moniteur_date.strftime('%d/%m/%Y')
|
2012-04-17 10:48:52 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def sanction_date_str(self):
|
|
|
|
return self.sanction_date.strftime('%d/%m/%Y')
|