コード例 #1
0
ファイル: states.py プロジェクト: mohalfaki/bungeni-portal
 def initialize(self, context):
     """Initialize content now in this state.
     """
     session = Session()
     _context = removeSecurityProxy(context)
     session.merge(_context)
     rpm = zope.securitypolicy.interfaces.IRolePermissionMap(_context)
     for action, permission, role in self.permissions:
         if action==GRANT:
            rpm.grantPermissionToRole(permission, role)
         if action==DENY:
            rpm.denyPermissionToRole(permission, role)
コード例 #2
0
ファイル: files.py プロジェクト: BenoitTalbot/bungeni-portal
def objectNewVersion(ob, event):
    """ when an object is versioned we copy the attachments 
    to the version"""
    if type(ob) == domain.AttachedFileVersion:
        return
    ob = removeSecurityProxy(ob)
    session = Session()
    session.merge(ob)
    session.flush()
    for attached_file in ob.head.attached_files:
        versions = interfaces.IVersioned(attached_file)
        version = versions.create("version created on object versioning: %s" % getattr(ob.change, "description", ""))
        version.file_version_id = ob.version_id
コード例 #3
0
ファイル: files.py プロジェクト: mohalfaki/bungeni-portal
def objectNewVersion(ob, event):
    """ when an object is versioned we copy the attachments 
    to the version"""
    if type(ob) == domain.AttachedFileVersion:
        return
    ob = removeSecurityProxy(ob)
    session = Session()
    session.merge(ob)
    session.flush()
    for attached_file in ob.head.attached_files:
        versions = interfaces.IVersioned(attached_file)
        version = versions.create('version created on object versioning: %s' %
                                  getattr(ob.change, 'description', ''))
        version.file_version_id = ob.version_id
コード例 #4
0
 def legislature(self):
     """Get the Legislature singleton instance -- ALWAYS call this from
     anywhere in the code to retrieve the Legislature singleton.
     Raises sqlalchemy.orm.exc.NoResultFound.        
     """
     from bungeni.alchemist import Session
     from bungeni.models.domain import Legislature
     session = Session()
     if Legislature._instance is None:
         session.query(Legislature).one() # this primes Legislature._instance
     # merge to avoid sqlalchemy.orm.exc.DetachedInstanceError
     session.merge(Legislature._instance)
     assert Legislature._instance.group_id is not None # !+LEGISLATURE_SETUP
     # retrieve the Legislature singleton by just "creating" a new one
     return Legislature()
コード例 #5
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     time = context.sitting_time
     if time is not None:
         return "%s (%s)" % (_(u"Discussion"), context.sitting_time)
     return _(u"Discussion")
コード例 #6
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s - %s" % (
         #self.context.type.capitalize(),
         context.short_name,
         context.full_name)
コード例 #7
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if context.motion_number is None:
         return self.translate(context, "short_name")
     return "#%d: %s" % (context.motion_number,
                         self.translate(context, "short_name"))
コード例 #8
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return '%s - %i' % (
         self.translate(context.constituency, "name"),
         context.date.year
     )
コード例 #9
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s - %s" % (
         #self.context.type.capitalize(),
         context.short_name,
         context.full_name)
コード例 #10
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s (%s %s %s)" % (
         _(u"Sitting scheduled for"), context.group.short_name,
         context.start_date.strftime('%Y-%m-%d %H:%M'), _(u"to"),
         context.end_date.strftime('%H:%M'))
コード例 #11
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title_member(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     mp_user = None
     try:
         mp_user = (
             session.query(domain.MemberOfParliament)
             .filter(domain.MemberOfParliament.user_id == context.user_id)
             .one()
         )
     except NoResultFound:
         # this user has no associated MP record
         pass
     except MultipleResultsFound:
         # this should not happen
         log.error("Multiple MP objects found for : %s", context.__str__())
     finally:
         if mp_user is None:
             return self.title
     dc_constituency = IDCDescriptiveProperties(mp_user.constituency)
     return _(
         "member_title_with_constituency",
         default=u"Member of Parliament for ${constituency} (${member})",
         mapping={"constituency": dc_constituency.title, "member": self.title},
     )
コード例 #12
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s - %s" % (
         #self.context.type.capitalize(),
         self.translate(context, "short_name"),
         self.translate(context, "full_name"))
コード例 #13
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s - %s" % (
         #self.context.type.capitalize(),
         self.translate(context, "short_name"),
         self.translate(context, "full_name"))
コード例 #14
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return '%s - %s ' % (
             self.translate(context.item, "short_name"), 
             self.translate(context.group, "short_name")
     )
