示例#1
0
文件: blog.py 项目: disko/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if 'security_state' in converted:
            if workflow is not None:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Tags and attachments
        set_tags(context, request, converted['tags'])
        creator = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(
            filter(lambda x: x is not None, converted['attachments']),
            attachments_folder,
            creator, request)

        # modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#2
0
文件: mailin.py 项目: iotest3/new
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        target = self.context['comments']
        reply = create_content(
            IComment,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
        )

        reply.title = info['subject']
        reply.creator = info['author']
        reply.created = info['date']
        reply.text = text

        target[target.next_id] = reply

        workflow = get_workflow(IComment, 'security', target)
        if workflow is not None:
            workflow.initialize(reply)

        if attachments:
            _addAttachments(reply, info, attachments)

        # Mailin always sends alerts
        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(reply, offline_request)
示例#3
0
文件: wiki.py 项目: reebalazs/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.text = converted['text']
        context.description = extract_description(converted['text'])
        newtitle = converted['title']
        if newtitle != context.title:
            context.change_title(newtitle)

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = model_url(context, request)
        msg = "?status_message=Wiki%20Page%20edited"
        return HTTPFound(location=location+msg)
示例#4
0
文件: forum.py 项目: boothead/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Save new attachments
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context['attachments'],
                               creator, request)

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = model_url(context, request,
                             query={'status_message':'Forum Topic Edited'})
        return HTTPFound(location=location)
