예제 #1
0
 def errors(self):
     """The `list of validation errors<cocktail.schema.errorlist.ErrorList>`
     for the current form state.
     """
     return schema.ErrorList(
         self.schema.get_errors(self.data, **self.validation_parameters
                                ) if self.submitted else ())
예제 #2
0
    def errors(self):
        errors = schema.ErrorList()

        for form in self.submitted_forms:
            for error in form.errors:
                errors.add(error)

        return errors
예제 #3
0
    def __call__(self, *args, **kwargs):

        node = self.stack_node
        previewed_item = self.previewed_item
        publishable = self.preview_publishable
        preview_language = self.preview_language
        user = get_current_user()

        # Set the language for the preview
        if preview_language:
            set_language(preview_language)

        # Enforce permissions
        user.require_permission(ReadPermission, target=previewed_item)

        if publishable is not previewed_item:
            user.require_permission(ReadPermission, target=publishable)

        # Disable the preview if the item's unsaved state produces validation
        # errors; these would usually lead to unhandled server errors during
        # rendering.
        errors = schema.ErrorList(node.iter_errors())

        if errors:
            error_box = templates.new("cocktail.html.ErrorBox")
            error_box.errors = errors
            message = Element("div",
                              class_name="preview-error-box",
                              children=[
                                  translations(
                                      "woost.backoffice invalid item preview",
                                      preview_language), error_box
                              ])
            message.add_resource("/resources/styles/backoffice.css")
            return message.render_page()

        # Update the edited item with the data to preview
        node.import_form_data(node.form_data, previewed_item)

        self.context.update(original_publishable=self.context["publishable"],
                            publishable=publishable)

        controller = publishable.resolve_controller()

        if controller is None:
            raise cherrypy.NotFound()

        if isinstance(controller, type):
            controller = controller()

        return controller()
예제 #4
0
 def form_errors(self):
     return schema.ErrorList(
         self.form_schema.get_errors(self.form_data) if self.
         submitted else [])
예제 #5
0
        def _process_comments(event):

            # Comments variables initialization
            comments_user_collection = None
            comments_schema = None
            comment_errors = None
            comment_data = {}

            controller = event.source
            comment_model = \
                resolve(getattr(controller, "comment_model", Comment))
            publishable = controller.context["publishable"]
            user = get_current_user()

            if publishable is not None and publishable.allow_comments:

                # Comments collection
                comments_user_collection = UserCollection(comment_model)
                comments_user_collection.allow_type_selection = False
                comments_user_collection.allow_filters = False
                comments_user_collection.allow_language_selection = False
                comments_user_collection.allow_member_selection = False
                comments_user_collection.params.prefix = "comments_"
                comments_user_collection.base_collection = publishable.comments

                # Show the last comments page if not specified
                if "comments_page" not in cherrypy.request.params:
                    div, mod = divmod(len(comments_user_collection.subset),
                                      comments_user_collection.page_size)
                    comments_page = div - 1 if not mod and div != 0 else div
                    cherrypy.request.params.update(
                        comments_page=str(comments_page))

                # Adapting the comments model
                comments_schema = CommentsExtension.instance._adapt_comments_schema(
                    comment_model)

                if user.anonymous \
                and getattr(CommentsExtension.instance, "captcha_enabled", False):
                    comments_schema.add_member(ReCaptcha("captcha"))

                # Insert a new comment
                if cherrypy.request.method == "POST" \
                and "post_comment" in cherrypy.request.params:

                    with changeset_context(user):
                        get_parameter(comments_schema,
                                      target=comment_data,
                                      errors="ignore")

                        comment_errors = schema.ErrorList(
                            comments_schema.get_errors(comment_data))

                        if not comment_errors:
                            comment = comment_model()

                            adapter = CommentsExtension.instance._create_comments_adapter(
                                comment_model)
                            adapter.import_object(
                                comment_data,
                                comment,
                                source_schema=comments_schema,
                                target_schema=comment_model)

                            comment.publishable = publishable
                            user.require_permission(CreatePermission,
                                                    target=comment)

                            comment.insert()
                            datastore.commit()
                            CommentsExtension.instance._after_process_comments(
                                comment)
                else:
                    comment_errors = schema.ErrorList([])

            # Update the output
            controller.output.update(
                comments_user_collection=comments_user_collection,
                comments_schema=comments_schema,
                comment_errors=comment_errors,
                comment_data=comment_data)
 def form_errors(self):
     return schema.ErrorList([] if not self.submitted else self.form_schema.
                             get_errors(self.form_data))