Esempio n. 1
0
 def parliament_id(self):
     """Vocabularies in the forms get the parliament id from the context,
     this property returns the id of the parliament the currently logged in
     user is a member of
     """
     user = utils.get_db_user()
     user_parliament = utils.get_parliament_for_user(user)
     return user_parliament.group_id
Esempio n. 2
0
 def __init__(self, context):
     self.context = context
     user = utils.get_db_user()
     user_parliament = utils.get_parliament_for_user(user)
     if user_parliament:
         self.object_type = user_parliament.type
         self.oid = user_parliament.group_id
     else:
         self.object_type = None
         self.oid = None
Esempio n. 3
0
 def get_body_css_class(self):
     # Add custom css classes to the list below
     parliament_type = "default"
     user = utils.get_db_user()
     if user:
         parliament = utils.get_parliament_for_user(user)
         if parliament and parliament.parliament_type:
             parliament_type = parliament.parliament_type
     classes = ["yui-skin-sam", "section-bungeni-%s" % get_section_name(),
                "chamber-%s" % parliament_type]
     return " ".join(classes)
def get_current_parliament(date=None, context=None):
    """Return the parliament for a given date (or the current for no date)
    """
    #check logged in user's parliament:
    parliament = utils.get_parliament_for_user(utils.get_db_user())
    if parliament is None:
        if context is not None:
            # look for current parliament from context tree
            _parent = context
            while not interfaces.IParliament.providedBy(_parent):
                _parent = _parent.__parent__
                if _parent is None:
                    break
                elif interfaces.IParliament.providedBy(_parent):
                    parliament = _parent
                    break
    #assume unicameral
    if parliament is None:
        def getFilter(date):
            return sql.or_(
                sql.between(date, 
                    schema.group.c.start_date, schema.group.c.end_date),
                sql.and_(
                    schema.group.c.start_date<=date, 
                    schema.group.c.end_date==None))
        if not date:
            date = datetime.date.today()
        session = Session()
        query = session.query(domain.Parliament).filter(getFilter(date))
        try:
            parliament = query.one()
        except:
            ##XXX raise(_(u"inconsistent data: none or more than one parliament found for this date"))
            # !+DATA(mb, July-2012) this should get the one active parliament
            # needs some review if there is more than one parliament active e.g.
            # bicameral legislatures
            query = session.query(domain.Parliament).filter(schema.group.c.status=="active")
            try:
                parliament = query.one()
            except Exception, e:
                log.error("Could not find active parliament. Activate a parliament"
                    " in Bungeni admin :: %s", e.__repr__())
                raise ValueError("Unable to locate a currently active parliament")
Esempio n. 5
0
 def __setitem__(self, name, item):
     session = Session()
     user = utils.get_db_user()
     user_parliament = utils.get_parliament_for_user(user)
     item.parliament_id = user_parliament.parliament_id
     session.add(item)