def test_unicode(self): from karl.views.utils import make_unique_name context = self._make_context() self.assertEqual(make_unique_name(context, u'what?'), "what") self.assertEqual(make_unique_name(context, u"\u0fff"), "-fff-") self.assertEqual(make_unique_name(context, u"\u0081\u0082"), "-81-82-") self.assertEqual(make_unique_name(context, u'foo\u008ab\u00c3ll'), "foosball")
def test_make_unique_name_noextension(self): from karl.views.utils import make_unique_name context = self._make_context() name = make_unique_name(context, 'opensociety') self.assertEqual(name, 'opensociety') for i in range(1, 20): context[name] = testing.DummyModel() name = make_unique_name(context, 'opensociety') self.assertEqual(name, 'opensociety-%i' % (i, ))
def test_make_unique_name_numbers(self): from karl.views.utils import make_unique_name context = self._make_context() name = make_unique_name(context, '123-456.78') self.assertEqual(name, '123-456.78') for i in range(1, 20): context[name] = testing.DummyModel() name = make_unique_name(context, '123-456.78') self.assertEqual(name, '123-456-%i.78' % (i, ))
def test_empty_name(self): from karl.views.utils import make_unique_name context = self._make_context() self.assertEqual(make_unique_name(context, '$@?%'), '-1') name = make_unique_name(context, '$@?%') self.assertEqual(name, '-1') for i in range(2, 101): context[name] = testing.DummyModel() name = make_unique_name(context, '$@?%') self.assertEqual(name, '-%i' % (i, ))
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)
def add_referencemanual_view(context, request): tags_list=request.POST.getall('tags') form = AddReferenceManualForm(tags_list=tags_list) if 'form.cancel' in request.POST: return HTTPFound(location=model_url(context, request)) if 'form.submitted' in request.POST: try: converted = form.validate(request.POST) # Create the reference manual and store it creator = authenticated_userid(request) reference_manual = create_content(IReferenceManual, converted['title'], converted['description'], creator, ) name = make_unique_name(context, converted['title']) context[name] = reference_manual # Save the tags on it. set_tags(reference_manual, request, converted['tags']) location = model_url(reference_manual, 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')] )
def evolve(root): former_id = None # Create lazily, in case we don't need it profiles = find_profiles(root) search = ICatalogSearch(root) catalog = find_catalog(root) creators = catalog['creator']._fwd_index.keys() modifiers = catalog['modified_by']._fwd_index.keys() userids = set(creators) | set(modifiers) for userid in userids: if userid not in profiles: if former_id is None: former_id = make_unique_name(profiles, 'formeruser') print "Creating profile for former user content:", former_id former_profile = create_content( IProfile, firstname='Former', lastname='User' ) profiles[former_id] = former_profile count, docids, resolver = search(creator=userid) for docid in docids: doc = resolver(docid) print "Updating 'creator' for", resource_path(doc) doc.creator = former_id count, docids, resolver = search(modified_by=userid) for docid in docids: doc = resolver(docid) print "Updating 'modified_by' for", resource_path(doc) doc.modified_by = former_id
def handle_submit(self, converted): request = self.request context = self.context workflow = self.workflow forum = create_content( IForum, converted['title'], converted['description'], authenticated_userid(request), ) name = make_unique_name(context, converted['title']) context[name] = forum # Set up workflow if workflow is not None: workflow.initialize(forum) if 'security_state' in converted: workflow.transition_to_state(forum, request, converted['security_state']) if 'sendalert' in converted and converted['sendalert']: alerts = queryUtility(IAlerts, default=Alerts()) alerts.emit(forum, request) location = resource_url(forum, request) return HTTPFound(location=location)
def evolve(root): former_id = None # Create lazily, in case we don't need it profiles = find_profiles(root) search = ICatalogSearch(root) catalog = find_catalog(root) creators = catalog['creator']._fwd_index.keys() modifiers = catalog['modified_by']._fwd_index.keys() userids = set(creators) | set(modifiers) for userid in userids: if userid not in profiles: if former_id is None: former_id = make_unique_name(profiles, 'formeruser') print "Creating profile for former user content:", former_id former_profile = create_content(IProfile, firstname='Former', lastname='User') profiles[former_id] = former_profile count, docids, resolver = search(creator=userid) for docid in docids: doc = resolver(docid) print "Updating 'creator' for", resource_path(doc) doc.creator = former_id count, docids, resolver = search(modified_by=userid) for docid in docids: doc = resolver(docid) print "Updating 'modified_by' for", resource_path(doc) doc.modified_by = former_id
def store_attachments(attachments_folder, params, creator): """Given some request data, pick apart and store attachments""" # Get the attachments out of the form data. We do iteritems # becauser there might be multiple with the name prefixed by # attachment. new_attachments = [] for key, value in params.iteritems(): if key.startswith('attachment') and value != '': new_attachments.append(value) # Iterate through the new attachments and create content to store in # the attachments folder. for attachment in new_attachments: filename = make_unique_name(attachments_folder, basename_of_filepath(attachment.filename)) attachments_folder[filename] = obj = create_content( ICommunityFile, title = filename, stream = attachment.file, mimetype = attachment.type, filename = filename, creator = creator, ) check_upload_size(attachments_folder, obj, 'attachment')
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)
def handle_submit(self, converted): request = self.request context = self.context ordering = getattr(context, 'ordering', None) if ordering is not None: ordering.sync(context.keys()) creator = authenticated_userid(request) reference_object = create_content( self.content_iface, converted['title'], converted['description'], creator, ) name = make_unique_name(context, converted['title']) context[name] = reference_object if ordering is not None: ordering.add(name) # save the tags set_tags(reference_object, request, converted['tags']) location = resource_url(reference_object, request) return HTTPFound(location=location)
def test_make_unique_name(self): from karl.views.utils import make_unique_name context = self._make_context() name = make_unique_name(context, 'foo.bar') self.assertEqual(name, 'foo.bar') for i in range(1, 20): context[name] = testing.DummyModel() name = make_unique_name(context, 'foo.bar') self.assertEqual(name, 'foo-%i.bar' % (i, )) name = make_unique_name(context, 'something.else.bar') self.assertEqual(name, 'something.else.bar') for i in range(1, 20): context[name] = testing.DummyModel() name = make_unique_name(context, 'something.else.bar') self.assertEqual(name, 'something.else-%i.bar' % (i, ))
def handle_submit(self, converted): request = self.request context = self.context #create the news item and store it creator = authenticated_userid(request) newsitem = create_content( INewsItem, title=converted['title'], text=converted['text'], creator=creator, publication_date=converted['publication_date'], caption=converted['caption'], ) name = make_unique_name(context, converted['title']) context[name] = newsitem relocate_temp_images(newsitem, request) # tags, attachments, and photos set_tags(newsitem, request, converted['tags']) attachments_folder = newsitem['attachments'] upload_attachments(converted['attachments'], attachments_folder, creator, request) try: handle_photo_upload(newsitem, converted) except Invalid, e: raise ValidationError(**e.error_dict)
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)
def upload_attachments(attachments, folder, creator, request): """ This creates *and removes* attachments based on information retrieved from a form""" for attachment in attachments: if attachment.filename: mimetype = get_upload_mimetype(attachment) filename = make_unique_name( folder, basename_of_filepath(attachment.filename) ) folder[filename] = obj = create_content( ICommunityFile, title = filename, stream = attachment.file, mimetype = mimetype, filename = filename, creator = creator, ) max_size = int(get_setting(folder, 'upload_limit', 0)) if max_size and obj.size > max_size: msg = 'File size exceeds upload limit of %d.' % max_size raise ValueError(msg) else: meta = attachment.metadata if meta.get('remove') and meta.get('default'): name = meta['default'] if name in folder: ob = folder[name] if has_permission('delete', ob, request): del folder[name]
def handle_submit(self, converted): request = self.request context = self.context #create the news item and store it creator = authenticated_userid(request) newsitem = create_content( INewsItem, title=converted['title'], text=converted['text'], creator=creator, publication_date=converted['publication_date'], caption=converted['caption'], ) name = make_unique_name(context, converted['title']) context[name] = newsitem # tags, attachments, and photos set_tags(newsitem, request, converted['tags']) attachments_folder = newsitem['attachments'] upload_attachments(converted['attachments'], attachments_folder, creator, request) try: handle_photo_upload(newsitem, converted) except Invalid, e: raise ValidationError(**e.error_dict)
def upload_attachments(attachments, folder, creator, request): """ This creates *and removes* attachments based on information retrieved from a form""" for attachment in attachments: if attachment.filename: mimetype = get_upload_mimetype(attachment) filename = make_unique_name( folder, basename_of_filepath(attachment.filename)) folder[filename] = obj = create_content( ICommunityFile, title=filename, stream=attachment.file, mimetype=mimetype, filename=filename, creator=creator, ) max_size = int(get_setting(folder, 'upload_limit', 0)) if max_size and obj.size > max_size: msg = 'File size exceeds upload limit of %d.' % max_size raise ValueError(msg) else: meta = attachment.metadata if meta.get('remove') and meta.get('default'): name = meta['default'] if name in folder: ob = folder[name] if has_permission('delete', ob, request): del folder[name]
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) folder = create_content(ICommunityFolder, converted['title'], creator, ) context[name] = folder if workflow is not None: workflow.initialize(folder) if 'security_state' in converted: workflow.transition_to_state(folder, request, converted['security_state']) # Tags, attachments, alerts set_tags(folder, request, converted['tags']) # Make changes post-creation based on policy in src/osi customizer = queryMultiAdapter((folder, request), IFolderCustomizer) if customizer: for interface in customizer.markers: alsoProvides(folder, interface) location = model_url(folder, 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 handle_submit(self, converted): request = self.request context = self.context #create the news item and store it creator = authenticated_userid(request) newsitem = create_content( INewsItem, title=converted['title'], text=converted['text'], creator=creator, publication_date=converted['publication_date'], caption=converted['caption'], ) name = make_unique_name(context, converted['title']) context[name] = newsitem # tags, attachments, and photos set_tags(newsitem, request, converted['tags']) attachments_folder = newsitem['attachments'] upload_attachments(converted['attachments'], attachments_folder, creator, request) handle_photo_upload(newsitem, converted) self.filestore.clear() location = model_url(newsitem, request) return HTTPFound(location=location)
def move_content(root, src, dst, wf_state): try: context = find_resource(root, src) except KeyError: print >> sys.stderr, "Source content not found: %s" % src sys.exit(-1) try: dest_folder = find_resource(root, dst) except KeyError: print >> sys.stderr, "Destination folder not found: %s" % dst sys.exit(-1) src_community = find_community(context) catalog = find_catalog(root) assert catalog is not None users = find_users(root) assert users is not None if src_community is not None: move_header = ('<p><em>This was originally authored ' 'in the "%s" community.</em></p>' % src_community.title) else: move_header = '' src_folder = context.__parent__ name = context.__name__ log.info("Moving %s", resource_path(context)) for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.remove_docid(docid) catalog.unindex_doc(docid) del src_folder[name] if (context.creator != 'admin' and users.get_by_id(context.creator) is None): # give the entry to the system admin log.warning("User %s not found; reassigning to admin", context.creator) context.creator = 'admin' if name in dest_folder: name = make_unique_name(dest_folder, context.title) dest_folder[name] = context for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.add(resource_path(obj), docid) catalog.index_doc(docid, obj) if wf_state is not None: wf = get_workflow(get_content_type(context), 'security', context) wf.transition_to_state(context, None, wf_state) if hasattr(context, 'text'): context.text = "%s\n%s" % (move_header, context.text)
def _restore(repo, parent, docid, name): version = repo.history(docid, only_current=True)[0] doc = version.klass() doc.revert(version) if name in parent: # Choose a non-conflicting name to restore to. (LP #821206) name = make_unique_name(parent, name) parent.add(name, doc, send_events=False) return doc
def _addAttachments(att_folder, info, attachments): for filename, mimetype, data in attachments: stream = StringIO(data) name = make_unique_name(att_folder, filename) attachment = create_content(ICommunityFile, title = filename, stream = stream, mimetype = mimetype, filename = filename, creator = info['author'], ) att_folder[name] = attachment
def _addAttachments(att_folder, info, attachments): for filename, mimetype, data in attachments: stream = StringIO(data) name = make_unique_name(att_folder, filename) attachment = create_content( ICommunityFile, title=filename, stream=stream, mimetype=mimetype, filename=filename, creator=info['author'], ) att_folder[name] = attachment
def test_make_name(self): from karl.views.utils import make_unique_name context = self._make_context() self.assertEqual(make_unique_name(context, "foo.bar"), "foo.bar") self.assertEqual(make_unique_name(context, "Harry 'Bigfoot' Henderson"), "harry-bigfoot-henderson") self.assertEqual(make_unique_name(context, "Which one?"), "which-one") self.assertEqual(make_unique_name(context, "One/Two/Three"), "one-two-three") self.assertEqual(make_unique_name(context, "Genesis 1:1"), "genesis-1-1") self.assertEqual(make_unique_name(context, "'My Life'"), "-my-life-")
def move_content_view(context, request): """ Move content from one community to another. Only blog entries supported for now. May or may not eventually expand to other content types. """ request.layout_manager.use_layout('admin') api = AdminTemplateAPI(context, request, 'Admin UI: Move Content') filtered_content = [] if 'filter_content' in request.params: # We're limiting ourselves to content that always lives in the same # place in each community, ie /blog, /calendar, /wiki, etc, so that # we can be pretty sure we can figure out where inside the destination # community we should move it to. filtered_content = _get_filtered_content( context, request, [IBlogEntry, IWikiPage, ICalendarEvent]) if not filtered_content: api.error_message = 'No content matches your query.' if 'move_content' in request.params: to_community = request.params.get('to_community', '') if not to_community: api.error_message = 'Please specify destination community.' else: try: paths = request.params.getall('selected_content') dst_community = find_resource(context, to_community) for path in paths: obj = find_resource(context, path) dst_container = _find_dst_container(obj, dst_community) name = make_unique_name(dst_container, obj.__name__) del obj.__parent__[obj.__name__] dst_container[name] = obj if len(paths) == 1: status_message = 'Moved one content item.' else: status_message = 'Moved %d content items.' % len(paths) redirect_to = resource_url( context, request, request.view_name, query=dict(status_message=status_message) ) return HTTPFound(location=redirect_to) except _DstNotFound, error: api.error_message = str(error)
def move_content_view(context, request): """ Move content from one community to another. Only blog entries supported for now. May or may not eventually expand to other content types. """ api = AdminTemplateAPI(context, request, 'Admin UI: Move Content') filtered_content = [] if 'filter_content' in request.params: # We're limiting ourselves to content that always lives in the same # place in each community, ie /blog, /calendar, /wiki, etc, so that # we can be pretty sure we can figure out where inside the destination # community we should move it to. filtered_content = _get_filtered_content( context, request, [IBlogEntry, IWikiPage, ICalendarEvent]) if not filtered_content: api.error_message = 'No content matches your query.' if 'move_content' in request.params: to_community = request.params.get('to_community', '') if not to_community: api.error_message = 'Please specify destination community.' else: try: paths = request.params.getall('selected_content') dst_community = find_resource(context, to_community) for path in paths: obj = find_resource(context, path) dst_container = _find_dst_container(obj, dst_community) name = make_unique_name(dst_container, obj.__name__) del obj.__parent__[obj.__name__] dst_container[name] = obj if len(paths) == 1: status_message = 'Moved one content item.' else: status_message = 'Moved %d content items.' % len(paths) redirect_to = resource_url( context, request, request.view_name, query=dict(status_message=status_message)) return HTTPFound(location=redirect_to) except _DstNotFound, error: api.error_message = str(error)
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))
def test_make_name(self): from karl.views.utils import make_unique_name context = self._make_context() self.assertEqual(make_unique_name(context, "foo.bar"), "foo.bar") self.assertEqual( make_unique_name(context, "Harry 'Bigfoot' Henderson"), "harry-bigfoot-henderson") self.assertEqual(make_unique_name(context, "Which one?"), "which-one") self.assertEqual(make_unique_name(context, "One/Two/Three"), "one-two-three") self.assertEqual(make_unique_name(context, "Genesis 1:1"), "genesis-1-1") self.assertEqual(make_unique_name(context, "'My Life'"), "-my-life-")
def relocate(match): matchdict = match.groupdict() tempid = matchdict['tempid'] if tempid in relocated_images: # Already relocated this one url = relocated_images[tempid] else: # Move temp image to attachments folder image = tempfolder[tempid] del tempfolder[tempid] name = make_unique_name(attachments, image.filename) attachments[name] = image size = (int(matchdict['width']), int(matchdict['height'])) url = thumb_url(image, request, size) relocated_images[tempid] = url workflow = get_workflow(ICommunityFile, 'security', image) if workflow is not None: workflow.initialize(image) return ''.join([matchdict['pre'], url, matchdict['post'],])
def add_referencesection_view(context, request): tags_list=request.POST.getall('tags') form = AddReferenceSectionForm(tags_list = tags_list) if 'form.cancel' in request.POST: return HTTPFound(location=model_url(context, request)) if 'form.submitted' in request.POST: try: converted = form.validate(request.POST) # Be a chicken and sync the ordering every time before # adding something, just to make sure nothing gets lost. context.ordering.sync(context.keys()) # Create the reference section and store it creator = authenticated_userid(request) reference_section = create_content(IReferenceSection, converted['title'], converted['description'], creator, ) name = make_unique_name(context, converted['title']) context[name] = reference_section # Save the tags on it. set_tags(reference_section, request, converted['tags']) # Update the ordering context.ordering.add(name) location = model_url(reference_section, 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')] )
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)
def _undelete(repo, parent, docid, name, restore_children): version = repo.history(docid, only_current=True)[0] doc = version.klass() doc.revert(version) if restore_children: try: container = repo.container_contents(docid) except NoResultFound: container = None if container is not None: for child_name, child_docid in container.map.items(): _undelete(repo, doc, child_docid, child_name, True) if name in parent: # Choose a non-conflicting name to restore to. (LP #821206) name = make_unique_name(parent, name) parent.add(name, doc, send_events=False) return doc
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)
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 handle_submit(self, converted): request = self.request context = self.context workflow = self.workflow forum = create_content(IForum, converted['title'], converted['description'], authenticated_userid(request), ) name = make_unique_name(context, converted['title']) context[name] = forum # Set up workflow if workflow is not None: workflow.initialize(forum) if 'security_state' in converted: workflow.transition_to_state(forum, request, converted['security_state']) location = model_url(forum, request) return HTTPFound(location=location)
def handle_submit(self, converted): request = self.request context = self.context ordering = getattr(context, 'ordering', None) if ordering is not None: ordering.sync(context.keys()) creator = authenticated_userid(request) reference_object = create_content(self.content_iface, converted['title'], converted['description'], creator, ) name = make_unique_name(context, converted['title']) context[name] = reference_object if ordering is not None: ordering.add(name) # save the tags set_tags(reference_object, request, converted['tags']) location = resource_url(reference_object, request) return HTTPFound(location=location)
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')] )
def move_content(root, src, dst, wf_state): try: context = find_resource(root, src) except KeyError: print >>sys.stderr, "Source content not found: %s" % src sys.exit(-1) try: dest_folder = find_resource(root, dst) except KeyError: print >>sys.stderr, "Destination folder not found: %s" % dst sys.exit(-1) src_community = find_community(context) catalog = find_catalog(root) assert catalog is not None users = find_users(root) assert users is not None if src_community is not None: move_header = ('<p><em>This was originally authored ' 'in the "%s" community.</em></p>' % src_community.title) else: move_header = '' src_folder = context.__parent__ name = context.__name__ log.info("Moving %s", resource_path(context)) for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.remove_docid(docid) catalog.unindex_doc(docid) del src_folder[name] if (context.creator != 'admin' and users.get_by_id(context.creator) is None): # give the entry to the system admin log.warning( "User %s not found; reassigning to admin", context.creator) context.creator = 'admin' if name in dest_folder: name = make_unique_name(dest_folder, context.title) dest_folder[name] = context for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.add(resource_path(obj), docid) catalog.index_doc(docid, obj) if wf_state is not None: wf = get_workflow(get_content_type(context), 'security', context) wf.transition_to_state(context, None, wf_state) if hasattr(context, 'text'): context.text = "%s\n%s" % (move_header, context.text)