コード例 #15
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s, %s %s %s" % (
         _(u"Sitting:"), context.group.short_name,
         context.start_date.strftime('%Y-%m-%d, %H:%M'), _(u"to"),
         context.end_date.strftime('%H:%M'))
コード例 #16
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (translate_i18n(_(u"Submitted by")), context.owner.first_name, context.owner.last_name)
     if context.notice_date:
         text += " (%s %s)" % (translate_i18n(_(u"notice given on")), self.formatDate(context.notice_date))
     return text + "."
コード例 #17
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     sitting = context.sitting
     return _(
         u"Scheduled for sitting ($start to $end)", mapping={"start": sitting.start_date, "end": sitting.end_date}
     )
コード例 #18
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     sitting = context.sitting
     return _(u"Scheduled for sitting ($start to $end)",
              mapping={'start': sitting.start_date,
                       'end': sitting.end_date})
コード例 #19
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if getattr(context, "delegation", None):
         return u"%s %s" % (context.delegation.first_name, context.delegation.last_name)
     else:
         return u""
コード例 #20
0
ファイル: states.py プロジェクト: mohalfaki/bungeni-portal
 def initialize(self, workflow_info, context):
     """Initialize content now in this state.
     """
     session = Session()
     instance = removeSecurityProxy(context)
     session.merge(instance)
     # version
     if self.version_action:
         self.version_action(workflow_info, instance)
     # permissions
     rpm = zope.securitypolicy.interfaces.IRolePermissionMap(instance)
     for action, permission, role in self.permissions:
         if action==GRANT:
            rpm.grantPermissionToRole(permission, role)
         if action==DENY:
            rpm.denyPermissionToRole(permission, role)
コード例 #21
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return u"%s %s to %s" % (translate_i18n(_(u"Covers")), 
         context.start_date.strftime('%Y-%m-%d'),
         context.end_date.strftime('%Y-%m-%d')
     )
コード例 #22
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title_member(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     mp_user = None
     try:
         mp_user = session.query(domain.MemberOfParliament).filter(
             domain.MemberOfParliament.user_id == context.user_id
         ).one()
     except NoResultFound:
         #this user has no associated MP record
         pass
     except MultipleResultsFound:
         # this should not happen
         log.error("Multiple MP objects found for : %s", context.__str__())
     finally:
         if mp_user is None:
             return self.title
     dc_constituency = IDCDescriptiveProperties(mp_user.constituency)
     return _("member_title_with_constituency",
             default=u"Member of Parliament for ${constituency} (${member})",
             mapping = {
                 "constituency": dc_constituency.title,
                 "member": self.title
             }
     )
コード例 #23
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     time = context.sitting_time
     if time is not None:
         return "%s (%s)" % (_(u"Discussion"), context.sitting_time)
     return _(u"Discussion")
コード例 #24
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if context.question_number is None:
         return self.translate(context, "short_name")
     return "#%d: %s" % (
         context.question_number,
         self.translate(context,"short_name"))
コード例 #25
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s (%s %s %s)" % (_(u"Sitting scheduled for"),
             context.group.short_name,
             context.start_date.strftime('%Y-%m-%d %H:%M'), 
             _(u"to"),
             context.end_date.strftime('%H:%M'))
コード例 #26
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s, %s %s %s" % (_(u"Sitting:"), 
             self.translate(context.group, "short_name"), 
             context.start_date.strftime('%Y-%m-%d, %H:%M'), 
             _(u"to"), 
             context.end_date.strftime('%H:%M'))
コード例 #27
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if getattr(context, 'delegation', None):
         return u'%s %s' % (context.delegation.first_name,
                            context.delegation.last_name)
     else:
         return u""
コード例 #28
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if context.user:
         return "%s %s %s" % (context.user.titles, context.user.first_name,
                              context.user.last_name)
     else:
         return u"New User"
コード例 #29
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if context.question_number is None:
         return context.short_name
     return "#%d: %s" % (
         context.question_number,
         context.short_name)
コード例 #30
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (_("Submitted by"),
                         context.owner.first_name, context.owner.last_name)
     if context.publication_date:
         text += " (%s %s)" % (_(u"published on"),
                               self.formatDate(context.publication_date))
     return text + "."
コード例 #31
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     if context.user:
         return "%s %s %s" % (self.translate(context.user, "titles"),
             context.user.first_name,
             context.user.last_name)
     else:
         return u"New User"
コード例 #32
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (translate_i18n(_(u"Submitted by")),
                          context.owner.first_name, context.owner.last_name)
     if context.notice_date:
         text += " (%s %s)" % (translate_i18n(
             _(u"notice given on")), self.formatDate(context.notice_date))
     return text + "."