示例#5
0
文件: page.py 项目: araymund/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        # create the page and store it
        creator = authenticated_userid(request)
        page = create_content(IPage,
                              converted['title'],
                              converted['text'],
                              extract_description(converted['text']),
                              creator,
                              )
        name = make_unique_name(context, converted['title'])
        context[name] = page

        # tags and attachments
        set_tags(page, request, converted['tags'])
        attachments_folder = page['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)
        relocate_temp_images(page, request)

        # update ordering if in ordered container
        if hasattr(context, 'ordering'):
            context.ordering.add(name)

        location = resource_url(page, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#6
0
文件: page.py 项目: araymund/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = authenticated_userid(request)
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # tags and attachments
        set_tags(context, request, converted['tags'])
        creator = userid
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)

        # modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        self.filestore.clear()
        location = resource_url(context, request)
        msg = "?status_message=Page%20edited"
        return HTTPFound(location=location+msg)
示例#7
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        name = make_unique_name(context, converted['title'])
        creator = authenticated_userid(request)

        topic = create_content(IForumTopic,
            converted['title'],
            converted['text'],
            creator,
            )

        topic.description = extract_description(converted['text'])
        context[name] = topic

        # Set up workflow
        if workflow is not None:
            workflow.initialize(topic)
            if 'security_state' in converted:
                workflow.transition_to_state(topic, request,
                                             converted['security_state'])

        # send the temp images to their final place
        relocate_temp_images(topic, request)

        # Tags and attachments
        set_tags(topic, request, converted['tags'])
        if support_attachments(topic):
            upload_attachments(converted['attachments'], topic['attachments'],
                               creator, request)

        location = resource_url(topic, request)
        return HTTPFound(location=location)
示例#8
0
文件: mailin.py 项目: iotest3/new
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        entry = create_content(
            IBlogEntry,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
        )
        entry.created = info['date']

        if attachments:
            if 'attachments' not in entry:
                # XXX Not a likely code path, left here for safety
                entry['attachments'] = att_folder = AttachmentsFolder()
                att_folder.title = 'Attachments'
                att_folder.creator = info['author']
            else:
                att_folder = entry['attachments']
            _addAttachments(att_folder, info, attachments)

        entry_id = make_unique_name(self.context, entry.title)
        self.context[entry_id] = entry

        workflow = get_workflow(IBlogEntry, 'security', self.context)
        if workflow is not None:
            workflow.initialize(entry)

        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(entry, offline_request)
示例#9
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        workflow = self.workflow
        wikipage = create_content(
            IWikiPage,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            authenticated_userid(request),
        )

        name = make_name(context, converted['title'])
        context[name] = wikipage

        if workflow is not None:
            workflow.initialize(wikipage)
            if 'security_state' in converted:
                workflow.transition_to_state(wikipage, request,
                                             converted['security_state'])

        # Save the tags on it.
        set_tags(wikipage, request, converted['tags'])

        relocate_temp_images(wikipage, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(wikipage, request)

        msg = '?status_message=Wiki%20Page%20created'
        location = resource_url(wikipage, request) + msg
        return HTTPFound(location=location)
示例#10
0
文件: mailin.py 项目: Falmarri/karl
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        target = self.context['comments']
        reply = create_content(
            IComment,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
        )

        reply.title = info['subject']
        reply.creator = info['author']
        reply.created = info['date']
        reply.text = text

        target[target.next_id] = reply

        workflow = get_workflow(IComment, 'security', target)
        if workflow is not None:
            workflow.initialize(reply)

        if attachments:
            _addAttachments(reply, info, attachments)

        # Mailin always sends alerts
        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(reply, offline_request)
示例#11
0
    def handle_submit(self, converted):
        if lock.owns_lock(self.context, self.userid):
            lock.clear(self.context)

        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.text = converted['text']
        context.description = extract_description(converted['text'])
        newtitle = converted['title']
        if newtitle != context.title:
            context.change_title(newtitle)

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        msg = "?status_message=Wiki%20Page%20edited"
        return HTTPFound(location=location + msg)
示例#12
0
文件: commenting.py 项目: lslaz1/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        parent = context.__parent__
        creator = authenticated_userid(request)
        comment = create_content(
            IComment,
            'Re: %s' % parent.title,
            converted['add_comment'],
            extract_description(converted['add_comment']),
            creator,
            )
        next_id = parent['comments'].next_id
        parent['comments'][next_id] = comment
        workflow = get_workflow(IComment, 'security', context)
        if workflow is not None:
            workflow.initialize(comment)
            if 'security_state' in converted:
                workflow.transition_to_state(comment, request,
                                             converted['security_state'])

        if support_attachments(comment):
            upload_attachments(converted['attachments'], comment,
                               creator, request)
        relocate_temp_images(comment, request)

        if converted.get('sendalert'):
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(comment, request)

        location = resource_url(parent, request)
        msg = 'Comment added'
        location = '%s?status_message=%s' % (location, urllib.quote(msg))
        self.filestore.clear()
        return HTTPFound(location=location)
示例#13
0
文件: blog.py 项目: araymund/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if 'security_state' in converted:
            if workflow is not None:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Tags and attachments
        set_tags(context, request, converted['tags'])
        creator = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(
            filter(lambda x: x is not None, converted['attachments']),
            attachments_folder, creator, request)

        # modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#14
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        # create the page and store it
        creator = authenticated_userid(request)
        page = create_content(
            IPage,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            creator,
        )
        name = make_unique_name(context, converted['title'])
        context[name] = page

        # tags and attachments
        set_tags(page, request, converted['tags'])
        attachments_folder = page['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)
        relocate_temp_images(page, request)

        # update ordering if in ordered container
        if hasattr(context, 'ordering'):
            context.ordering.add(name)

        location = resource_url(page, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#15
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = authenticated_userid(request)
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # tags and attachments
        set_tags(context, request, converted['tags'])
        creator = userid
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)

        # modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        self.filestore.clear()
        location = resource_url(context, request)
        msg = "?status_message=Page%20edited"
        return HTTPFound(location=location + msg)
示例#16
0
文件: forum.py 项目: boothead/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        name = make_unique_name(context, converted['title'])
        creator = authenticated_userid(request)

        topic = create_content(IForumTopic,
            converted['title'],
            converted['text'],
            creator,
            )

        topic.description = extract_description(converted['text'])
        context[name] = topic

        # Set up workflow
        if workflow is not None:
            workflow.initialize(topic)
            if 'security_state' in converted:
                workflow.transition_to_state(topic, request,
                                             converted['security_state'])

        # Tags and attachments
        set_tags(context, request, converted['tags'])
        if support_attachments(topic):
            upload_attachments(converted['attachments'], topic['attachments'],
                               creator, request)

        location = model_url(topic, request)
        return HTTPFound(location=location)
示例#17
0
文件: wiki.py 项目: reebalazs/karl
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        workflow = self.workflow
        wikipage = create_content(
            IWikiPage,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            authenticated_userid(request),
            )

        name = make_name(context, converted['title'])
        context[name] = wikipage

        if workflow is not None:
            workflow.initialize(wikipage)
            if 'security_state' in converted:
                workflow.transition_to_state(wikipage,
                                             request,
                                             converted['security_state'])

        # Save the tags on it.
        set_tags(wikipage, request, converted['tags'])

        relocate_temp_images(wikipage, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(wikipage, request)

        msg = '?status_message=Wiki%20Page%20created'
        location = model_url(wikipage, request) + msg
        return HTTPFound(location=location)
示例#18
0
文件: mailin.py 项目: Falmarri/karl
    def handle(self, message, info, text, attachments):
        """ See IMailinHandler.
        """
        entry = create_content(
            IBlogEntry,
            title=info['subject'],
            creator=info['author'],
            text=text,
            description=extract_description(text),
            )
        entry.created = info['date']

        if attachments:
            if 'attachments' not in entry:
                # XXX Not a likely code path, left here for safety
                entry['attachments'] = att_folder = AttachmentsFolder()
                att_folder.title = 'Attachments'
                att_folder.creator = info['author']
            else:
                att_folder = entry['attachments']
            _addAttachments(att_folder, info, attachments)

        entry_id = make_unique_name(self.context, entry.title)
        self.context[entry_id] = entry

        workflow = get_workflow(IBlogEntry, 'security', self.context)
        if workflow is not None:
            workflow.initialize(entry)

        alerts = queryUtility(IAlerts, default=Alerts())
        alerts.emit(entry, offline_request)
示例#19
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Save new attachments
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context['attachments'],
                               creator, request)

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request,
                             query={'status_message':'Forum Topic Edited'})
        return HTTPFound(location=location)
示例#20
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        parent = context.__parent__
        creator = authenticated_userid(request)
        comment = create_content(
            IComment,
            'Re: %s' % parent.title,
            converted['add_comment'],
            extract_description(converted['add_comment']),
            creator,
        )
        next_id = parent['comments'].next_id
        parent['comments'][next_id] = comment
        workflow = get_workflow(IComment, 'security', context)
        if workflow is not None:
            workflow.initialize(comment)
            if 'security_state' in converted:
                workflow.transition_to_state(comment, request,
                                             converted['security_state'])

        if support_attachments(comment):
            upload_attachments(converted['attachments'], comment, creator,
                               request)
        relocate_temp_images(comment, request)

        if converted.get('sendalert'):
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(comment, request)

        location = resource_url(parent, request)
        msg = 'Comment added'
        location = '%s?status_message=%s' % (location, urllib.quote(msg))
        self.filestore.clear()
        return HTTPFound(location=location)
示例#21
0
    def handle_submit(self, converted):
        # base class does some validation and simple massaging
        super(AddCalendarEventFormController, self).handle_submit(converted)

        # we create the event and handle other details
        context = self.context
        request = self.request
        creator = authenticated_userid(request)
        attendees = converted.get('attendees') or []
        calendar_event = create_content(ICalendarEvent,
                                        converted['title'],
                                        converted['start_date'],
                                        converted['end_date'],
                                        creator,
                                        converted['text'],
                                        converted['location'],
                                        attendees,
                                        converted['contact_name'],
                                        converted['contact_email'],
                                        calendar_category=converted['category'],
                                        )
        calendar_event.description = extract_description(converted['text'])
        calname = make_unique_name(context, calendar_event.title)
        context[calname] = calendar_event

        # set up workflow
        workflow = get_workflow(ICalendarEvent, 'security', context)
        if workflow is not None:
            workflow.initialize(calendar_event)
            if 'security_state' in converted:
                workflow.transition_to_state(calendar_event, request,
                                             converted['security_state'])

        # save tags and attachments
        set_tags(calendar_event, request, converted['tags'])
        upload_attachments(converted['attachments'],
                           calendar_event['attachments'],
                           creator, request)

        # send alert
        if converted.get('sendalert', False):
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(calendar_event, request)

        self.filestore.clear()
        return HTTPFound(location=model_url(calendar_event, request))
示例#22
0
def edit_comment_view(context, request):

    form = EditCommentForm()
    workflow = get_workflow(IComment, 'security', context)

    if workflow is None:
        security_states = []
    else:
        security_states = get_security_states(workflow, context, request)

    if security_states:
        form.add_field('security_state', security_state_field)

    if 'form.cancel' in request.POST:
        return HTTPFound(location=model_url(context.__parent__, request))

    if 'form.submitted' in request.POST:
        try:
            converted = form.validate(request.POST)
            form.is_valid = True

            # *will be* modified event
            objectEventNotify(ObjectWillBeModifiedEvent(context))
            if workflow is not None:
                if 'security_state' in converted:
                    workflow.transition_to_state(context, request,
                                                 converted['security_state'])

            context.text  = converted['add_comment']
            context.description = extract_description(context.text)

            creator = authenticated_userid(request)
            if support_attachments(context):
                store_attachments(context, request.params, creator)

            context.modified_by = authenticated_userid(request)
            objectEventNotify(ObjectModifiedEvent(context))

            location = model_url(context, request)
            return HTTPFound(location=location)

        except Invalid, e:
            fielderrors = e.error_dict
            fill_values = form.convert(request.POST)
示例#23
0
文件: blog.py 项目: lslaz1/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        name = make_unique_name(context, converted['title'])

        creator = authenticated_userid(request)

        blogentry = create_content(
            IBlogEntry,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            creator,
            )

        context[name] = blogentry

        # Set up workflow
        if workflow is not None:
            workflow.initialize(blogentry)
            if 'security_state' in converted:
                workflow.transition_to_state(blogentry, request,
                                             converted['security_state'])

        # Tags, attachments, alerts, images
        set_tags(blogentry, request, converted['tags'])
        attachments_folder = blogentry['attachments']
        upload_attachments(filter(lambda x: x is not None,
                                  converted['attachments']),
                           attachments_folder,
                           creator, request)
        relocate_temp_images(blogentry, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(blogentry, request)

        location = resource_url(blogentry, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#24
0
    def handle_submit(self, converted):
        # base class does some validation and simple massaging
        super(EditCalendarEventFormController, self).handle_submit(converted)

        context = self.context
        request = self.request
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if self.workflow is not None:
            if 'security_state' in converted:
                self.workflow.transition_to_state(context, request,
                                                  converted['security_state'])

        context.title = converted['title']
        context.startDate = converted['start_date']
        context.endDate = converted['end_date']
        context.text = converted['text']
        context.location = converted['location']
        context.attendees = converted.get('attendees') or []
        context.contact_name = converted['contact_name']
        context.contact_email = converted['contact_email']
        context.calendar_category = converted['category']
        context.description = extract_description(converted['text'])

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Save new attachments
        userid = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           userid, request)

        # Modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        self.filestore.clear()
        location = model_url(context, request)
        msg = "?status_message=Calendar%20Event%20edited"
        return HTTPFound(location='%s%s' % (location, msg))
示例#25
0
文件: commenting.py 项目: lslaz1/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = get_workflow(IComment, 'security', context)

        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])
        context.text = converted['add_comment']
        context.description = extract_description(context.text)
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context, creator,
                               request)
        context.modified_by = creator
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#26
0
文件: commenting.py 项目: zagy/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow =  get_workflow(IComment, 'security', context)

        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])
        context.text = converted['add_comment']
        context.description = extract_description(context.text)
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context, creator,
                               request)
        context.modified_by = creator
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#27
0
文件: blog.py 项目: araymund/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        name = make_unique_name(context, converted['title'])

        creator = authenticated_userid(request)

        blogentry = create_content(
            IBlogEntry,
            converted['title'],
            converted['text'],
            extract_description(converted['text']),
            creator,
        )

        context[name] = blogentry

        # Set up workflow
        if workflow is not None:
            workflow.initialize(blogentry)
            if 'security_state' in converted:
                workflow.transition_to_state(blogentry, request,
                                             converted['security_state'])

        # Tags, attachments, alerts, images
        set_tags(blogentry, request, converted['tags'])
        attachments_folder = blogentry['attachments']
        upload_attachments(
            filter(lambda x: x is not None, converted['attachments']),
            attachments_folder, creator, request)
        relocate_temp_images(blogentry, request)

        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(blogentry, request)

        location = resource_url(blogentry, request)
        self.filestore.clear()
        return HTTPFound(location=location)
