Example #1
0
 def validate(self, action, data):
     errors = super(ReportView, self).validate(action, data)
     time_span = self.time_span(data)
     if IGroupSitting.providedBy(self.context):
         if not self.context.items:
             errors.append(interface.Invalid(
             _(u"The sitting has no scheduled items")))
     else:
         start_date = data["date"] if "date" in data else \
                                             datetime.datetime.today().date()
         end_date = self.get_end_date(start_date, time_span)
         try:
             ctx = ISchedulingContext(self.context)
         except:
             errors.append(interface.Invalid(
                     _(u"You are trying to generate a report "
                         "outside scheduling")
                 )
             )
         sittings = ctx.get_sittings(start_date, end_date).values()
         if not sittings:
             errors.append(interface.Invalid(
                     _(u"The period selected has no sittings"),
                             "date"))
         
         parliament = queries.get_parliament_by_date_range(
             start_date, end_date
         )
         if parliament is None:
             errors.append(interface.Invalid(
                 _(u"A parliament must be active in the period"),
                     "date"))
     return errors
Example #2
0
    def validate(self, action, data):
        errors = super(ReportView, self).validate(action, data)
        self.time_span = TIME_SPAN.daily
        if 'doc_type' in data:
            if data['doc_type'] == "Order of the day":
                self.time_span = TIME_SPAN.daily
            elif data['doc_type'] == "Proceedings of the day":
                self.time_span = TIME_SPAN.daily
            elif data['doc_type'] == "Weekly Business":
                self.time_span = TIME_SPAN.weekly
            elif data['doc_type'] == "Questions of the week":
                self.time_span = TIME_SPAN.weekly

        if IGroupSitting.providedBy(self.context):
            self.start_date = datetime.date(self.context.start_date.year,
                                            self.context.start_date.month,
                                            self.context.start_date.day)
        elif ISchedulingContext.providedBy(self.context):
            if 'date' in data:
                self.start_date = data['date']
        else:
            self.start_date = datetime.today().date()

        self.end_date = self.get_end_date(self.start_date, self.time_span)

        parliament = queries.get_parliament_by_date_range(
            self, self.start_date, self.end_date)
        #session = queries.get_session_by_date_range(self, start_date, end_date)

        if parliament is None:
            errors.append(
                interface.Invalid(
                    _(u"A parliament must be active in the period"), "date"))

        return errors
Example #3
0
    def validate(self, action, data):
        errors = super(ReportView, self).validate(action, data)
        time_span = self.time_span(data)
        if IGroupSitting.providedBy(self.context):
            if not self.context.items:
                errors.append(
                    interface.Invalid(
                        _(u"The sitting has no scheduled items")))
        else:
            start_date = data["date"] if "date" in data else \
                                                datetime.datetime.today().date()
            end_date = self.get_end_date(start_date, time_span)
            try:
                ctx = ISchedulingContext(self.context)
            except:
                errors.append(
                    interface.Invalid(
                        _(u"You are trying to generate a report "
                          "outside scheduling")))
            sittings = ctx.get_sittings(start_date, end_date).values()
            if not sittings:
                errors.append(
                    interface.Invalid(
                        _(u"The period selected has no sittings"), "date"))

            parliament = queries.get_parliament_by_date_range(
                start_date, end_date)
            if parliament is None:
                errors.append(
                    interface.Invalid(
                        _(u"A parliament must be active in the period"),
                        "date"))
        return errors
Example #4
0
    def validate(self, action, data):
        errors = super(ReportView, self).validate(action, data)
        self.time_span = TIME_SPAN.daily
        if 'doc_type' in data:
            if data['doc_type'] == "Order of the day":
                self.time_span = TIME_SPAN.daily
            elif data['doc_type'] == "Proceedings of the day":
                self.time_span = TIME_SPAN.daily
            elif data['doc_type'] == "Weekly Business":
                self.time_span = TIME_SPAN.weekly
            elif data['doc_type'] == "Questions of the week":
                self.time_span = TIME_SPAN.weekly

        if IGroupSitting.providedBy(self.context):
            self.start_date = datetime.date(
                self.context.start_date.year,
                self.context.start_date.month,
                self.context.start_date.day)
        elif ISchedulingContext.providedBy(self.context):
            if 'date' in data:
                self.start_date = data['date']
        else:
            self.start_date = datetime.today().date()

        self.end_date = self.get_end_date(self.start_date, self.time_span)

        parliament = queries.get_parliament_by_date_range(self, self.start_date, self.end_date)
        #session = queries.get_session_by_date_range(self, start_date, end_date)

        if parliament is None:
            errors.append(interface.Invalid(
                _(u"A parliament must be active in the period"),
                "date"))

        return errors