コード例 #33
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (_("Submitted by"), context.owner.first_name, context.owner.last_name)
     if context.ministry:
         text += " to %s" % IDCDescriptiveProperties(context.ministry).title
     if context.admissible_date:
         text += " (%s %s)" % (_(u"Approved on"), self.formatDate(context.admissible_date))
     return text + "."
コード例 #34
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return "%s %s (%s %s %s)" % (
         translate_i18n(_(u"Sitting scheduled for")),
         self.translate(context.group, "short_name"),
         context.start_date.strftime("%Y-%m-%d %H:%M"),
         _(u"to"),
         context.end_date.strftime("%H:%M"),
     )
コード例 #35
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def verbose_title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     sitting_title = _("verbose_sitting_title", 
         default=u"Sitting of ${group_name} @ ${sitting_venue}",
         mapping = {
             "group_name": IDCDescriptiveProperties(context.group).title,
             "sitting_venue": IDCDescriptiveProperties(context.venue).title
         }
     )
     return translate_i18n(sitting_title)
コード例 #36
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     text = "%s %s %s" % (_("Submitted by"), context.owner.first_name,
                          context.owner.last_name)
     if context.ministry:
         text += " to %s" % IDCDescriptiveProperties(context.ministry).title
     if context.admissible_date:
         text += " (%s %s)" % (_(u"Approved on"),
                               self.formatDate(context.admissible_date))
     return text + "."
コード例 #37
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def verbose_title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     sitting_title = _(
         "verbose_sitting_title",
         default=u"Sitting of ${group_name} @ ${sitting_venue}",
         mapping={
             "group_name": IDCDescriptiveProperties(context.group).title,
             "sitting_venue": IDCDescriptiveProperties(context.venue).title
         })
     return translate_i18n(sitting_title)
コード例 #38
0
ファイル: files.py プロジェクト: BenoitTalbot/bungeni-portal
def objectNewVersion(ob, event):
    """When an object is versioned we copy the attachments to the version.
    """
    if type(ob) == domain.AttachedFileVersion:
        return
    ob = removeSecurityProxy(ob)
    session = Session()
    session.merge(ob)
    session.flush()
    ''' !+ATTACHED_FILE_VERSIONS(mr, sep-2011) consider alternative way to 
    handle the "snapshotting" of attached_files (on versioning of head object) 
    i.e:
    a) to NEVER modify a db record of a file attachment
    b) if EDIT of an attachment is to be supported, expose an edit view, but
    saving a "modified" attachment means *replacing* it with a new record (this 
    also serves as an automatic changelog mechanism on any change). 
    Note, each attached_file would need thus need to record pointer back to 
    "previous" version.
    c) this results in that an explicit VERSIONING of an attachment 
    (independently of its owning item) should no longer be needed... given that 
    any CHANGE in an attachment's info systematically causes a new version.
    d) versioning of a "head item" (and of any of its attachments at that time)
    now implies only copying of FK refs to any attachments on the head object.
    
    The above has several advantages:
    
    - multiple attachments per item are not needlessly copied over each time 
    a head object is versioned, thus reducing data duplication/noise.
    - does not *lose* semantics in the persisted information i.e. currently a
    version of a head item points to a *version* of an attachment that is 
    in *most* cases *identical* to the "head attachment" it is versioning...
    but to know whether it *is* the same object some additional checking 
    would be needed. With this scheme, if the head item OR ANY version of it 
    have the *same logical* attachment instance then they would point to the 
    SAME attachment db record.
    '''
    for attached_file in ob.head.attached_files:
        versions = IVersioned(attached_file)
        version = versions.create('version created on object versioning: %s' %
                getattr(ob.change, 'description', ''))
        version.file_version_id = ob.version_id
コード例 #39
0
ファイル: files.py プロジェクト: mohalfaki/bungeni-portal
def objectNewVersion(ob, event):
    """When an object is versioned we copy the attachments to the version.
    """
    if type(ob) == domain.AttachedFileVersion:
        return
    ob = removeSecurityProxy(ob)
    session = Session()
    session.merge(ob)
    session.flush()
    ''' !+ATTACHED_FILE_VERSIONS(mr, sep-2011) consider alternative way to 
    handle the "snapshotting" of attached_files (on versioning of head object) 
    i.e:
    a) to NEVER modify a db record of a file attachment
    b) if EDIT of an attachment is to be supported, expose an edit view, but
    saving a "modified" attachment means *replacing* it with a new record (this 
    also serves as an automatic changelog mechanism on any change). 
    Note, each attached_file would need thus need to record pointer back to 
    "previous" version.
    c) this results in that an explicit VERSIONING of an attachment 
    (independently of its owning item) should no longer be needed... given that 
    any CHANGE in an attachment's info systematically causes a new version.
    d) versioning of a "head item" (and of any of its attachments at that time)
    now implies only copying of FK refs to any attachments on the head object.
    
    The above has several advantages:
    
    - multiple attachments per item are not needlessly copied over each time 
    a head object is versioned, thus reducing data duplication/noise.
    - does not *lose* semantics in the persisted information i.e. currently a
    version of a head item points to a *version* of an attachment that is 
    in *most* cases *identical* to the "head attachment" it is versioning...
    but to know whether it *is* the same object some additional checking 
    would be needed. With this scheme, if the head item OR ANY version of it 
    have the *same logical* attachment instance then they would point to the 
    SAME attachment db record.
    '''
    for attached_file in ob.head.attached_files:
        versions = IVersioned(attached_file)
        version = versions.create('version created on object versioning: %s' %
                                  getattr(ob.change, 'description', ''))
        version.file_version_id = ob.version_id
