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)
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)
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)
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')] )