示例#28
0
文件: forum.py 项目: lslaz1/karl
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        name = make_unique_name(context, converted['title'])
        creator = authenticated_userid(request)

        topic = create_content(
            IForumTopic,
            converted['title'],
            converted['text'],
            creator,
            )

        topic.description = extract_description(converted['text'])
        context[name] = topic

        # Set up workflow
        if workflow is not None:
            workflow.initialize(topic)
            if 'security_state' in converted:
                workflow.transition_to_state(topic, request,
                                             converted['security_state'])

        # send the temp images to their final place
        relocate_temp_images(topic, request)

        # Tags and attachments
        set_tags(topic, request, converted['tags'])
        if support_attachments(topic):
            upload_attachments(converted['attachments'], topic['attachments'],
                               creator, request)

        if 'sendalert' in converted and converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(topic, request)
        location = resource_url(topic, request)
        return HTTPFound(location=location)
示例#29
0
def edit_calendarevent_view(context, request):

    tags_list = request.POST.getall('tags')
    form = EditCalendarEventForm(tags_list=tags_list)
    workflow = get_workflow(ICalendarEvent, 'security', context)

    if workflow is None:
        security_states = []
    else:
        security_states = get_security_states(workflow, context, request)

    if security_states:
        form.add_field('security_state', security_state_field)

    if 'form.cancel' in request.POST:
        return HTTPFound(location=model_url(context, request))

    if 'form.submitted' in request.POST:
        try:
            if 'calendar_category' not in request.POST:
                # FormEncode doesn't let us mark certain keys as being missable
                # Either any key can be missing from form or none, so we just
                # manually massage calendar_category, which may be missing,
                # before performing validation.
                request.POST['calendar_category'] = None

            converted = form.validate(request.POST)

            # *will be* modified event
            objectEventNotify(ObjectWillBeModifiedEvent(context))
            if workflow is not None:
                if 'security_state' in converted:
                    workflow.transition_to_state(context, request,
                                                 converted['security_state'])

            context.title = converted['title']
            context.startDate = converted['startDate']
            context.endDate = converted['endDate']
            context.text = converted['text']
            context.location = converted['location']
            context.attendees = converted['attendees']
            context.contact_name = converted['contact_name']
            context.contact_email = converted['contact_email']
            context.calendar_category = converted['calendar_category']
            context.description = extract_description(converted['text'])

            # Save the tags on it
            set_tags(context, request, converted['tags'])

            # Save new attachments
            creator = authenticated_userid(request)
            store_attachments(context['attachments'], request.params, creator)

            # Modified
            context.modified_by = authenticated_userid(request)
            objectEventNotify(ObjectModifiedEvent(context))

            location = model_url(context, request)
            msg = "?status_message=Calendar%20Event%20edited"
            return HTTPFound(location=location+msg)

        except Invalid, e:
            fielderrors = e.error_dict
            fill_values = form.convert(request.POST)
