Пример #1
0
 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
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
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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
 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
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
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
 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
 def mover(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return translate_i18n(
         IDCDescriptiveProperties(context.owner).title_member)
Пример #46
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
Пример #47
0
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""
Пример #48
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return u"%s  (%s)" % (context.file_name, context.file_mimetype)
Пример #49
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "committee_type_status_name")
Пример #50
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
Пример #51
0
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""