def assignable_state_ids():
    _sids = set()
    for name, iface in adapters.WORKFLOW_REG:
        wf = adapters.get_workflow(name)
        _sids.update(wf.get_state_ids(
                not_tagged=["private", "fail", "terminal"], restrict=False))
    return _sids
 def values(self):
     workflow = get_workflow(self.context.domain_model.__name__.lower())
     public_wfstates = workflow.get_state_ids(tagged=["public"],
         restrict=False)
     return [ x for x in self.context.values()
         if checkPermission("zope.View", x)
              and x.status in public_wfstates ]
 def update(self):
     user_id = self.context.user_id
     parliament_id = self.context.group_id
     session = Session()
     # add cosigned items
     signed_pi_ids = [sgn.head_id for sgn in
         session.query(domain.Signatory).filter(
             sql.and_(domain.Signatory.user_id == user_id,
                 domain.Signatory.status.in_(get_workflow(
                         "signatory").get_state_ids(tagged=["public"])
                 ),
             )
         ).all()
     ]
     if len(signed_pi_ids) > 0:
         self.query = self.query.union(
             session.query(domain.Doc).filter(
                 sql.and_(
                     domain.Doc.parliament_id == parliament_id,
                     domain.Doc.status.in_(self.states),
                     domain.Doc.doc_id.in_(
                         signed_pi_ids
                     )
                 )
             )
         )
     self.query = self.query.order_by(
         domain.Doc.doc_id.desc()
     )
Exemple #4
0
class SchedulableHeadingsViewlet(SchedulableItemsViewlet):
    view_name = "heading"
    view_title = _("Headings")
    states = (get_workflow("heading").get_state("public").id, )
    model = domain.Heading

    def _item_url(self, item):
        return ""

    def _get_item_key(self, item):
        return item.heading_id

    def get_group_id(self):
        parent = self.context
        while parent is not None:
            group_id = getattr(parent, "group_id", None)
            if group_id:
                return group_id
            else:
                parent = parent.__parent__
        raise ValueError("Unable to determine group.")

    def _query_items(self):
        return tuple(Session().query(self.model).filter(
            sql.and_(self.model.status.in_(self.states),
                     self.model.group_id == self.get_group_id())))
Exemple #5
0
class SchedulableAgendaItemsViewlet(SchedulableItemsViewlet):
    view_name = "agendaitem"
    view_title = _("Agenda items")
    visible = True
    states = get_workflow("agendaitem").get_state_ids(tagged=["tobescheduled"])
    model = domain.AgendaItem

    def get_group_id(self):
        parent = self.context
        while parent is not None:
            group_id = getattr(parent, "group_id", None)
            if group_id:
                return group_id
            else:
                parent = parent.__parent__
        raise ValueError("Unable to determine group.")

    def _query_items(self):
        return tuple(Session().query(self.model).filter(
            sql.and_(self.model.status.in_(self.states),
                     self.model.group_id == self.get_group_id())))

    def _item_date(self, item):
        return item.changes[-1].date_active

    def _item_url(self, item):
        return url.set_url_context(url.absoluteURL(item, self.request))
Exemple #6
0
 def update(self):
     user_id = self.context.user_id
     parliament_id = self.context.group_id
     session = Session()
     # add cosigned items
     signed_pi_ids = [
         sgn.item_id for sgn in session.query(domain.Signatory).filter(
             sql.and_(
                 domain.Signatory.user_id == user_id,
                 domain.Signatory.status.in_(
                     get_workflow("signatory").get_state_ids(
                         tagged=["public"])),
             )).all()
     ]
     if len(signed_pi_ids) > 0:
         self.query = self.query.union(
             session.query(domain.ParliamentaryItem).filter(
                 sql.and_(
                     domain.ParliamentaryItem.parliament_id ==
                     parliament_id,
                     domain.ParliamentaryItem.status.in_(self.states),
                     domain.ParliamentaryItem.parliamentary_item_id.in_(
                         signed_pi_ids))))
     self.query = self.query.order_by(
         domain.ParliamentaryItem.parliamentary_item_id.desc())
