예제 #1
0
 def as_json(self):
     is_text = IScheduleText.implementedBy(self.domain_class)
     date_formatter = date.getLocaleFormatter(common.get_request(), "date",
                                              "medium")
     items = [
         dict(
             item_type=self.item_type,
             item_id=orm.object_mapper(item).primary_key_from_instance(
                 item)[0],
             item_title=IDCDescriptiveProperties(item).title,
             status=(IWorkflow(item).get_state(item.status).title
                     if not is_text else None),
             status_date=(date_formatter.format(item.submission_date) if
                          (hasattr(item, "submission_date")
                           and getattr(item, "submission_date")) else None),
             registry_number=(item.registry_number if hasattr(
                 item, "registry_number") else None),
             item_mover=(IDCDescriptiveProperties(item.owner).title
                         if hasattr(item, "owner") else None),
             item_uri="%s-%d" %
             (self.item_type,
              orm.object_mapper(item).primary_key_from_instance(item)[0]))
         for item in self.query()
     ]
     items = sorted(items,
                    key=lambda item: item.get("status_date"),
                    reverse=True)
     return json.dumps(dict(items=items))
예제 #2
0
def get_listings(context, request, sub_container_name=""):
    trusted = removeSecurityProxy(context)
    if hasattr(trusted, sub_container_name):
        sub_container = removeSecurityProxy(
            getattr(trusted, sub_container_name))
        #!+DESCRIPTOR_LOOKUP(murithi, jul-2011) descriptor lookup fails in
        # testing - as at r8474 : use sub_container_name as title
        #table_title = (CONTAINER_TITLES.get(sub_container_name, None) or
        #    IDCDescriptiveProperties(sub_container).title
        #)
        table_title = sub_container_name
        columns = [
            LinkColumn("title",
                       lambda i, f: IDCDescriptiveProperties(i).title),
        ]
        for extra_col in EXTRA_COLUMNS.get(sub_container_name, []):
            columns.append(
                column.GetterColumn(
                    extra_col, lambda i, f: getattr(
                        IDCDescriptiveProperties(i), extra_col)))
        if hasattr(sub_container, "values"):
            items = [removeSecurityProxy(it) for it in sub_container.values()]
        else:
            items = [removeSecurityProxy(it) for it in sub_container]
        if not len(items):
            return u""
        formatter = SimpleContainerListing(context,
                                           request,
                                           items,
                                           columns=columns)
        return formatter(translate_i18n(table_title))
    else:
        return u""
예제 #3
0
 def get_items_by_type(self, item_type):
     day = u""
     day_list = []
     s_dict = {}
     formatter = self.request.locale.dates.getFormatter("date", "full")
     for schedule in self.itemschedules:
         if type(schedule.item) == item_type:
             sday = formatter.format(schedule.sitting.start_date)
             if sday != day:
                 s_list = []
                 day = sday
                 if s_dict:
                     day_list.append(s_dict)
                 s_dict = {}
             s_list.append({
                 "name":
                 IDCDescriptiveProperties(schedule.item).title,
                 "status":
                 str(misc.get_wf_state(schedule.item)),
                 "url":
                 url.set_url_context(
                     "/business/%ss/obj-%s" %
                     (schedule.item.type, schedule.item.doc_id)),
                 "group_type":
                 schedule.sitting.group.type,
                 "group_name":
                 schedule.sitting.group.short_name
             })
             s_dict["day"] = day
             s_dict["items"] = s_list
     if s_dict:
         day_list.append(s_dict)
     return day_list
예제 #4
0
 def get_items_by_type(self, item_type):
     day = u''
     day_list = []
     s_dict = {}
     formatter = self.request.locale.dates.getFormatter('date', 'full')
     for schedule in self.itemschedules:
         if type(schedule.item) == item_type:
             sday = formatter.format(schedule.sitting.start_date)
             if sday != day:
                 s_list = []
                 day = sday
                 if s_dict:
                     day_list.append(s_dict)
                 s_dict = {}
             s_list.append({
                 'name':
                 IDCDescriptiveProperties(schedule.item).title,
                 'status':
                 str(misc.get_wf_state(schedule.item)),
                 'url':
                 url.set_url_context("/business/%ss/obj-%s" %
                                     (schedule.item.type,
                                      schedule.item.parliamentary_item_id)),
                 'group_type':
                 schedule.sitting.group.type,
                 'group_name':
                 schedule.sitting.group.short_name
             })
             s_dict['day'] = day
             s_dict['items'] = s_list
     if s_dict:
         day_list.append(s_dict)
     return day_list