示例#30
0
def add_comment_view(context, request):
    # This is NOT a self-posting form.  The BlogEntry has the form
    # that submits to this view.  Thus, we only need to handle
    # submission requests, then redirect back to the parent (the blog
    # entry).

    # Handle the Add Comment form
    #post_url = model_url(context, request, "comments/add_comment.html")
    form = AddCommentForm()
    # add the security state field if appropriate for the context
    workflow = get_workflow(IComment, 'security', context)

    if workflow is None:
        security_states = []
    else:
        security_states = get_security_states(workflow, None, request)

    if security_states:
        form.add_field('security_state', security_state_field)

    if 'form.cancel' in request.POST:
        return HTTPFound(location=model_url(context.__parent__, request))

    if 'form.submitted' in request.POST:
        converted = form.validate(request.POST)
        form.is_valid = True
        parent = context.__parent__
        creator = authenticated_userid(request)
        c = create_content(
            IComment,
            'Re: %s' % parent.title,
            converted['add_comment'],
            extract_description(converted['add_comment']),
            creator,
            )
        next_id = parent['comments'].next_id
        parent['comments'][next_id] = c
        if workflow is not None:
            workflow.initialize(c)
            if 'security_state' in converted:
                workflow.transition_to_state(c, request,
                                             converted['security_state'])

        if support_attachments(c):
            store_attachments(c, request.params, creator)
        relocate_temp_images(c, request)

        url = model_url(parent, request)
        msg = 'Comment added'
        url = url + '?status_message=%s' % urllib.quote(msg)

        blogentry = find_interface(context, IBlogEntry)
        if converted['sendalert']:
            alerts = queryUtility(IAlerts, default=Alerts())
            alerts.emit(c, request)

        return HTTPFound(location=url)

    # XXX Need different flow of control here, since it isn't
    # self-posting.

    else:
        raise Invalid('This is not a self-posting form. It is submit only.',
                      None, None)