Exemple #7
0
def main(argv):
    output_folder = ""
    if len(argv):
        output_folder = argv[0]
        if not output_folder.endswith("/"):
            output_folder = output_folder + "/"
    
    #!+bungeni_custom(mr, aug-2011) should be localized parameter, or 
    # generated dynamically e.g. listing of workflow file definitions.
    workflow_names = [
        "address",
        "agendaitem",
        "attachedfile",
        "bill",
        "committee",
        "event",
        "groupsitting",
        "group",
        "heading",
        "motion",
        "parliament", 
        "question",
        "report",
        "signatory",
        "tableddocument",
        "user",
    ]
    for name in workflow_names:
        write_file(output_folder, "%s.dot" % name, dot(get_workflow(name)))
Exemple #8
0
def main(argv):
    output_folder = ""
    if len(argv):
        output_folder = argv[0]
        if not output_folder.endswith("/"):
            output_folder = output_folder + "/"

    #!+bungeni_custom(mr, aug-2011) should be localized parameter, or
    # generated dynamically e.g. listing of workflow file definitions.
    workflow_names = [
        "address",
        "agendaitem",
        "attachedfile",
        "bill",
        "committee",
        "event",
        "groupsitting",
        "group",
        "heading",
        "motion",
        "parliament",
        "question",
        "report",
        "signatory",
        "tableddocument",
        "user",
    ]
    for name in workflow_names:
        write_file(output_folder, "%s.dot" % name, dot(get_workflow(name)))
Exemple #9
0
 def values(self):
     workflow = get_workflow(self.context.domain_model.__name__.lower())
     public_wfstates = workflow.get_state_ids(tagged=["public"],
                                              restrict=False)
     return [
         x for x in self.context.values()
         if checkPermission("zope.View", x) and x.status in public_wfstates
     ]
Exemple #10
0
def assignable_state_ids():
    _sids = set()
    for name, iface in adapters.WORKFLOW_REG:
        wf = adapters.get_workflow(name)
        _sids.update(
            wf.get_state_ids(not_tagged=["private", "fail", "terminal"],
                             restrict=False))
    return _sids
Exemple #11
0
class SchedulableHeadingsViewlet(SchedulableItemsViewlet):
    view_name = "heading"
    view_title = _("Headings")
    states = (get_workflow("heading").get_state("public").id,)
    model = domain.Heading
    
    def _item_url(self, item):
        return ""
Exemple #12
0
def get_filter_config(tag="tobescheduled"):
    return dict([(item_type, {
        "label":
        _(u"choose status"),
        "menu": [{
            "text":
            IWorkflow(
                domain.DOMAIN_CLASSES[item_type]()).get_state(status).title,
            "value":
            status
        } for status in get_workflow(item_type).get_state_ids(tagged=[tag])]
    }) for item_type in get_schedulable_types().keys()])
 def query_add_filters(self, query, *filter_strings):
     """Add filtering on public workflow states
     """
     try:
         workflow = get_workflow(self.context.domain_model.__name__.lower())
         public_wfstates = workflow.get_state_ids(tagged=["public"], 
             restrict=False)
         if public_wfstates:
             query = query.filter(
                 self.domain_model.status.in_(public_wfstates))
     except KeyError, e:
         # not workflowed...
         log.warn("PublicStatesContainerJSONListing / get_workflow "
             "for %s ERROR: %s: %s:" % (
                 self.context.domain_model, e.__class__.__name__, e))
Exemple #14
0
 def query_add_filters(self, query, *filter_strings):
     """Add filtering on public workflow states
     """
     try:
         workflow = get_workflow(self.context.domain_model.__name__.lower())
         public_wfstates = workflow.get_state_ids(tagged=["public"], 
             restrict=False)
         if public_wfstates:
             query = query.filter(
                 self.domain_model.status.in_(public_wfstates))
     except KeyError, e:
         # not workflowed...
         log.warn("PublicStatesContainerJSONListing / get_workflow "
             "for %s ERROR: %s: %s:" % (
                 self.context.domain_model, e.__class__.__name__, e))