예제 #5
0
 def page_description(self):
     """Formalize view.page_description as a view property to factor the 
     logic for determining the page description for a view out of the 
     template.
     
     Templates should always simply call: view.page_description
     """
     # if view explicitly sets a page_description, use it
     if self._page_description:
         return self._page_description
     # otherwise try to determine it from DC annotations
     context = removeSecurityProxy(self.context)
     try:
         # This is equivalent of the ZPT expression "context/dc:description"
         # i.e. to "load the value of the variable context, then find a
         # component that adapts that object to Dublin Core and read the
         # description attribute of the component."
         return IDCDescriptiveProperties(context).description
     except (Exception, ):
         debug.log_exc(sys.exc_info(), log_handler=log.debug)
     # otherwise try to determine it from the context
     if getattr(context, "description", None):
         return context.description
     else:
         return "Bungeni"
예제 #6
0
def get_element_value(context, name, default=None):
    if name.startswith("dc:"):
        dc_context = (context.sitting
                      if isinstance(context, ExpandedSitting) else context)
        dc_adapter = IDCDescriptiveProperties(dc_context, None)
        if dc_adapter is None:
            log.error("No dublin core adapter found for object %s.", context)
            return default
        else:
            try:
                return getattr(dc_adapter, name[3:])
            except AttributeError:
                log.error("Dublin core adapter %s for %s has no attribute %s.",
                          dc_adapter, context, name)
                return default
    else:
        try:
            value = getattr(context, name)
            assert value is not None
            return value
        except AssertionError:
            msg = "Context %s attribute %s is None. Check report template."
        except AttributeError:
            msg = "Context %s has no such attribute %s. Check report template."
        log.error(msg, context, name)
        return default
예제 #7
0
 def getMenuItems(self, context, request):
     results = []
     unproxied = proxy.removeSecurityProxy(context.__parent__)
     try:
         items = unproxied.items()
     except AttributeError:
         items = []
         for key, info in capi.iter_type_info():
             if IScheduleContent.implementedBy(info.domain_model):
                 name = naming.plural(key)
                 if hasattr(unproxied, name):
                     items.append((name, getattr(unproxied, name)))
     for key, item in items:
         if not IAlchemistContainer.providedBy(item): continue
         if not IScheduleContent.implementedBy(item.domain_model): continue
         type_info = capi.get_type_info(item.domain_model)
         permission = "bungeni.%s.Add" % (
             type_info.workflow_key
             or naming.type_key("model_name", item.domain_model.__name__))
         if not checkPermission(permission, context): continue
         dc_adapter = IDCDescriptiveProperties(item, None)
         if dc_adapter:
             _title = dc_adapter.title
         else:
             _title = getattr(item, "title", "Unknown")
         results.append(
             dict(title=_title,
                  description=_title,
                  action=url.absoluteURL(item, request),
                  selected=False,
                  icon=None,
                  extra={},
                  submenu=None))
     return results
예제 #8
0
 def as_json(self):
     date_formatter = date.getLocaleFormatter(common.get_request(), "date",
                                              "medium")
     items_json = dict(items=[
         dict(item_type=self.item_type,
              item_id=orm.object_mapper(item).primary_key_from_instance(
                  item)[0],
              item_title=IDCDescriptiveProperties(item).title,
              status=IWorkflow(item).get_state(item.status).title,
              status_date=(date_formatter.format(item.submission_date)
                           if hasattr(item, "submission_date") else None),
              registry_number=(item.registry_number if hasattr(
                  item, "registry_number") else None),
              item_mover=(IDCDescriptiveProperties(item.owner).
                          title if hasattr(item, "owner") else None),
              item_uri=IDCDescriptiveProperties(item).uri)
         for item in self.query()
     ])
     return json.dumps(items_json)
예제 #9
0
 def __call__(self, context=None):
     query = self.constructQuery(context)
     results = query.all()
     terms = []
     for ob in results:
         terms.append(
             vocabulary.SimpleTerm(value=ob.venue_id,
                                   token=ob.venue_id,
                                   title="%s" %
                                   IDCDescriptiveProperties(ob).title))
     return vocabulary.SimpleVocabulary(terms)
예제 #10
0
 def get_sitting_items(self, sitting):
     s_list = []
     if sitting.status in self._agenda_private_state_ids:
         return s_list
     else:
         for schedule in sitting.item_schedule:
             descriptor = queryModelDescriptor(schedule.item.__class__)
             s_list.append({
                 "name":
                 IDCDescriptiveProperties(schedule.item).title,
                 "status":
                 str(misc.get_wf_state(schedule.item)),
                 "url":
                 IDCDescriptiveProperties(schedule.item).uri,
                 "item_type":
                 schedule.item.type,
                 "heading":
                 True if schedule.item.type == "heading" else False,
                 "item_type_title": (descriptor.display_name
                                     if descriptor else schedule.item.type),
             })
         return s_list