Example #5
0
    def __init__(self, context, request):
        super(ReportingView, self).__init__(context, request)

        if IGroupSitting.providedBy(context):
            self.date = datetime.date(context.start_date.year,
                                      context.start_date.month,
                                      context.start_date.day)
        '''
Example #6
0
 def buildSittings(self, start_date, end_date):
     if IGroupSitting.providedBy(self.context):
         trusted = removeSecurityProxy(self.context)
         order = "real_order"
         trusted.item_schedule.sort(key=operator.attrgetter(order))
         self.sittings.append(trusted)
     else:
         sittings = ISchedulingContext(self.context).get_sittings(
             start_date, end_date).values()
         self.sittings = map(removeSecurityProxy, sittings)
     self.sittings = [ExpandedSitting(sitting) for sitting in self.sittings]
Example #7
0
 def buildSittings(self, start_date, end_date):
     if IGroupSitting.providedBy(self.context):
         trusted = removeSecurityProxy(self.context)
         order="real_order"
         trusted.item_schedule.sort(key=operator.attrgetter(order))
         self.sittings.append(trusted)
     else:
         sittings = ISchedulingContext(self.context).get_sittings(
             start_date, end_date
         ).values()
         self.sittings = map(removeSecurityProxy, sittings)
     self.sittings = [ ExpandedSitting(sitting) for sitting in self.sittings ]
Example #8
0
    def handle_save(self, action, data):
        report = domain.Report()
        session = Session()
        report.body_text = data["body_text"]
        report.start_date = data["start_date"]
        report.end_date = data["end_date"]
        report.note = data["note"]
        report.report_type = data["report_type"]
        report.short_name = data["report_type"]
        owner_id = get_db_user_id()
        '''!+TODO(Miano, 18/08/2010) The admin user is currently not a db user
            thus the line above returns None when the admin publishes a report.
            to go around this if it returns None, just query the db for users
            and set the owner id to be the first result'''
        if owner_id is not None:
            report.owner_id = owner_id
        else:
            query = session.query(domain.User)
            results = query.all()
            report.owner_id = results[0].user_id
        report.language = "en"
        report.created_date = datetime.datetime.now()
        report.group_id = self.context.group_id
        session.add(report)
        notify(ObjectCreatedEvent(report))
        # !+INVALIDATE(mr, sep-2010)
        container.invalidate_caches_for("Report", "add")
        if "sittings" in data.keys():
            try:
                ids = data["sittings"].split(",")
                for id_number in ids:
                    sit_id = int(id_number)
                    sitting = session.query(domain.GroupSitting).get(sit_id)
                    sr = domain.SittingReport()
                    sr.report = report
                    sr.sitting = sitting
                    session.add(sr)
                    # !+INVALIDATE(mr, sep-2010) via an event...
                    container.invalidate_caches_for("SittingReport", "add")
            except:
                #if no sittings are present in report or some other error occurs
                pass
        session.commit()

        if IGroupSitting.providedBy(self.context):
            back_link = "./schedule"
        elif ISchedulingContext.providedBy(self.context):
            back_link = "./"
        else:
            raise NotImplementedError
        self.request.response.redirect(back_link)
Example #9
0
    def process_form(self, data):
        class optionsobj(object):
            """Object that holds all the options."""

        self.options = optionsobj()
        if not hasattr(self, "short_name"):
            if "short_name" in data:
                self.short_name = data["short_name"]
        self.sittings = []
        if IGroupSitting.providedBy(self.context):
            trusted = removeSecurityProxy(self.context)
            order = "real_order" if self.display_minutes else "planned_order"
            trusted.item_schedule.sort(key=operator.attrgetter(order))
            self.sittings.append(trusted)
            self.start_date = self.context.start_date
            self.end_date = self.get_end_date(self.start_date,
                                              self.time_span(data))
        else:
            self.start_date = data["date"] if "date" in data else \
                                                datetime.datetime.today().date()
            self.end_date = self.get_end_date(self.start_date,
                                              self.time_span(data))
            sittings = ISchedulingContext(self.context).get_sittings(
                self.start_date, self.end_date).values()
            self.sittings = map(removeSecurityProxy, sittings)
        self.ids = ""
        for sitting in self.sittings:
            self.ids += str(sitting.group_sitting_id) + ","

        def cleanup(string):
            return string.lower().replace(" ", "_")

        for item_type in data["item_types"]:
            itemtype = cleanup(item_type)
            type_key = itemtype.rstrip("s").replace("_", "")
            setattr(self.options, type_key, True)
            setattr(self.options, itemtype, True)
            for option in data[itemtype + "_options"]:
                opt_key = "".join(
                    (cleanup(itemtype.rstrip("s")).replace("_", ""), "_",
                     cleanup(option)))
                setattr(self.options, opt_key, True)
        if self.display_minutes:
            self.link = url.absoluteURL(self.context, self.request) \
                                                + "/votes-and-proceedings"
        else:
            self.link = url.absoluteURL(self.context, self.request) + "/agenda"
        try:
            self.group = self.context.group
        except:
            self.group = ISchedulingContext(self.context).get_group()
Example #10
0
 def handle_save(self, action, data):
     report = domain.Report()
     session = Session()
     report.body_text = data["body_text"]
     report.start_date = data["start_date"]
     report.end_date = data["end_date"]
     report.note = data["note"]
     report.short_name = report.short_name = data["short_name"]
     owner_id = get_db_user_id()
     '''!+TODO(Miano, 18/08/2010) The admin user is currently not a db user
         thus the line above returns None when the admin publishes a report.
         to go around this if it returns None, just query the db for users
         and set the owner id to be the first result'''
     if owner_id is not None:
         report.owner_id = owner_id
     else:
         query = session.query(domain.User)
         results = query.all()
         report.owner_id = results[0].user_id
     # TODO get language from config
     report.language = "en"
     report.created_date = datetime.datetime.now()
     report.group_id = self.context.group_id
     session.add(report)
     notify(ObjectCreatedEvent(report))
     # !+INVALIDATE(mr, sep-2010)
     container.invalidate_caches_for("Report", "add")
     if "sittings" in data.keys():
         try:
             ids = data["sittings"].split(",")
             for id_number in ids:
                 sit_id = int(id_number)
                 sitting = session.query(domain.GroupSitting).get(sit_id)
                 sr = domain.SittingReport()
                 sr.report = report
                 sr.sitting = sitting
                 session.add(sr)
                 # !+INVALIDATE(mr, sep-2010) via an event...
                 container.invalidate_caches_for("SittingReport", "add")
         except:
             #if no sittings are present in report or some other error occurs
             pass
     session.commit()
     
     if IGroupSitting.providedBy(self.context):
         back_link = "./schedule"
     elif ISchedulingContext.providedBy(self.context):
         back_link = "./"
     else:
         raise NotImplementedError
     self.request.response.redirect(back_link)
Example #11
0
    def process_form(self, data):
        class optionsobj(object):
            '''Object that holds all the options.'''
            pass

        self.options = optionsobj()
        if not hasattr(self, 'doc_type'):
            if 'doc_type' in data:
                self.doc_type = data['doc_type']
        self.sittings = []

        if IGroupSitting.providedBy(self.context):
            session = Session()
            st = self.context.sitting_id
            sitting = session.query(domain.GroupSitting).get(st)
            self.sittings.append(sitting)
            back_link = ui_url.absoluteURL(self.context,
                                           self.request) + '/schedule'
        elif ISchedulingContext.providedBy(self.context):
            self.sittings = self.get_sittings(self.start_date, self.end_date)
            back_link = ui_url.absoluteURL(self.context, self.request)
        else:
            raise NotImplementedError
        count = 0
        self.ids = ""
        for s in self.sittings:
            self.ids = self.ids + str(s.sitting_id) + ","

        def cleanup(string):
            return string.lower().replace(" ", "_")

        for item_type in data['item_types']:
            itemtype = cleanup(item_type)
            setattr(self.options, itemtype, True)
            for option in data[itemtype + "_options"]:
                setattr(self.options, cleanup(itemtype + "_" + option), True)

        if self.display_minutes:
            self.link = ui_url.absoluteURL(
                self.context, self.request) + '/votes-and-proceedings'
        else:
            self.link = ui_url.absoluteURL(self.context,
                                           self.request) + '/agenda'

        try:
            self.group = self.context.get_group()
        except:
            session = Session()
            self.group = session.query(domain.Group).get(self.context.group_id)
Example #12
0
 def process_form(self, data):
     class optionsobj(object):
         """Object that holds all the options."""
     self.options = optionsobj()
     if not hasattr(self, "short_name"):
         if "short_name" in data:
             self.short_name = data["short_name"]
     self.sittings = []
     if IGroupSitting.providedBy(self.context):
         trusted = removeSecurityProxy(self.context)
         order = "real_order" if self.display_minutes else "planned_order"
         trusted.item_schedule.sort(key=operator.attrgetter(order))
         self.sittings.append(trusted)
         self.start_date = self.context.start_date
         self.end_date = self.get_end_date(self.start_date,
                                                        self.time_span(data))
     else:
         self.start_date = data["date"] if "date" in data else \
                                             datetime.datetime.today().date()
         self.end_date = self.get_end_date(self.start_date, 
                                                        self.time_span(data))
         sittings = ISchedulingContext(self.context).get_sittings(
                                     self.start_date, self.end_date).values()
         self.sittings = map(removeSecurityProxy,sittings)
     self.ids = ""
     for sitting in self.sittings:
         self.ids += str(sitting.group_sitting_id) + ","
     def cleanup(string):
         return string.lower().replace(" ", "_")
     for item_type in data["item_types"]:
         itemtype = cleanup(item_type)
         type_key = itemtype.rstrip("s").replace("_", "")
         setattr(self.options, type_key, True)
         setattr(self.options, itemtype, True)
         for option in data[itemtype + "_options"]:
             opt_key = "".join((cleanup(itemtype.rstrip("s")).replace("_",""),
                 "_", cleanup(option)
             ))
             setattr(self.options, opt_key, True)
     if self.display_minutes:
         self.link = url.absoluteURL(self.context, self.request) \
                                             + "/votes-and-proceedings"
     else :
         self.link = url.absoluteURL(self.context, self.request) + "/agenda"
     try:
         self.group = self.context.group
     except:
         self.group = ISchedulingContext(self.context).get_group()
Example #13
0
    def process_form(self, data):
        class optionsobj(object):
            """Object that holds all the options."""
            pass

        self.options = optionsobj()
        if not hasattr(self, "short_name"):
            if "short_name" in data:
                self.short_name = data["short_name"]
        self.sittings = []

        if IGroupSitting.providedBy(self.context):
            trusted = removeSecurityProxy(self.context)
            order = "real_order" if self.display_minutes else "planned_order"
            trusted.item_schedule.sort(key=operator.attrgetter(order))
            self.sittings.append(trusted)
            back_link = url.absoluteURL(self.context,
                                        self.request) + "/schedule"
        elif ISchedulingContext.providedBy(self.context):
            self.sittings = self.get_sittings(self.start_date, self.end_date)
            back_link = url.absoluteURL(self.context, self.request)
        else:
            raise NotImplementedError
        self.ids = ""
        for s in self.sittings:
            self.ids = self.ids + str(s.group_sitting_id) + ","

        def cleanup(string):
            return string.lower().replace(" ", "_")

        for item_type in data["item_types"]:
            itemtype = cleanup(item_type)
            setattr(self.options, itemtype, True)
            for option in data[itemtype + "_options"]:
                setattr(self.options, cleanup(itemtype + "_" + option), True)

        if self.display_minutes:
            self.link = url.absoluteURL(
                self.context, self.request) + "/votes-and-proceedings"
        else:
            self.link = url.absoluteURL(self.context, self.request) + "/agenda"

        try:
            self.group = self.context.get_group()
        except:
            session = Session()
            self.group = session.query(domain.Group).get(self.context.group_id)
Example #14
0
    def handle_save(self, action, data):
        report = domain.Report()
        session = Session()
        report.body_text = data['body_text']
        report.start_date = data['start_date']
        report.end_date = data['end_date']
        report.note = data['note']
        report.report_type = data['report_type']
        report.short_name = data['report_type']
        owner_id = get_db_user_id()
        '''!+TODO(Miano, 18/08/2010) The admin user is currently not a db user
            thus the line above returns None when the admin publishes a report.
            to go around this if it returns None, just query the db for users
            and set the owner id to be the first result'''
        if owner_id is not None:
            report.owner_id = owner_id
        else:
            query = session.query(domain.User)
            results = query.all()
            report.owner_id = results[0].user_id
        report.language = "en"
        report.created_date = datetime.datetime.now()
        report.group_id = self.context.group_id
        session.add(report)
        notify(ObjectCreatedEvent(report))
        ids = data["sittings"].split(",")
        for id in ids:
            try:
                sit_id = int(id)
            except:
                continue
            sitting = session.query(domain.GroupSitting).get(sit_id)
            sr = domain.SittingReport()
            sr.report = report
            sr.sitting = sitting
            session.add(sr)
        session.commit()

        if IGroupSitting.providedBy(self.context):
            back_link = './schedule'
        elif ISchedulingContext.providedBy(self.context):
            back_link = './'
        else:
            raise NotImplementedError
        self.request.response.redirect(back_link)
Example #15
0
    def handle_save(self, action, data):
        report = domain.Report()
        session = Session()
        report.body_text = data['body_text']
        report.start_date = data['start_date']
        report.end_date = data['end_date']
        report.note = data['note']
        report.report_type = data['report_type']
        report.short_name = data['report_type']
        owner_id = get_db_user_id()
        '''!+TODO(Miano, 18/08/2010) The admin user is currently not a db user
            thus the line above returns None when the admin publishes a report.
            to go around this if it returns None, just query the db for users
            and set the owner id to be the first result'''
        if owner_id is not None:
            report.owner_id = owner_id
        else:
            query = session.query(domain.User)
            results = query.all()
            report.owner_id = results[0].user_id
        report.language = "en"
        report.created_date = datetime.datetime.now()
        report.group_id = self.context.group_id
        session.add(report)
        notify(ObjectCreatedEvent(report))
        ids = data["sittings"].split(",")
        for id in ids:
            try:
                sit_id = int(id)
            except:
                continue
            sitting = session.query(domain.GroupSitting).get(sit_id)
            sr = domain.SittingReport()
            sr.report = report
            sr.sitting = sitting
            session.add(sr)
        session.commit()

        if IGroupSitting.providedBy(self.context):
            back_link = './schedule'
        elif ISchedulingContext.providedBy(self.context):
            back_link = './'
        else:
            raise NotImplementedError
        self.request.response.redirect(back_link)
Example #16
0
    def process_form(self, data):
        class optionsobj(object):
            '''Object that holds all the options.'''
            pass
        self.options = optionsobj()
        if not hasattr(self, 'doc_type'):
            if 'doc_type' in data:
                self.doc_type = data['doc_type']
        self.sittings = []

        if IGroupSitting.providedBy(self.context):
            session = Session()
            st = self.context.sitting_id
            sitting = session.query(domain.GroupSitting).get(st)
            self.sittings.append(sitting)
            back_link = ui_url.absoluteURL(self.context, self.request) + '/schedule'
        elif ISchedulingContext.providedBy(self.context):
            self.sittings = self.get_sittings(self.start_date, self.end_date)
            back_link = ui_url.absoluteURL(self.context, self.request)
        else:
            raise NotImplementedError
        count = 0
        self.ids = ""
        for s in self.sittings:
            self.ids = self.ids + str(s.sitting_id) + ","
        def cleanup(string):
            return string.lower().replace(" ", "_")

        for item_type in data['item_types']:
            itemtype = cleanup(item_type)
            setattr(self.options, itemtype, True)
            for option in data[itemtype + "_options"]:
                setattr(self.options, cleanup(itemtype + "_" + option), True)

        if self.display_minutes:
            self.link = ui_url.absoluteURL(self.context, self.request) + '/votes-and-proceedings'
        else :
            self.link = ui_url.absoluteURL(self.context, self.request) + '/agenda'

        try:
            self.group = self.context.get_group()
        except:
            session = Session()
            self.group = session.query(domain.Group).get(self.context.group_id)
Example #17
0
    def process_form(self, data):
        class optionsobj(object):
            """Object that holds all the options."""
            pass
        self.options = optionsobj()
        if not hasattr(self, "short_name"):
            if "short_name" in data:
                self.short_name = data["short_name"]
        self.sittings = []

        if IGroupSitting.providedBy(self.context):
            trusted = removeSecurityProxy(self.context)
            order = "real_order" if self.display_minutes else "planned_order"
            trusted.item_schedule.sort(key=operator.attrgetter(order))
            self.sittings.append(trusted)
            back_link = url.absoluteURL(self.context, self.request) + "/schedule"
        elif ISchedulingContext.providedBy(self.context):
            self.sittings = self.get_sittings(self.start_date, self.end_date)
            back_link = url.absoluteURL(self.context, self.request)
        else:
            raise NotImplementedError
        self.ids = ""
        for s in self.sittings:
            self.ids = self.ids + str(s.group_sitting_id) + ","
        def cleanup(string):
            return string.lower().replace(" ", "_")

        for item_type in data["item_types"]:
            itemtype = cleanup(item_type)
            setattr(self.options, itemtype, True)
            for option in data[itemtype + "_options"]:
                setattr(self.options, cleanup(itemtype + "_" + option), True)

        if self.display_minutes:
            self.link = url.absoluteURL(self.context, self.request) + "/votes-and-proceedings"
        else :
            self.link = url.absoluteURL(self.context, self.request) + "/agenda"

        try:
            self.group = self.context.get_group()
        except:
            session = Session()
            self.group = session.query(domain.Group).get(self.context.group_id)
Example #18
0
    def setUpWidgets(self, ignore_request=False):
        if IGroupSitting.providedBy(self.context):

            class context:
                item_types = 'Bills'
                bill_options = 'Title'
                agenda_options = 'Title'
                question_options = 'Title'
                motion_options = 'Title'
                tabled_document_options = 'Title'
                note = None

            self.adapters = {self.IReportingForm2: context}
            self.widgets = form.setUpEditWidgets(self.form_fields2,
                                                 self.prefix,
                                                 self.context,
                                                 self.request,
                                                 adapters=self.adapters,
                                                 ignore_request=ignore_request)
        elif ISchedulingContext.providedBy(self.context):

            class context:
                date = self.date or datetime.date.today()
                #time_span = TIME_SPAN.daily
                doc_type = 'Order of the day'
                item_types = 'Bills'
                bill_options = 'Title'
                agenda_options = 'Title'
                question_options = 'Title'
                motion_options = 'Title'
                tabled_document_options = 'Title'
                note = None
                draft = 'No'

            self.adapters = {self.IReportingForm: context}
            self.widgets = form.setUpEditWidgets(self.form_fields,
                                                 self.prefix,
                                                 self.context,
                                                 self.request,
                                                 adapters=self.adapters,
                                                 ignore_request=ignore_request)
        else:
            raise NotImplementedError
Example #19
0
    def __call__(self):
        body_text = self.request.form['body_text']
        session = Session()
        report = domain.Report()
        start_date = self.request.form['start_date']
        end_date = self.request.form['end_date']
        report.start_date = start_date
        report.end_date = end_date
        report.created_date = datetime.datetime.now()
        report.note = self.request.form['note']
        report.report_type = self.request.form['report_type']
        report.body_text = body_text
        report.user_id = get_principal_id()
        report.group_id = self.context.group_id
        report.language = "en"
        session.add(report)

        if self.request.form['single'] == "False":
            self.sitting_items = self.get_sittings_items(start_date, end_date)
        else:
            self.sitting_items = []
            st = self.context.sitting_id
            sitting = session.query(domain.GroupSitting).get(st)
            self.sitting_items.append(sitting)

        for sitting in self.sitting_items:
            sr = domain.SittingReport()
            sr.report = report
            sr.sitting = sitting
            session.add(sr)
        session.flush()

        rpm = zope.securitypolicy.interfaces.IRolePermissionMap(report)
        rpm.grantPermissionToRole(u'zope.View', 'bungeni.Anybody')

        if IGroupSitting.providedBy(self.context):
            back_link = './schedule'
        elif ISchedulingContext.providedBy(self.context):
            back_link = './'
        else:
            raise NotImplementedError
        self.request.response.redirect(back_link)
Example #20
0
    def handle_save(self, action, data):
        report = domain.Report()
        session = Session()
        report.body_text = data["body_text"]
        report.start_date = data["start_date"]
        report.end_date = data["end_date"]
        report.note = data["note"]
        report.short_name = data["short_name"]
        report.owner_id = get_db_user_id()
        report.language = get_default_language()
        report.created_date = datetime.datetime.now()
        if not hasattr(self.context, "group_id"):
            report.group_id = ISchedulingContext(self.context).group_id
        else:
            report.group_id = self.context.group_id
        session.add(report)
        session.flush()
        notify(ObjectCreatedEvent(report))
        if "sittings" in data.keys():
            try:
                ids = data["sittings"].split(",")
                for id_number in ids:
                    sit_id = int(id_number)
                    sitting = session.query(domain.GroupSitting).get(sit_id)
                    sr = domain.SittingReport()
                    sr.report = report
                    sr.sitting = sitting
                    session.add(sr)
                    notify(ObjectCreatedEvent(report))
            except:
                #if no sittings are present in report or some other error occurs
                pass
        session.flush()

        if IGroupSitting.providedBy(self.context):
            back_link = "./schedule"
        else:
            back_link = "./"
        self.request.response.redirect(back_link)
Example #21
0
 def handle_save(self, action, data):
     report = domain.Report()
     session = Session()
     report.body_text = data["body_text"]
     report.start_date = data["start_date"]
     report.end_date = data["end_date"]
     report.note = data["note"]
     report.short_name = data["short_name"]
     report.owner_id = get_db_user_id()
     report.language = get_default_language()
     report.created_date = datetime.datetime.now()
     if not hasattr(self.context, "group_id"):
         report.group_id = ISchedulingContext(self.context).group_id
     else:
         report.group_id = self.context.group_id
     session.add(report)
     session.flush()
     notify(ObjectCreatedEvent(report))
     if "sittings" in data.keys():
         try:
             ids = data["sittings"].split(",")
             for id_number in ids:
                 sit_id = int(id_number)
                 sitting = session.query(domain.GroupSitting).get(sit_id)
                 sr = domain.SittingReport()
                 sr.report = report
                 sr.sitting = sitting
                 session.add(sr)
                 notify(ObjectCreatedEvent(report))
         except:
             #if no sittings are present in report or some other error occurs
             pass
     session.flush()
     
     if IGroupSitting.providedBy(self.context):
         back_link = "./schedule"
     else:
         back_link = "./"
     self.request.response.redirect(back_link)
Example #22
0
 def process_form(self, data):
     if 'date' in data:
         self.start_date = data['date']
     else:
         self.start_date = self.date
     time_span = TIME_SPAN.daily
     if 'doc_type' in data:
         self.doc_type = data['doc_type']
     else:
         if self.display_minutes:
             self.doc_type = "Proceedings of the day"
         else:
             self.doc_type = "Order of the day"
     if self.doc_type == "Order of the day":
         time_span = TIME_SPAN.daily
     elif self.doc_type == "Weekly Business":
         time_span = TIME_SPAN.weekly
     elif self.doc_type == "Questions of the week":
         time_span = TIME_SPAN.weekly
     elif self.doc_type == "Proceedings of the day":
         time_span = TIME_SPAN.daily
     self.end_date = self.get_end_date(self.start_date, time_span)
     #Hack:Check if called on scheduling page or sitting page. todo : fix this
     if 'date' in data:
         self.sitting_items = self.get_sittings_items(
             self.start_date, self.end_date)
         self.single = "False"
     else:
         session = Session()
         self.sitting_items = []
         st = self.context.sitting_id
         sitting = session.query(domain.GroupSitting).get(st)
         self.sitting_items.append(sitting)
         self.single = "True"
     self.item_types = data['item_types']
     self.bill = False
     self.motion = False
     self.agenda = False
     self.question = False
     self.tabled_document = False
     self.bill_options = data['bill_options']
     self.agenda_options = data['agenda_options']
     self.motion_options = data['motion_options']
     self.question_options = data['question_options']
     self.note = data['note']
     self.tabled_document_options = data['tabled_document_options']
     for type in self.item_types:
         if type == 'Bills':
             self.bill_title = False
             self.bill_summary = False
             self.bill_text = False
             self.bill_owner = False
             self.bill_cosignatories = False
             for option in self.bill_options:
                 if option == 'Title':
                     self.bill_title = True
                 elif option == 'Summary':
                     self.bill_summary = True
                 elif option == 'Text':
                     self.bill_text = True
                 elif option == 'Owner':
                     self.bill_owner = True
                 elif option == 'Cosignatories':
                     self.bill_cosignatories = True
             self.bill = True
         elif type == 'Motions':
             self.motion_title = False
             self.motion_number = False
             self.motion_text = False
             self.motion_owner = False
             for option in self.motion_options:
                 if option == 'Title':
                     self.motion_title = True
                 elif option == 'Number':
                     self.motion_number = True
                 elif option == 'Text':
                     self.motion_text = True
                 elif option == 'Owner':
                     self.motion_owner = True
             self.motion = True
         elif type == 'Agenda Items':
             self.agenda_title = False
             self.agenda_text = False
             self.agenda_owner = False
             for option in self.agenda_options:
                 if option == 'Title':
                     self.agenda_title = True
                 elif option == 'Text':
                     self.agenda_text = True
                 elif option == 'Owner':
                     self.agenda_owner = True
             self.agenda = True
         elif type == 'Tabled Documents':
             self.tabled_document_title = False
             self.tabled_document_text = False
             self.tabled_document_owner = False
             self.tabled_document_number = False
             for option in self.tabled_document_options:
                 if option == 'Title':
                     self.tabled_document_title = True
                 elif option == 'Text':
                     self.tabled_document_text = True
                 elif option == 'Owner':
                     self.tabled_document_owner = True
                 elif option == 'Number':
                     self.tabled_document_number = True
             self.tabled_document = True
         elif type == 'Questions':
             self.question_title = False
             self.question_number = False
             self.question_text = False
             self.question_owner = False
             #self.question_response = False
             self.question_type = False
             for option in self.question_options:
                 if option == 'Title':
                     self.question_title = True
                 elif option == 'Number':
                     self.question_number = True
                 elif option == 'Text':
                     self.question_text = True
                 elif option == 'Owner':
                     self.question_owner = True
                 #elif option == 'Response':
                 #    self.question_response = True
                 elif option == 'Type':
                     self.question_type = True
             self.question = True
     #import pdb; pdb.set_trace()
     '''for item in self.sitting_items:
         if item.item_schedule.item.type in item_types:
             opt = item.type + '_option'
             for option in data[opt]:
                 item.options[option] = True
         else:
             self.sitting_items.remove(item) '''
     '''if self.display_minutes:
         if data['draft'] == 'No':
             for sitting in self.sitting_items:
                 items = []
                 for item in sitting.item_schedule:
                     if item.item_status not in ["draft"]:
                         items.append(item)
                 sitting.item_schedule = items'''
     if 'draft' in data:
         sitting_items = []
         for sitting in self.sitting_items:
             if data["draft"] == 'No':
                 if sitting.status in [
                         "published-agenda", "published-minutes"
                 ]:
                     sitting_items.append(sitting)
             elif data["draft"] == 'Yes':
                 if sitting.status in [
                         "published-agenda", "draft-minutes",
                         "published-minutes", "draft-agenda"
                 ]:
                     sitting_items.append(sitting)
         self.sitting_items = sitting_items
     if self.display_minutes:
         self.link = ui_url.absoluteURL(
             self.context, self.request) + '/votes-and-proceedings'
     else:
         self.link = ui_url.absoluteURL(self.context,
                                        self.request) + '/agenda'
     try:
         self.group = self.context.get_group()
     except:
         session = Session()
         self.group = session.query(domain.Group).get(self.context.group_id)
     if IGroupSitting.providedBy(self.context):
         self.back_link = ui_url.absoluteURL(self.context,
                                             self.request) + '/schedule'
     elif ISchedulingContext.providedBy(self.context):
         self.back_link = ui_url.absoluteURL(self.context, self.request)
Example #23
0
    def __call__(self):
        date = datetime.datetime.strptime(self.request.form['date'],
                                          '%Y-%m-%d').date()
        self.display_minutes = (self.request.form['display_minutes'] == "True")
        time_span = self.request.form['time_span']
        if time_span == TIME_SPAN.daily:
            time_span = TIME_SPAN.daily
        elif time_span == TIME_SPAN.weekly:
            time_span = TIME_SPAN.weekly
        end = self.get_end_date(date, time_span)
        body_text = super(StoreReportView, self).__call__()
        sitting_items = []
        for sitting in self.sitting_items:
            if self.display_minutes:
                if sitting.status in ["published-minutes"]:
                    sitting_items.append(sitting)
            else:
                if sitting.status in [
                        "published-agenda", "draft-minutes",
                        "published-minutes"
                ]:
                    sitting_items.append(sitting)
        if len(sitting_items) == 0:
            referer = self.request.getHeader('HTTP_REFERER')
            if referer:
                referer = referer.split('?')[0]
            else:
                referer = ""
            self.request.response.redirect(
                referer + "?portal_status_message=No data found")
            return
        self.sitting_items = sitting_items
        session = Session()
        report = domain.Report()
        report.start_date = date
        report.end_date = end
        report.created_date = datetime.datetime.now()
        if self.display_minutes:
            report.report_type = 'minutes'
        else:
            report.report_type = 'agenda'
        report.body_text = body_text
        report.user_id = get_principal_id()
        report.group_id = self.group.group_id
        session.add(report)
        for sitting in self.sitting_items:
            sr = domain.SittingReport()
            sr.report = report
            sr.sitting = sitting
            session.add(sr)
        session.flush()

        rpm = zope.securitypolicy.interfaces.IRolePermissionMap(report)
        rpm.grantPermissionToRole(u'zope.View', 'bungeni.Anybody')

        if IGroupSitting.providedBy(self.context):
            back_link = ui_url.absoluteURL(self.context,
                                           self.request) + '/schedule'
        elif ISchedulingContext.providedBy(self.context):
            back_link = ui_url.absoluteURL(self.context, self.request)
        else:
            raise NotImplementedError
        self.request.response.redirect(back_link)
        session.close()