Exemple #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
Exemple #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
Exemple #3
0
    def _try_save_entity(self, client, uuid, form):
        """
        Save an existing or a new plasmoid, render/show the general plasmoid overview and notify others.

        :param Client client: The requesting client
        :param str plasmoid_uuid: The uuid of the plasmoid to save
        :return: dict - Status and html-layout response
        """
        if form.is_valid():
            try:
                entity = PageEntity.objects.get(pk = uuid)
                entity.slug = form.cleaned_data['slug']
                entity.anchor = form.cleaned_data['anchor']
                entity.code = form.content
                entity.type = form.cleaned_data['type']
                entity.last_modified = datetime.now()
                entity.save()
                client_response, tpl_params = self._get_pages(client)
                client_response.update({
                    'status':{
                        'code':'ENTITY_EDIT_OK',
                        'i18n':_('Page entity %(slug)s updated...') % {'slug':entity.slug},
                        'type': HWIOS.ws_realm._t['notify-info'],
                        'state': '/pages/',
                    }
                })
            except PageEntity.DoesNotExist:
                entity = PageEntity()
                publish_activity(client.profile, _('Page entity created'),'/pages/entities/%s/edit/' % uuid,[0,0,4,0,0])
                entity.slug = form.cleaned_data['slug']
                entity.anchor = form.cleaned_data['anchor']
                entity.code = form.content
                entity.type = form.cleaned_data['type']
                entity.last_modified = datetime.now()
                entity.save()
                client_response, tpl_params = self._get_pages(client)
                client_response.update({
                    'status':{
                        'code':'ENTITY_CREATE_OK',
                        'i18n':_('Page entity %(slug)s created...') % {'slug':entity.slug},
                        'type': HWIOS.ws_realm._t['notify-info'],
                        'state': '/pages/',
                    }
                })
            
            #UPDATE ROUTES
            HWIOS.anchors.get_routes()
            notify_others(client, client_response,'/pages/entities/modified/', '^/pages/$', tpl_params)
            publish_activity(client.profile, _('Page entity saved'),'/pages/entities/%s/edit/' % uuid,[0,0,4,0,0])
            return client_response
        else:
            try:
                entity = PageEntity.objects.get(pk = uuid)
                main = render_to_string("pages/edit_entity.html", {'entity':entity, "form":form})
            except ObjectDoesNotExist:
                entity = PageEntity()
                entity.slug = _('New Entity')
                entity.uuid = uuid
                main = render_to_string("pages/create_entity.html", {'entity':entity, "form":form})
            response = {
                'status':{
                    'code':'FORM_INVALID',
                    'i18n':_('Invalid Form!'),
                    'type': HWIOS.ws_realm._t['notify-warning']
                },
                'data':{'dom':{'main':main}}
            }
            return response