예제 #11
0
 def __getattr__(self, name):
     """ Attribute lookup fallback - Sitting should have access to item
     """
     if name in self.grouped.keys():
         return self.grouped.get(name)
     if hasattr(self.sitting, name):
         return getattr(self.sitting, name)
     dc_adapter = IDCDescriptiveProperties(self.sitting)
     if hasattr(dc_adapter, name):
         return getattr(dc_adapter, name)
     else:
         log.error("Sitting Context %s has no such attribute: %s",
                   self.sitting.__str__(), name)
         return []
예제 #12
0
 def columns(self):
     date_formatter = date.getLocaleFormatter(common.get_request(),
                                              "dateTime", "medium")
     listing_columns = [
         column.GetterColumn(
             title=_("Take start time"),
             getter=lambda i, f: date_formatter.format(i.start_date)),
         column.GetterColumn(
             title=_("Take end time"),
             getter=lambda i, f: date_formatter.format(i.end_date)),
         column.GetterColumn(title=_("Take name"),
                             getter=lambda i, f: i.debate_take_name),
         column.GetterColumn(
             title=_("Take transcriber"),
             getter=lambda i, f: IDCDescriptiveProperties(i.user).title),
     ]
     return listing_columns
예제 #13
0
 def page_title(self):
     """Formalize view.page_title as a view property to factor the logic for 
     determining the page title for a view out of the template. 
     Templates should always simply call view.page_title.
     """
     if self._page_title:
         return self._page_title
     if getattr(self.context, "title"):
         return self.context.title
     try:
         # This is the equivalent of the ZPT expression "context/dc:title"
         # i.e. to "load the value of the variable context, then find a
         # component that adapts that object to Dublin Core and read the
         # title attribute of the component."
         return IDCDescriptiveProperties(self.context).title
     except (Exception, ):
         debug.log_exc(sys.exc_info(), log_handler=log.debug)
         return "Bungeni"
예제 #14
0
 def role_listing(self, role_id, editable):
     listing = []
     users = common.get_users(role_id)
     if not users:
         return _("No users available for this role.")
     for user in users:
         data = {}
         data["title"] = IDCDescriptiveProperties(user).title
         data["name"] = self.make_id(user.login, role_id)
         data["is_assigned"] = self.user_is_assigned(user.login, role_id)
         data["editable"] = editable
         listing.append(data)
     formatter = TableFormatter(self.context,
                                self.request,
                                listing,
                                prefix="assignment",
                                columns=self.columns)
     formatter.updateBatching()
     return formatter()
예제 #15
0
def get_element_value(context, name, default=None):
    if name.startswith("dc:"):
        dc_adapter = IDCDescriptiveProperties(context, None)
        if dc_adapter is None:
            log.error("No dublin core adapter found for object %s", context)
            return default
        else:
            try:
                return getattr(dc_adapter, name[3:])
            except AttributeError:
                log.error("Dublin core adapter %s for %s has no attribute %s",
                          dc_adapter, context, name)
                return default
    try:
        return getattr(context, name)
    except AttributeError:
        log.error("Context %s has no such attribute %s. Check report template",
                  context, name)
        return default
예제 #16
0
def format_change_description(change):
    """Format/i18n a document's change object description for timeline listing
    """
    description = change.description
    if change.action == "new-version":
        version = change.origin.versions.get(
            int(change.extras.get("version_id")))
        chg_url = url.absoluteURL(version, common.get_request())
        if chg_url:
            description = "<a href='%s'>%s</a>" % (chg_url, (translate_i18n(
                change.description) or translate_i18n(u"New Version")))
    elif change.action == "workflow":
        description = translate_i18n(change.description)
    if not description:
        # use principal effecting the change as description as a fallback
        dc = IDCDescriptiveProperties(change.user, None)
        if dc:
            description = translate_i18n(dc.title_member)
    return description
예제 #17
0
 def __getattr__(self, name):
     """Attribute lookup fallback - Sitting should have access to item.
     """
     s = self.sitting
     success_message = (
         "SUCCESS LOOKUP of ATTR %r (%s) on %s / sitting=%s / grouped=%r" %
         (name, "%s", self, s, self.grouped))
     if name in self.grouped:
         log.debug(success_message, "[1] via ExpandedSitting.grouped")
         return self.grouped[name]
     if hasattr(s, name):
         log.debug(success_message, "[2] directly via sitting")
         return getattr(s, name)
     dc_adapter = IDCDescriptiveProperties(s)
     if hasattr(dc_adapter, name):
         log.debug(success_message, "[3] via sitting DCAdapter %s",
                   dc_adapter)
         return getattr(dc_adapter, name)
     log.error("FAILED LOOKUP of ATTR %r on %s / sitting=%s / grouped=%r",
               name, self, s, self.grouped)
