Exemplo n.º 1
0
    def edit_entity(self, client, uuid, form = None):
        """
        Edit an existing or a new plasmoid. In both cases, the infinote subscription pool defines the plasmoid view, not the model. This makes it
        possible to edit a new plasmoid, that's not yet in the database.

        :param Client client: The requesting client
        :param str plasmoid_uuid: The uuid of the plasmoid to edit
        :return: dict - Data and html-layout response
        """
        if form == None:
            try:
                entity = PageEntity.objects.get(pk = uuid)
            except ObjectDoesNotExist:
                entity = PageEntity()
                entity.code = ''
            client.role = 'edit'
            form = EntityForm(initial={'slug':entity.slug,'anchor':entity.anchor,'type':entity.type})
            main = render_to_string("pages/edit_entity.html",{'entity':entity, 'form': form})
            subscriber = self.infinote_pool.subscribe(client, uuid, entity.code, 'entities', self._signal_presence)
            publish_activity(client.profile, _('Entity editing'),'/pages/entities/%s/edit/' % uuid,[0,0,4,0,0])
            return {
                'data':{
                    'ce':subscriber,
                    'uid': client.profile.pk,
                    'dom':{'main':main}
                }
            } 
        else:
            print "PROCESS NEW!"
            _content = form['content']
            del form['content']
            form = EntityForm(form)
            form.content = _content
            response = self._try_save_entity(client, uuid, form)
            return response
Exemplo n.º 2
0
    def create_entity(self, client, uuid, form = None):
        """Render and returns the create plasmoid view

        :param Client client: The requesting client
        :return: dict - Data and html-layout response
        """
        if form == None:
            form = EntityForm()
            entity = PageEntity()
            entity.uuid = uuid
            subscriber = self.infinote_pool.subscribe(client, uuid, '', 'entities', self._signal_presence)
            main = render_to_string("pages/create_entity.html",{'entity':entity,'form': form})
            return {
                'data':{
                    'ce':subscriber,
                    'uid': client.profile.pk,
                    'dom':{'main':main},
                }
            }
        else:
            print "PROCESS NEW!"
            _content = form['content']
            del form['content']
            form = EntityForm(form)
            form.content = _content
            response = self._try_save_entity(client, uuid, form)
            return response