Exemple #15
0
def get_filter_config(tag="tobescheduled"):
    return dict(
        [ (item_type, 
            { 
                "label": _(u"choose status"),
                "menu": [ 
                    { 
                        "text": IWorkflow(domain.DOMAIN_CLASSES[item_type]()).get_state(status).title, 
                        "value": status 
                    } 
                    for status in get_workflow(item_type).get_state_ids(tagged=[tag])
                ]
            }
           ) 
            for item_type in get_schedulable_types().keys()
        ]
    )
Exemple #16
0
 def __init__(self,
              context,
              item_type,
              filter_states=None,
              group_filter=False,
              item_filters={}):
     self.context = context
     self.item_type = item_type
     self.filter_states = filter_states or get_workflow(
         item_type).get_state_ids(tagged=["tobescheduled"])
     self.group_filter = group_filter
     try:
         self.domain_class = domain.DOMAIN_CLASSES[item_type]
     except AttributeError:
         raise AttributeError("Domain Class mapping has no such type %s" %
                              item_type)
     self.item_filters = item_filters
Exemple #17
0
 def __init__(self, context, item_type, filter_states=None, 
     group_filter=False, item_filters={}
 ):
     self.context = context
     self.item_type = item_type
     self.filter_states = filter_states or get_workflow(
         item_type
     ).get_state_ids(
         tagged=["tobescheduled"]
     )
     self.group_filter = group_filter
     try:
         self.domain_class = domain.DOMAIN_CLASSES[item_type]
     except AttributeError:
         raise AttributeError("Domain Class mapping has no such type %s" %
             item_type
         )
     self.item_filters = item_filters
 def _agenda_public_state_ids(self):
     return get_workflow("sitting").get_state_ids(tagged=["public"])
Exemple #19
0
class SchedulableTabledDocumentsViewlet(SchedulableItemsViewlet):
    view_name = "tableddocument"
    view_title = _("Tabled documents")
    states = get_workflow("tableddocument").get_state_ids(
        tagged=["tobescheduled"])
    model = domain.TabledDocument
Exemple #20
0
class SchedulableMotionsViewlet(SchedulableItemsViewlet):
    view_name = "motion"
    view_title = _("Motions")
    states = get_workflow("motion").get_state_ids(tagged=["tobescheduled"])
    model = domain.Motion
Exemple #21
0
class SchedulableBillsViewlet(SchedulableItemsViewlet):
    view_name = "bill"
    view_title = _("Bills")
    states = get_workflow("bill").get_state_ids(tagged=["tobescheduled"])
    model = domain.Bill
 def _agenda_private_state_ids(self):
     return get_workflow("sitting").get_state_ids(
         tagged=["agendaprivate"]
     )
# Bungeni Parliamentary Information System - http://www.bungeni.org/
# Copyright (C) 2010 - Africa i-Parliaments - http://www.parliaments.info/
# Licensed under GNU GPL v2 - http://www.gnu.org/licenses/gpl-2.0.txt
"""Workflow States tagging mechanism and processing, 
to manage logical collections of Workflow States.

$Id$
"""
log = __import__("logging").getLogger("bungeni.ui.tagged")

from bungeni.core.workflows.adapters import get_workflow
STATE_GETTERS = {
    "agendaitem": get_workflow("agendaitem").get_state,
    "bill": get_workflow("bill").get_state,
    "motion": get_workflow("motion").get_state,
    "question": get_workflow("question").get_state,
    "tableddocument": get_workflow("tableddocument").get_state,
    "groupsitting": get_workflow("groupsitting").get_state,
    "signatory": get_workflow("signatory").get_state,
}

from states import ACTIVE_TAGS, TAG_MAPPINGS


# Utilities

EMPTY_SET = set()

def get_states(pi_type, tagged=[], not_tagged=[], keys=[], conjunction="OR"):
    """Get the list of matching states.
    
Exemple #24
0
# Bungeni Parliamentary Information System - http://www.bungeni.org/
# Copyright (C) 2010 - Africa i-Parliaments - http://www.parliaments.info/
# Licensed under GNU GPL v2 - http://www.gnu.org/licenses/gpl-2.0.txt
"""Workflow States tagging mechanism and processing, 
to manage logical collections of Workflow States.

