def create_plasmoid(self, client): ''' Creates a new plasmoid ''' form = EditPlasmoidForm() plasmoid = Plasmoid() plasmoid.uuid = str(uuid.uuid4()) main = render_to_string("plasmoids/create_plasmoid.html",{'plasmoid':plasmoid,'form': form}) return { 'data':{ 'dom':{'main':main}, 'plasmoid':{'uuid':plasmoid.uuid} } }
def save_plasmoid(self, client, plasmoid_uuid, form): _content = form['content'] del form['content'] form = EditPlasmoidForm(form) if form.is_valid(): try: plasmoid = Plasmoid.objects.get(pk = plasmoid_uuid) except Plasmoid.DoesNotExist: plasmoid = Plasmoid() publish_activity(client.profile, _('Plasmoid created'),'/plasmoids/%s/edit/' % plasmoid_uuid,[0,0,4,0,0]) plasmoid.slug = form.cleaned_data['slug'] plasmoid.script = _content plasmoid.type = form.cleaned_data['type'] plasmoid.target = form.cleaned_data['target'] plasmoid.visible = int(form.cleaned_data['visible']) plasmoid.last_modified = datetime.now() plasmoid.save() client_response, tpl_params = self._get_plasmoids(client) #UPDATE ROUTES HWIOS.plasmoids.get_routes() client_response.update({ 'status':{ 'code':'PLASMOID_EDIT_OK', 'i18n':_('Plasmoid %(slug)s stored...') % {'slug':plasmoid.slug}, 'type': HWIOS.ws_realm._t['notify-info'], } }) notify_others(client, client_response,'/plasmoids/modified/', '^/plasmoids/$', tpl_params) publish_activity(client.profile, _('Plasmoid saved'),'/plasmoids/%s/edit/' % plasmoid_uuid,[0,0,4,0,0]) return client_response else: try: plasmoid = Plasmoid.objects.get(pk = plasmoid_uuid) except ObjectDoesNotExist: plasmoid = Plasmoid() main = render_to_string("plasmoids/edit_plasmoid.html", {'plasmoid':plasmoid, "form":form}) response = { 'status':{ 'code':'FORM_INVALID', 'i18n':_('Invalid Form!'), 'type': HWIOS.ws_realm._t['notify-warning'] }, 'data':{'dom':{'main':main}} } return response