예제 #18
0
 def getMenuItems(self, context, request):
     results = []
     unproxied = proxy.removeSecurityProxy(context.__parent__)
     items = []
     for key, info in capi.iter_type_info():
         if IScheduleContent.implementedBy(info.domain_model):
             name = naming.plural(key)
             traverser = component.getMultiAdapter((unproxied, request),
                                                   IPublishTraverse)
             try:
                 item = traverser.publishTraverse(request, name)
                 items.append((name, item))
             except NotFound:
                 continue
     for key, item in items:
         if not IAlchemistContainer.providedBy(item):
             continue
         if not IScheduleContent.implementedBy(item.domain_model):
             continue
         type_info = capi.get_type_info(item.domain_model)
         permission = "bungeni.%s.Add" % (
             type_info.workflow_key
             or naming.type_key("model_name", item.domain_model.__name__))
         if not checkPermission(permission, context):
             continue
         dc_adapter = IDCDescriptiveProperties(item, None)
         if dc_adapter:
             _title = dc_adapter.title
         else:
             _title = getattr(item, "title", "Unknown")
         results.append(
             dict(
                 title=_title,
                 description=_title,
                 action=url.absoluteURL(item, request),
                 selected=False,
                 icon=None,
                 extra={"id": "nav_calendar_content_%s" % key},
                 submenu=None,
             ))
     return results
예제 #19
0
 def listing(self):
     list_data = []
     trusted = removeSecurityProxy(self.context)
     current_attendance = list(trusted.attendance.values())
     for member in trusted.group.members:
         attd = filter(lambda i: i.member_id == member.user_id,
                       current_attendance)
         m_data = {}
         m_data["attendee"] = IDCDescriptiveProperties(member).title
         m_data["has_record"] = int(bool(attd))
         m_data["records"] = [{
             "name":
             self.makeId(member.user_id),
             "checked":
             bool(attd) and (attd[0].attendance_type == at_type.value),
             "value":
             at_type.value
         } for at_type in self.attendance_types]
         list_data.append(m_data)
     sorted_list = sorted(list_data,
                          key=itemgetter("has_record", "attendee"))
     return sorted_list
예제 #20
0
 def getMenuItems(self, context, request):
     results = []
     try:
         items = proxy.removeSecurityProxy(context.__parent__).items()
     except AttributeError:
         return results
     for key, item in items:
         if not IAlchemistContainer.providedBy(item): continue
         if not IScheduleText.implementedBy(item.domain_model): continue
         dc_adapter = IDCDescriptiveProperties(item, None)
         if dc_adapter:
             _title = dc_adapter.title
         else:
             _title = getattr(item, "title", "Unknown")
         results.append(
             dict(title=_title,
                  description=_title,
                  action=url.absoluteURL(item, request),
                  selected=False,
                  icon=None,
                  extra={},
                  submenu=None))
     return results
예제 #21
0
 def get_sitting_items(self, sitting):
     s_list = []
     if sitting.status in get_states('groupsitting',
                                     tagged=['agendaprivate']):
         return s_list
     else:
         # !+DCPROPERTIES(murithi, april-2011) Factor out properties+i18n to DC
         for schedule in sitting.item_schedule:
             descriptor = queryModelDescriptor(schedule.item.__class__)
             s_list.append({
                 'name':
                 IDCDescriptiveProperties(schedule.item).title,
                 'status':
                 str(misc.get_wf_state(schedule.item)),
                 'url':
                 url.set_url_context(
                     ('/business/' + schedule.item.type + 's/obj-' +
                      str(schedule.item.parliamentary_item_id))),
                 'item_type':
                 schedule.item.type,
                 'item_type_title': (descriptor.display_name
                                     if descriptor else schedule.item.type),
             })
         return s_list
예제 #22
0
 def channel_title(self):
     return IDCDescriptiveProperties(self.context).title
예제 #23
0
 def channel_description(self):
     return IDCDescriptiveProperties(self.context).description
예제 #24
0
 def get_title(self, item):
     return IDCDescriptiveProperties(item).title
예제 #25
0
 def get_description(self, item):
     return IDCDescriptiveProperties(item).description