Пример #1
0
 def _do_save(self, data):
     for key in data.keys():
         if isinstance(data[key], str):
             data[key] = unescape(data[key])
     formlib.form.applyChanges(self.context, self.form_fields, data)
     # invalidate caches for this domain object type
     invalidate_caches_for(self.context.__class__.__name__, "edit")
Пример #2
0
 def _do_save(self, data):
     formlib.form.applyChanges(self.context, self.form_fields, data)
     # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no modify event
     # invalidate caches for this domain object type
     notify(ObjectModifiedEvent(self.context))
     cascade_modifications(self.context)
     invalidate_caches_for(self.context.__class__.__name__, "edit")
Пример #3
0
 def _do_save(self, data):
     formlib.form.applyChanges(self.context, self.form_fields, data)
     # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no modify event
     # invalidate caches for this domain object type
     notify(ObjectModifiedEvent(self.context))
     #cascade_modifications(self.context)
     invalidate_caches_for(self.context.__class__.__name__, "edit")
Пример #4
0
 def _do_save(self, data):
     for key in data.keys():
         if isinstance(data[key], str):
             data[key] = unescape(data[key])
     formlib.form.applyChanges(self.context, self.form_fields, data)
     # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no modify event
     # invalidate caches for this domain object type
     invalidate_caches_for(self.context.__class__.__name__, "edit")
Пример #5
0
 def invalidate_caches(info, context):
     """GroupSitting JSON Listing caches should be invalidated for 
     any transition towards or away from a "public" state.
     """
     # we import here because module load time the setup of various
     # GroupSitting-related classes (descriptor, ...) is not yet complete
     from bungeni.ui import container
     container.invalidate_caches_for("GroupSitting", "transition")
Пример #6
0
 def _do_save(self, data):
     for key in data.keys():
         if isinstance(data[key], str):
             data[key] = unescape(data[key])
     formlib.form.applyChanges(self.context, self.form_fields, data)
     # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no modify event
     # invalidate caches for this domain object type
     invalidate_caches_for(self.context.__class__.__name__, "edit")
Пример #7
0
 def invalidate_caches(info, context):
     """GroupSitting JSON Listing caches should be invalidated for 
     any transition towards or away from a "public" state.
     """
     # we import here because module load time the setup of various
     # GroupSitting-related classes (descriptor, ...) is not yet complete
     from bungeni.ui import container
     container.invalidate_caches_for("GroupSitting", "transition")
Пример #8
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        #url = url.absoluteURL(self.context, self.request)
        #language = get_language_by_name(data["language"])["name"]
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name)

        current_translation = get_translation_for(self.context,
                                                  data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)

        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()
        # !+SESSION_CLOSE(taras.sterch, july-2011) there is no need to close the
        # session. Transaction manager will take care of this. Hope it does not
        # brake anything.
        #session.commit()
        #session.close()

        # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no translate event
        # invalidate caches for this domain object type
        invalidate_caches_for(trusted.__class__.__name__, "translate")

        #versions = IVersioned(self.context)
        #version = versions.create("'%s' translation added" % language)

        # reset workflow state
        #version.status = None
        #IWorkflowController(version).fireTransition("-draft_translation")
        # redefine form context and proceed with edit action
        #self.setUpAdapters(version)
        #handle_edit_action(self, action, data)

        # commit version such that it gets a version id
        #transaction.commit()

        #if not self._next_url:
        #    self._next_url = ( \
        #        "%s/versions/%s" % (url, stringKey(version)) + \
        #        "?portal_status_message=Translation added")

        self._finished_add = True