$Id$
"""
log = __import__("logging").getLogger("bungeni.ui.tagged")

from bungeni.core.workflows.adapters import get_workflow
STATE_GETTERS = {
    "agendaitem": get_workflow("agendaitem").get_state,
    "bill": get_workflow("bill").get_state,
    "motion": get_workflow("motion").get_state,
    "question": get_workflow("question").get_state,
    "tableddocument": get_workflow("tableddocument").get_state,
    "groupsitting": get_workflow("groupsitting").get_state,
    "signatory": get_workflow("signatory").get_state,
}

from states import ACTIVE_TAGS, TAG_MAPPINGS

# Utilities

EMPTY_SET = set()


def get_states(pi_type, tagged=[], not_tagged=[], keys=[], conjunction="OR"):
    """Get the list of matching states.
    
Exemple #25
0
def main(argv):
    output_folder = ""
    if (len(argv) > 0 ):
        output_folder = argv[0]
        if (output_folder.endswith("/") == False):
            output_folder = output_folder + "/"
    
    write_file(output_folder, "bill.dot", dot(get_workflow("bill")))
    write_file(output_folder, "question.dot", dot(get_workflow("question")))
    write_file(output_folder, "motion.dot", dot(get_workflow("motion")))
    write_file(output_folder, "version.dot", dot(get_workflow("version")))
    write_file(output_folder, "groupsitting.dot", 
        dot(get_workflow("groupsitting")))
    write_file(output_folder, "group.dot", dot(get_workflow("group")))
    write_file(output_folder, "question.dot", dot(get_workflow("question")))
    write_file(output_folder, "address.dot", dot(get_workflow("address")))
    write_file(output_folder, "tableddocument.dot", 
        dot(get_workflow("tableddocument")))
    write_file(output_folder, "agendaitem.dot", 
        dot(get_workflow("agendaitem")))
    write_file(output_folder, "committee.dot", 
        dot(get_workflow("committee")))
    write_file(output_folder, "parliament.dot", 
        dot(get_workflow("parliament")))
    write_file(output_folder, "signatory.dot", 
        dot(get_workflow("signatory")))
    write_file(output_folder, "event.dot", 
        dot(get_workflow("event")))
Exemple #26
0
class MemberItemsViewlet(browser.BungeniItemsViewlet):
    """A tab with bills, motions etc for an MP 
    (the "parliamentary activities" tab of of the "member" view)
    """
    # !+ un-hardwire, user defined document types
    states = \
        get_workflow("agendaitem").get_state_ids(tagged=["public"]) + \
        get_workflow("bill").get_state_ids(tagged=["public"]) + \
        get_workflow("motion").get_state_ids(tagged=["public"]) + \
        get_workflow("question").get_state_ids(tagged=["public"]) + \
        get_workflow("tableddocument").get_state_ids(tagged=["public"])

    render = ViewPageTemplateFile("templates/mp-item-viewlet.pt")

    def __init__(self, context, request, view, manager):
        super(MemberItemsViewlet, self).__init__(context, request, view,
                                                 manager)
        user_id = self.context.user_id
        parliament_id = self.context.group_id
        self.query = Session().query(domain.ParliamentaryItem).filter(
            sql.and_(
                domain.ParliamentaryItem.owner_id == user_id,
                domain.ParliamentaryItem.parliament_id == parliament_id,
                domain.ParliamentaryItem.status.in_(self.states),
            ))
        #self.for_display = (self.query.count() > 0)
        self.formatter = self.get_date_formatter("date", "medium")

    def update(self):
        user_id = self.context.user_id
        parliament_id = self.context.group_id
        session = Session()
        # add cosigned items
        signed_pi_ids = [
            sgn.item_id for sgn in session.query(domain.Signatory).filter(
                sql.and_(
                    domain.Signatory.user_id == user_id,
                    domain.Signatory.status.in_(
                        get_workflow("signatory").get_state_ids(
                            tagged=["public"])),
                )).all()
        ]
        if len(signed_pi_ids) > 0:
            self.query = self.query.union(
                session.query(domain.ParliamentaryItem).filter(
                    sql.and_(
                        domain.ParliamentaryItem.parliament_id ==
                        parliament_id,
                        domain.ParliamentaryItem.status.in_(self.states),
                        domain.ParliamentaryItem.parliamentary_item_id.in_(
                            signed_pi_ids))))
        self.query = self.query.order_by(
            domain.ParliamentaryItem.parliamentary_item_id.desc())

    @property
    def items(self):
        for item in self.query.all():
            _url = "/business/%ss/obj-%i" % (item.type,
                                             item.parliamentary_item_id)
            yield {
                "type": item.type,
                "short_name": item.short_name,
                "status": misc.get_wf_state(item),
                "submission_date": item.submission_date,
                "url": _url
            }