コード例 #40
0
 def title_member(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     mp_user = session.query(domain.MemberOfParliament).filter(
         domain.MemberOfParliament.user_id == context.user_id
     ).one()
     if mp_user is None:
         return self.title
     dc_constituency = IDCDescriptiveProperties(mp_user.constituency)
     return _("member_title_with_constituency",
             default=u"Member of Parliament for ${constituency} (${member})",
             mapping = {
                 "constituency": dc_constituency.title,
                 "member": self.title
             }
     )
コード例 #41
0
 def _traverse(self, request, name):
     self.context = removeSecurityProxy(self.context)
     session = Session()
     context = session.merge(self.context)
     hansard = session.query(domain.Hansard) \
                             .filter(domain.Hansard.group_sitting_id 
                                             == context.group_sitting_id) \
                             .first()
     if not hansard:
         hansard = domain.Hansard()
         hansard.group_sitting_id = context.group_sitting_id
         session.add(hansard)
         session.flush()
         hansard.media_paths = domain.HansardMediaPaths()
     hansard.__name__ = 'hansard'
     hansard.__parent__ = self.context
     interface.alsoProvides(hansard, ILocation)
     return hansard
コード例 #42
0
 def _traverse(self, request, name):
     self.context = removeSecurityProxy(self.context)
     session = Session()
     context = session.merge(self.context)
     hansard = session.query(domain.Hansard) \
                             .filter(domain.Hansard.group_sitting_id
                                             == context.group_sitting_id) \
                             .first()
     if not hansard:
         hansard = domain.Hansard()
         hansard.group_sitting_id = context.group_sitting_id
         session.add(hansard)
         session.flush()
         hansard.media_paths = domain.HansardMediaPaths()
     hansard.__name__ = 'hansard'
     hansard.__parent__ = self.context
     interface.alsoProvides(hansard, ILocation)
     return hansard
コード例 #43
0
 def _traverse(self, request, name):
     self.context = removeSecurityProxy(self.context)
     session = Session()
     context = session.merge(self.context)
     debate = session.query(domain.DebateRecord) \
         .filter(domain.DebateRecord.sitting_id
             == context.sitting_id) \
             .first()
     if not debate:
         debate = domain.DebateRecord()
         debate.sitting_id = context.sitting_id
         session.add(debate)
         wfc = IWorkflowController(debate)
         wfc.fireAutomatic()
         session.flush()
     debate.__name__ = self.traversalName
     debate.__parent__ = self.context
     interface.alsoProvides(debate, ILocation)
     return debate
コード例 #44
0
ファイル: adaptors.py プロジェクト: gelie/bungeni_src
 def _traverse(self, request, name):
     self.context = removeSecurityProxy(self.context)
     session = Session()
     context = session.merge(self.context)
     debate = session.query(domain.DebateRecord) \
         .filter(domain.DebateRecord.sitting_id
             == context.sitting_id) \
             .first()
     if not debate:
         debate = domain.DebateRecord()
         debate.sitting_id = context.sitting_id
         session.add(debate)
         wfc = IWorkflowController(debate)
         wfc.fireAutomatic()
         session.flush()
     debate.__name__ = self.traversalName
     debate.__parent__ = self.context
     interface.alsoProvides(debate, ILocation)
     return debate
コード例 #45
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def mover(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return translate_i18n(
         IDCDescriptiveProperties(context.owner).title_member)
コード例 #46
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
コード例 #47
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""
コード例 #48
0
ファイル: dc.py プロジェクト: mohalfaki/bungeni-portal
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return u"%s  (%s)" % (context.file_name, context.file_mimetype)
コード例 #49
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "committee_type_status_name")
コード例 #50
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
コード例 #51
0
ファイル: dc.py プロジェクト: BenoitTalbot/bungeni-portal
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""