def __call__(self, request, content_object, **kwargs): logger.debug('Updating object: "%s"' % str(content_object)) try: # specific update factory component hook update_factory = get_component('TreeContentUpdateFactory', (content_object,)) update_factory(request, content_object, **kwargs) except ComponentDoesNotExist: # generic content object update filtered_data = filter_and_clean_fields(request.tree_context.node.content_type, **kwargs) logger.debug("filtered_data: " + str(filtered_data) ) content_object.__dict__.update(**filtered_data) content_object.save() if hasattr(request, 'user'): username = request.user.username else: # if serving backend tree web service, no auth and no request.user username = kwargs.get('authenticated_username') #XXX do we need to recalculate slug?? # probably not as it changes node absolute_path # any cached urls to the page.. #XXX send signal updated node, do we need this, this possibly the only place # node upated, could invoke it directly #tree_content_updated.send(sender=content_object, username=username) updated_node = update_node_factory(content_object.node, username=username) #return request.tree_context.node return updated_node
def __call__(self, request, create_content_type, **kwargs): logger.debug('creating obj of type: "%s"' % str(create_content_type)) create_content_type_name = create_content_type.app_label + '.' + create_content_type.model try: create_factory = get_component('TreeContentCreateFactory', name=create_content_type_name) new_content_object = create_factory(request, create_content_type, **kwargs) except ComponentDoesNotExist: # generic content creation filtered_data = filter_and_clean_fields(create_content_type, **kwargs) model_class = create_content_type.model_class() new_content_object = model_class(**filtered_data) new_content_object.save() ## need to create tree node ## # calc node slug try: slugutil = get_component('SlugUtil', name=create_content_type_name) slug = slugutil.calc_slug(new_content_object, request, **kwargs) except ComponentDoesNotExist: # generic slug slug = SlugUtil.calc_slug(new_content_object, request, **kwargs) # node can also be ordered by seq_num seq_num = kwargs.get('seq_num') parent_node = request.tree_context.node if hasattr(request, 'user'): username = request.user.username else: # if serving backend tree web service, no auth and no request.user username = kwargs.get('authenticated_username') #XXX send signal creating node, do we need this, this possibly the only place # node created, could invoke it directly #tree_content_created.send(sender=new_content_object, parent_node=parent_node, username=username, slug=slug, seq_num=seq_num) new_node = create_node_factory(new_content_object, parent_node=parent_node, username=username, slug=slug, seq_num=seq_num) #logger.debug("object created") #XXX is signal processing asynchronos, node might not be created, # is it expensive referencing it here, do we need to return # aNSwER: yes we need to check node created to rollback if it didn't # or during node creating we need to raise some kind of exception which would # trigger rollback #return new_content_object.node return new_node