Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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"))
Ejemplo n.º 8
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return '%s - %i' % (
         self.translate(context.constituency, "name"),
         context.date.year
     )
Ejemplo n.º 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)
Ejemplo n.º 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'))
Ejemplo n.º 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},
     )
Ejemplo n.º 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"))
Ejemplo n.º 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"))
Ejemplo n.º 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")
     )
Ejemplo n.º 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'))
Ejemplo n.º 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 + "."
Ejemplo n.º 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}
     )
Ejemplo n.º 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})
Ejemplo n.º 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""
Ejemplo n.º 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)
Ejemplo n.º 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')
     )
Ejemplo n.º 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
             }
     )
Ejemplo n.º 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")
Ejemplo n.º 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"))
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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""
Ejemplo n.º 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"
Ejemplo n.º 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)
Ejemplo n.º 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 + "."
Ejemplo n.º 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"
Ejemplo n.º 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 + "."
Ejemplo n.º 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 + "."
Ejemplo n.º 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"),
     )
Ejemplo n.º 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)
Ejemplo n.º 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 + "."
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
             }
     )
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 45
0
 def mover(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return translate_i18n(
         IDCDescriptiveProperties(context.owner).title_member)
Ejemplo n.º 46
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
Ejemplo n.º 47
0
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""
Ejemplo n.º 48
0
 def description(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return u"%s  (%s)" % (context.file_name, context.file_mimetype)
Ejemplo n.º 49
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "committee_type_status_name")
Ejemplo n.º 50
0
 def title(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return self.translate(context, "title_name")
Ejemplo n.º 51
0
 def uri(self):
     session = Session()
     context = session.merge(removeSecurityProxy(self.context))
     return (context.uri or "") if hasattr(context, "uri") else ""