Пример #9
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        for key in data.keys():
            if isinstance(data[key], str):
                data[key] = unescape(data[key])
        #url = url.absoluteURL(self.context, self.request)
        #language = get_language_by_name(data["language"])["name"]
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name)

        current_translation = get_translation_for(self.context, data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)

        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()
        session.commit()
        session.close()
        
        # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no translate event
        # invalidate caches for this domain object type
        invalidate_caches_for(trusted.__class__.__name__, "translate")

        #versions = IVersioned(self.context)
        #version = versions.create("'%s' translation added" % language)

        # reset workflow state
        #version.status = None
        #IWorkflowInfo(version).fireTransition("-draft_translation")
        # redefine form context and proceed with edit action
        #self.setUpAdapters(version)
        #handle_edit_action(self, action, data)

        # commit version such that it gets a version id
        #transaction.commit()

        #if not self._next_url:
        #    self._next_url = ( \
        #        "%s/versions/%s" % (url, stringKey(version)) + \
        #        "?portal_status_message=Translation added")

        self._finished_add = True
Пример #10
0
 def createAndAdd(self, data):
     added_obj = super(AddForm, self).createAndAdd(data)
     # invalidate caches for this domain object type
     invalidate_caches_for(added_obj.__class__.__name__, "add")
     # !+ADD_invalidate_CACHE(mr, sep-2010) should not be necessary as 
     # all domain items are created into a "draft" workflow state that 
     # is NOT public, so in theory any existing cache of listings of public 
     # items are NOT affected. Plus, the required subsequent modification 
     # of the item (to transit the item into a public state) will anyway
     # invalidate the cache.
     return added_obj
Пример #11
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        for key in data.keys():
            if isinstance(data[key], str):
                data[key] = unescape(data[key])
        #url = url.absoluteURL(self.context, self.request)
        #language = get_language_by_name(data["language"])["name"]
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name)

        current_translation = get_translation_for(self.context, data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)

        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()
        session.commit()
        session.close()

        # invalidate caches for this domain object type
        invalidate_caches_for(trusted.__class__.__name__, "translate")

        #versions = IVersioned(self.context)
        #version = versions.create("'%s' translation added" % language)

        # reset workflow state
        #version.status = None
        #IWorkflowInfo(version).fireTransition("create-translation")
        # redefine form context and proceed with edit action
        #self.setUpAdapters(version)
        #handle_edit_action(self, action, data)

        # commit version such that it gets a version id
        #transaction.commit()

        #if not self._next_url:
        #    self._next_url = ( \
        #        "%s/versions/%s" % (url, stringKey(version)) + \
        #        "?portal_status_message=Translation added")

        self._finished_add = True
Пример #12
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)
Пример #13
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)
Пример #14
0
def default_reports(sitting, event):
    if sitting.status in ("published_agenda", "published_minutes"):
        sitting = removeSecurityProxy(sitting)
        sittings = []
        sittings.append(sitting)
        report = domain.Report()
        session = Session()
        #!+REPORTS(miano, dec-2010) using test request here is not quite right
        # TODO : fix this.
        from zope.publisher.browser import TestRequest
        report.start_date = sitting.start_date
        report.end_date = sitting.end_date
        # The owner ID is the ID of the user that performed the last workflow
        # change
        for change in reversed(sitting.changes):
            if change.action == "workflow":
                owner_id = change.user_id
                break
        assert owner_id is not None, _("No user is defined. Are you logged in as Admin?")
        report.owner_id = owner_id
        report.language = get_default_language()
        report.created_date = datetime.datetime.now()
        report.group_id = sitting.group_id
        if sitting.status == 'published_agenda':
            report.short_name = "Sitting Agenda"
            drc = DefaultReportContent(sittings, report.short_name, False)
            report.body_text = DefaultReportView(drc, TestRequest())()
        elif sitting.status == 'published_minutes':
            report.short_name = "Sitting Votes and Proceedings"
            drc = DefaultReportContent(sittings, report.short_name, True)
            report.body_text = DefaultReportView(drc, TestRequest())()
        session.add(report)
        notify(ObjectCreatedEvent(report))
        sr = domain.SittingReport()
        sr.report = report
        sr.sitting = sitting
        session.add(sr)
        notify(ObjectCreatedEvent(sr))
        session.commit()
        container.invalidate_caches_for("Report", "add")
        container.invalidate_caches_for("SittingReport", "add")