示例#31
0
文件: test_utils.py 项目: iotest3/new
 def _callFUT(self, htmlstring):
     from karl.content.views.utils import extract_description
     return extract_description(htmlstring)
示例#32
0
def add_calendarevent_view(context, request):

    tags_list=request.POST.getall('tags')
    form = AddCalendarEventForm(tags_list=tags_list)
    workflow = get_workflow(ICalendarEvent, 'security', context)

    if workflow is None:
        security_states = []
    else:
        security_states = get_security_states(workflow, None, request)

    if security_states:
        form.add_field('security_state', security_state_field)

    if 'form.cancel' in request.POST:
        return HTTPFound(location=model_url(context, request))

    if 'form.submitted' in request.POST:
        try:
            if 'calendar_category' not in request.POST:
                # FormEncode doesn't let us mark certain keys as being missable
                # Either any key can be missing from form or none, so we just
                # manually massage calendar_category, which may be missing,
                # before performing validation.
                request.POST['calendar_category'] = None

            converted = form.validate(request.POST)

            creator = authenticated_userid(request)
            if converted['contact_email'] is None:
                # Couldn't convince the email validator to call
                # _to_python
                converted['contact_email'] = u''
            calendarevent = create_content(ICalendarEvent,
                                           converted['title'],
                                           converted['startDate'],
                                           converted['endDate'],
                                           creator,
                                           converted['text'],
                                           converted['location'],
                                           converted['attendees'],
                                           converted['contact_name'],
                                           converted['contact_email'],
                                           calendar_category=
                                            converted['calendar_category'],
                                           )
            calendarevent.description = extract_description(converted['text'])

            calname = make_unique_name(context, calendarevent.title)
            context[calname] = calendarevent

            # Set up workflow
            if workflow is not None:
                workflow.initialize(calendarevent)
                if 'security_state' in converted:
                    workflow.transition_to_state(calendarevent, request,
                                                 converted['security_state'])

            # Save the tags on it.
            set_tags(calendarevent, request, converted['tags'])
            store_attachments(calendarevent['attachments'],
                              request.params, creator)

            if converted['sendalert']:
                alerts = queryUtility(IAlerts, default=Alerts())
                alerts.emit(calendarevent, request)

            location = model_url(calendarevent, request)
            return HTTPFound(location=location)

        except Invalid, e:
            fielderrors = e.error_dict
            fill_values = form.convert(request.POST)
            tags_field = dict(
                records = [dict(tag=t) for t in request.POST.getall('tags')]
                )
示例#33
0
 def _callFUT(self, htmlstring):
     from karl.content.views.utils import extract_description
     return extract_description(htmlstring)