Exemple #27
0
 def _agenda_public_state_ids(self):
     return get_workflow("sitting").get_state_ids(tagged=["public"])
Exemple #28
0
 def _agenda_private_state_ids(self):
     return get_workflow("sitting").get_state_ids(tagged=["agendaprivate"])
for name in [
    "bill", 
    "question", 
    "motion", 
    "version", 
    "groupsitting", 
    "user", 
    "group", 
    "address", 
    "tableddocument", 
    "agendaitem", 
    "committee", 
    "parliament", 
    "attachedfile", 
    "event", 
    "report"
]:
    workflow = get_workflow(name)
    for status, state in workflow.states.items():
        f.write("""<b i18n:translate="">%s</b>""" % (state.title))
        f.write("\n")
    for transition in workflow._transitions_by_id.values():
        f.write("""<b i18n:translate="">%s</b>""" % (transition.title))
        f.write("\n")

f.write("</body></html>")
f.write("\n")
f.close()

import os
from bungeni.core.workflows.adapters import get_workflow

path = os.path.split(os.path.abspath(__file__))[0]

f = open("%s/wfi18n.pt" % path, "w")

f.write("""
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      i18n:domain="bungeni"> <body>
""")

for name in [
        "bill", "question", "motion", "groupsitting", "user", "group",
        "address", "tableddocument", "agendaitem", "committee", "parliament",
        "attachedfile", "event", "report"
]:
    workflow = get_workflow(name)
    for status, state in workflow.states.items():
        f.write("""<b i18n:translate="">%s</b>""" % (state.title))
        f.write("\n")
    for transition in workflow._transitions_by_id.values():
        f.write("""<b i18n:translate="">%s</b>""" % (transition.title))
        f.write("\n")

f.write("</body></html>")
f.write("\n")
f.close()
Exemple #31
0
def main(argv):
    output_folder = ""
    if (len(argv) > 0):
        output_folder = argv[0]
        if (output_folder.endswith("/") == False):
            output_folder = output_folder + "/"

    write_file(output_folder, "bill.dot", dot(get_workflow("bill")))
    write_file(output_folder, "question.dot", dot(get_workflow("question")))
    write_file(output_folder, "motion.dot", dot(get_workflow("motion")))
    write_file(output_folder, "version.dot", dot(get_workflow("version")))
    write_file(output_folder, "groupsitting.dot",
               dot(get_workflow("groupsitting")))
    write_file(output_folder, "group.dot", dot(get_workflow("group")))
    write_file(output_folder, "question.dot", dot(get_workflow("question")))
    write_file(output_folder, "address.dot", dot(get_workflow("address")))
    write_file(output_folder, "tableddocument.dot",
               dot(get_workflow("tableddocument")))
    write_file(output_folder, "agendaitem.dot",
               dot(get_workflow("agendaitem")))
    write_file(output_folder, "committee.dot", dot(get_workflow("committee")))
    write_file(output_folder, "parliament.dot",
               dot(get_workflow("parliament")))
    write_file(output_folder, "signatory.dot", dot(get_workflow("signatory")))
    write_file(output_folder, "event.dot", dot(get_workflow("event")))