Пример #15
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        #url = url.absoluteURL(self.context, self.request)
        #language = get_language_by_name(data["language"])["name"]
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name)

        current_translation = get_translation_for(self.context,
                                                  data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)

        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()

        # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no translate event
        # invalidate caches for this domain object type
        invalidate_caches_for(trusted.__class__.__name__, "translate")

        #if not self._next_url:
        #    self._next_url = ( \
        #        "%s/versions/%s" % (url, stringKey(version)) + \
        #        "?portal_status_message=Translation added")

        self._finished_add = True
Пример #16
0
    def handle_add_save(self, action, data):
        """After succesful creation of translation, redirect to the
        view."""
        # url = url.absoluteURL(self.context, self.request)
        # language = get_language_by_name(data["language"])["name"]
        session = Session()
        trusted = removeSecurityProxy(self.context)
        mapper = rdb.orm.object_mapper(trusted)
        pk = getattr(trusted, mapper.primary_key[0].name)

        current_translation = get_translation_for(self.context, data["language"])
        if current_translation:
            for translation in current_translation:
                session.delete(translation)

        for form_field in data.keys():
            if form_field == "language":
                continue
            translation = domain.ObjectTranslation()
            translation.object_id = pk
            translation.object_type = trusted.__class__.__name__
            translation.field_name = form_field
            translation.lang = data["language"]
            translation.field_text = data[form_field]
            session.add(translation)
        session.flush()

        # !+EVENT_DRIVEN_CACHE_INVALIDATION(mr, mar-2011) no translate event
        # invalidate caches for this domain object type
        invalidate_caches_for(trusted.__class__.__name__, "translate")

        # if not self._next_url:
        #    self._next_url = ( \
        #        "%s/versions/%s" % (url, stringKey(version)) + \
        #        "?portal_status_message=Translation added")

        self._finished_add = True
Пример #17
0
class DeleteForm(PageForm):
    """Delete-form for Bungeni content.

    Confirmation

        The user is presented with a confirmation form which details
        the items that are going to be deleted.

    Subobjects

        Recursively, a permission check is carried out for each item
        that is going to be deleted. If a permission check fails, an
        error message is displayed to the user.

    Will redirect back to the container on success.
    """
    # evoque
    template = z3evoque.PageViewTemplateFile("delete.html")

    # zpt
    # !+form_template(mr, jul-2010) this is unused here, but needed by
    # some adapter of this "object delete" view
    #form_template = NamedTemplate("alchemist.form")
    #template = ViewPageTemplateFile("templates/delete.pt")

    _next_url = None
    form_fields = formlib.form.Fields()

    def _can_delete_item(self, action):
        return True

    def nextURL(self):
        return self._next_url

    def update(self):
        self.subobjects = self.get_subobjects()
        super(DeleteForm, self).update()

    def get_subobjects(self):
        return ()

    def delete_subobjects(self):
        return 0

    @formlib.form.action(_(u"Delete"), condition=_can_delete_item)
    def handle_delete(self, action, data):
        count = self.delete_subobjects()
        container = self.context.__parent__
        trusted = removeSecurityProxy(self.context)
        session = Session()
        session.delete(trusted)
        count += 1

        try:
            session.commit()
        except IntegrityError, e:
            # this should not happen in production; it's a critical
            # error, because the transaction might have failed in the
            # second phase of the commit
            session.rollback()
            logging.critical(e)

            self.status = _(u"Could not delete item due to "
                            "database integrity error")

            return self.render()
        session.close()
        # invalidate caches for this domain object type
        invalidate_caches_for(self.context.__class__.__name__, "delete")

        #TODO: check that it is removed from the index!
        notify(ObjectRemovedEvent(
            self.context, oldParent=container, oldName=self.context.__name__))
        # we have to switch our context here otherwise the deleted object will
        # be merged into the session again and reappear magically
        self.context = container
        next_url = self.nextURL()

        if next_url is None:
            next_url = url.absoluteURL(container, self.request) + \
                       "/?portal_status_message=%d items deleted" % count

        self.request.response.redirect(next_url)