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)
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)
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)
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)
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)
def show_comment_view(context, request): page_title = "Comment on " + context.title api = TemplateAPI(context, request, page_title) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) byline_info = getMultiAdapter((context, request), IBylineInfo) container = find_interface(context, IBlogEntry) if container is None: # Comments can also be in forum topics container = find_interface(context, IForumTopic) if container is None: # Comments can also be files container = find_interface(context, ICommunityFile) backto = { 'href': resource_url(container, request), 'title': container.title, } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context, request) else: attachments = () return render_to_response( 'templates/show_comment.pt', dict(api=api, actions=actions, byline_info=byline_info, attachments=attachments, backto=backto, layout=layout), request=request, )
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 show_comment_view(context, request): page_title = "Comment on " + context.title api = TemplateAPI(context, request, page_title) actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) byline_info = getMultiAdapter((context, request), IBylineInfo) container = find_interface(context, IBlogEntry) if container is None: # Comments can also be in forum topics container = find_interface(context, IForumTopic) backto = { 'href': resource_url(container, request), 'title': container.title, } # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context, request) else: attachments = () return render_to_response( 'templates/show_comment.pt', dict(api=api, actions=actions, byline_info=byline_info, attachments=attachments, backto=backto, old_layout=layout), request=request, )
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)
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)
def support_attachments(self): return support_attachments(self.context)
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 show_forum_topic_view(context, request): post_url = resource_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) # Convert comments into a digestable form for the template comments = [] page_title = context.title actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) if has_permission('administer', context, request): actions.append(('Advanced', 'advanced.html')) api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = resource_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = resource_url(comment, request, 'edit.html') else: newc['edit_url'] = None if has_permission('delete', comment, request): newc['delete_url'] = resource_url(comment, request, 'delete.html') else: newc['delete_url'] = None if has_permission('administer', comment, request): newc['advanced_url'] = resource_url(comment, request, 'advanced.html') else: newc['advanced_url'] = None # Display portrait photo = profile.get('photo') photo_url = {} if photo is not None: photo_url = thumb_url(photo, request, PROFILE_THUMB_SIZE) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda x: x['timestamp']) byline_info = getMultiAdapter((context, request), IBylineInfo) forum = find_interface(context, IForum) backto = { 'href': resource_url(forum, request), 'title': forum.title, } # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Get a layout layout_provider = get_layout_provider(context, request) old_layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context['attachments'], request) else: attachments = () # manually construct formish comment form controller = AddCommentFormController(context['comments'], request) form_schema = schemaish.Structure() form_fields = controller.form_fields() for fieldname, field in form_fields: form_schema.add(fieldname, field) form_action_url = '%sadd_comment.html' % resource_url(context['comments'], request) comment_form = Form(form_schema, add_default_action=False, name='save', action_url=form_action_url) form_defaults = controller.form_defaults() comment_form.defaults = form_defaults request.form_defaults = form_defaults form_actions = [FormAction('submit', 'submit'), FormAction('cancel', 'cancel', validate=False)] for action in form_actions: comment_form.add_action(action.name, action.title) widgets = controller.form_widgets(form_fields) for name, widget in widgets.items(): comment_form[name].widget = widget # enable imagedrawer for adding forum replies (comments) api.karl_client_data['text'] = dict( enable_imagedrawer_upload = True, ) # ux2 layout = request.layout_manager.layout layout.section_style = "none" layout.head_data['panel_data']['tinymce'] = api.karl_client_data['text'] layout.head_data['panel_data']['tagbox'] = client_json_data['tagbox'] layout.add_portlet('tagbox') return render_to_response( 'templates/show_forum_topic.pt', dict(api=api, actions=actions, comments=comments, attachments=attachments, formfields=api.formfields, post_url=post_url, byline_info=byline_info, head_data=convert_to_script(client_json_data), backto=backto, old_layout=old_layout, comment_form=comment_form), request=request, )
security_state = '' else: security_state = workflow.state_of(context) fill_values = dict( add_comment=context.text, security_state = security_state) # Render the form and shove some default values in page_title = 'Edit ' + context.title api = TemplateAPI(context, request, page_title) # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context, request) else: attachments = () return render_form_to_response( 'templates/edit_comment.pt', form, fill_values, post_url=request.url, formfields=api.formfields, fielderrors=fielderrors, api=api, attachments=attachments, layout=layout, security_states = security_states,
def show_forum_topic_view(context, request): post_url = model_url(context, request, "comments", "add_comment.html") karldates = getUtility(IKarlDates) profiles = find_profiles(context) # Convert comments into a digestable form for the template comments = [] page_title = context.title actions = [] if has_permission('edit', context, request): actions.append(('Edit', 'edit.html')) if has_permission('delete', context, request): actions.append(('Delete', 'delete.html')) api = TemplateAPI(context, request, page_title) for comment in context['comments'].values(): profile = profiles.get(comment.creator) author_name = profile.title author_url = model_url(profile, request) newc = {} newc['id'] = comment.__name__ if has_permission('edit', comment, request): newc['edit_url'] = model_url(comment, request, 'edit.html') newc['delete_url'] = model_url(comment, request, 'delete.html') else: newc['edit_url'] = None newc['delete_url'] = None # Display portrait photo = profile.get_photo() photo_url = {} if photo is not None: photo_url = model_url(photo, request) else: photo_url = api.static_url + "/images/defaultUser.gif" newc["portrait_url"] = photo_url newc['author_url'] = author_url newc['author_name'] = author_name newc['date'] = karldates(comment.created, 'longform') newc['timestamp'] = comment.created newc['text'] = comment.text # Fetch the attachments info newc['attachments'] = fetch_attachments(comment, request) comments.append(newc) comments.sort(key=lambda x: x['timestamp']) byline_info = getMultiAdapter((context, request), IBylineInfo) forum = find_interface(context, IForum) backto = { 'href': model_url(forum, request), 'title': forum.title, } # provide client data for rendering current tags in the tagbox client_json_data = dict( tagbox = get_tags_client_data(context, request), ) # Get a layout layout_provider = get_layout_provider(context, request) layout = layout_provider('community') if support_attachments(context): attachments = fetch_attachments(context['attachments'], request) else: attachments = () return render_template_to_response( 'templates/show_forum_topic.pt', api=api, actions=actions, comments=comments, attachments=attachments, formfields=api.formfields, post_url=post_url, byline_info=byline_info, head_data=convert_to_script(client_json_data), backto=backto, layout=layout, )