Exemplo n.º 1
0
    def update(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'igadgets')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("iGadget JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            tab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=workspace_id, pk=tab_id) 
            received_data = simplejson.loads(received_json)
            igadgets = received_data.get('iGadgets')
            for igadget in igadgets:
                UpdateIGadget(igadget, user, tab)
            transaction.commit()
            return HttpResponse('ok')
        except Tab.DoesNotExist:
            msg = _('referred tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadgets cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 2
0
    def delete(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)
        
        #set new order
        tabs = Tab.objects.filter(workspace__pk=workspace_id).order_by('position')

        # Get tab, if it does not exist, an http 404 error is returned
        tab = get_object_or_404(Tab, workspace__pk=workspace_id, pk=tab_id)
        
        #decrease the position of the following tabs
        for t in range(tab.position, tabs.count()):
            tabs[t].position = tabs[t].position - 1
        
        tabs = tabs.exclude(pk=tab_id)
        
        if tabs.count()==0:
            msg = _("tab cannot be deleted")
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')

        #Delete WorkSpace variables too!
        deleteTab(tab, user) 
        
        #set a new visible tab (first tab by default)
        activeTab=tabs[0]
        setVisibleTab(user, workspace_id, activeTab)

        return HttpResponse('ok')
Exemplo n.º 3
0
    def update(self, request, workspace_id, tab_id, igadget_id):
        user = get_user_authentication(request)
        
        received_json = PUT_parameter(request, 'variables')

        # Gets JSON parameter from request
        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("iGadget variables JSON expected")), mimetype='application/xml; charset=UTF-8')
        
        try:
            received_variables = simplejson.loads(received_json)
            
            tab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=workspace_id, pk=tab_id) 
            server_variables = Variable.objects.filter(igadget__tab=tab)
            
            # Gadget variables collection update
            for varServer in server_variables:
                for varJSON in received_variables:
                    if (varServer.vardef.pk == varJSON['pk'] and varServer.igadget.pk == varJSON['iGadget']):
                        varServer.value = varJSON['value']
                        varServer.save()
            
            transaction.commit()
        except Tab.DoesNotExist:
            msg = _('referred tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 4
0
    def update(self, request, workspace_id, tab_id, igadget_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'igadget')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            igadget = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)
            UpdateIGadget(igadget, user, tab)
            return HttpResponse('ok')
        except Tab.DoesNotExist:
            msg = _('referred tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadget cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 5
0
    def create(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        if not request.POST.has_key('igadget'):
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            received_json = request.POST['igadget']
            igadget = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)
            ids = SaveIGadget(igadget, user, tab)
            return HttpResponse(json_encode(ids),
                                mimetype='application/json; charset=UTF-8')
        except WorkSpace.DoesNotExist:
            msg = _('referred workspace %(workspace_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadget cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 6
0
    def create(self, request, user_name=None):
        user = get_user_authentication(request)
        if request.POST.has_key('url'):
            templateURL = request.POST['url']
        else:
            return HttpResponseServerError(
                '<error>Url not specified</error>',
                mimetype='application/xml; charset=UTF-8')

        ########### Template Parser
        templateParser = None

        try:
            # Gadget is created only once
            templateParser = TemplateParser(templateURL)
            gadget_uri = templateParser.getGadgetUri()
            try:
                gadget = Gadget.objects.get(uri=gadget_uri)
            except Gadget.DoesNotExist:
                # Parser creates the gadget. It's made only if the gadget does not exist
                templateParser.parse()
                gadget = templateParser.getGadget()

            # A new user has added the gadget in his showcase
            gadget.users.add(user)
            transaction.commit()
        except TemplateParseException, e:
            log(e, request)
            transaction.rollback()

            return HttpResponseServerError(
                get_xml_error(unicode(e)),
                mimetype='application/xml; charset=UTF-8')
Exemplo n.º 7
0
    def update(self, request, user_name, vendor, name, version):

        try:
            format = PUT_parameter(request, 'format')
        except:
            format = 'default'

        user = user_authentication(request, user_name)

        # Get the vote from the request
        vote = PUT_parameter(request, 'vote')

        # Get the gadget's id for those vendor, name and version
        gadget = get_object_or_404(GadgetResource,
                                   short_name=name,
                                   vendor=vendor,
                                   version=version)

        # Insert the vote for these resource and user in the database
        try:
            userVote = get_object_or_404(UserVote,
                                         idUser=user,
                                         idResource=gadget)
            userVote.vote = vote
            userVote.save()
        except Exception, ex:
            log(ex, request)
            return HttpResponseServerError(
                get_xml_error(unicode(ex)),
                mimetype='application/xml; charset=UTF-8')
Exemplo n.º 8
0
    def update(self, request, workspace_id):  
        user = get_user_authentication(request)
        
        received_json = PUT_parameter(request, 'variables') 

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("variables JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            variables = eval(received_json)
                    
            igadgetVariables = variables['igadgetVars']
            workSpaceVariables = variables['workspaceVars']
            
            for wsVar in workSpaceVariables:
                wsVarDAO = WorkSpaceVariable.objects.get(pk=wsVar['id'])
                   
                wsVarDAO.abstract_variable.value=wsVar['value'];
                wsVarDAO.abstract_variable.save();   
               
            for igVar in igadgetVariables:
                igVarDAO = Variable.objects.get(pk=igVar['id'])
   
                igVarDAO.abstract_variable.value=igVar['value'];
                igVarDAO.abstract_variable.save(); 
            
            return HttpResponse(str('OK'))
        except Exception, e:
            transaction.rollback()
            msg = _("cannot update variables: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 9
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'workspace')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("workspace JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            ts = simplejson.loads(received_json)
            workspace = WorkSpace.objects.get(users__id=user.id, pk=workspace_id)
            
            if ts.has_key('active'):
                active = ts.get('active')
                if (active == 'true'):
                    #Only one active workspace
                    setActiveWorkspace(user, workspace)
                else:
                    workspace.active = False
            
            if ts.has_key('name'):
                workspace.name = ts.get('name')
            
            workspace.save()
            
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 10
0
    def create(self, request, workspace_id):
        user = get_user_authentication(request)

        if not request.POST.has_key('tab'):
            return HttpResponseBadRequest(get_xml_error(_("tab JSON expected")), mimetype='application/xml; charset=UTF-8')

        #TODO we can make this with deserializers (simplejson)
        received_json = request.POST['tab']

        try:
            t = simplejson.loads(received_json)
            
            if not t.has_key('name'):
                raise Exception(_('Malformed tab JSON: expecting tab name.'))
            
            tab_name = t.get('name')
            workspace = WorkSpace.objects.get(users__id=user.id, pk=workspace_id)   
            
            ids = createTab(tab_name, user, workspace)
            
            return HttpResponse(json_encode(ids), mimetype='application/json; charset=UTF-8')

        except Exception, e:
            transaction.rollback()
            msg = _("tab cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 11
0
    def update(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)
        
        received_json = PUT_parameter(request, 'tab')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("tab JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            t = eval(received_json)
            tab = Tab.objects.get(workspace__user=user, workspace__pk=workspace_id, pk=tab_id)
            
            if t.has_key('visible'):
                visible = t.get('visible')
                if (visible == 'true'):
                    #Only one visible tab
                    setVisibleTab(user, workspace_id, tab)
                else:
                    tab.visible = False
            
            if t.has_key('name'):
                tab.name = t.get('name')
      
            tab.save()
            
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("tab cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 12
0
    def create(self, request):
        user = get_user_authentication(request)

        if not request.POST.has_key('workspace'):
            return HttpResponseBadRequest(get_xml_error(_("workspace JSON expected")), mimetype='application/xml; charset=UTF-8')

        #TODO we can make this with deserializers (simplejson)
        received_json = request.POST['workspace']

        try:
            ts = simplejson.loads(received_json)
            
            if not ts.has_key('name'):
                raise Exception(_('Malformed workspace JSON: expecting workspace uri.'))
            
            workspace_name = ts.get('name')

            ids = createWorkSpace (workspace_name, user)          
            
            workspaces = get_list_or_404(WorkSpace, users__id=user.id, pk=ids['workspace']['id'])
            data = serializers.serialize('python', workspaces, ensure_ascii=False)
            
            
            concept_data = {}
            concept_data['user'] = user
            workspace_data = get_global_workspace_data(data[0], workspaces[0], concept_data, user)
            
            return HttpResponse(json_encode(workspace_data), mimetype='application/json; charset=UTF-8')
            
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 13
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'workspace')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("workspace JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            ts = simplejson.loads(received_json)
            workspace = WorkSpace.objects.get(users__id=user.id, pk=workspace_id)
            
            if ts.has_key('active'):
                active = ts.get('active')
                if (active == 'true'):
                    #Only one active workspace
                    setActiveWorkspace(user, workspace)
                else:
                    workspace.active = False
            
            if ts.has_key('name'):
                workspace.name = ts.get('name')
            
            workspace.save()
            
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 14
0
    def create(self, request, workspace_id):
        user = get_user_authentication(request)

        if not request.POST.has_key('tab'):
            return HttpResponseBadRequest(get_xml_error(_("tab JSON expected")), mimetype='application/xml; charset=UTF-8')

        #TODO we can make this with deserializers (simplejson)
        received_json = request.POST['tab']

        try:
            t = simplejson.loads(received_json)
            
            if not t.has_key('name'):
                raise Exception(_('Malformed tab JSON: expecting tab name.'))
            
            tab_name = t.get('name')
            workspace = WorkSpace.objects.get(users__id=user.id, pk=workspace_id)   
            
            ids = createTab(tab_name, user, workspace)
            
            return HttpResponse(json_encode(ids), mimetype='application/json; charset=UTF-8')

        except Exception, e:
            transaction.rollback()
            msg = _("tab cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 15
0
    def update(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        if not request.PUT.has_key('igadgets'):
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        #TODO we can make this with deserializers (simplejson)
        received_json = request.PUT['igadgets']

        try:
            tab = Tab.objects.get(workspace__user=user,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)
            received_data = eval(received_json)
            igadgets = received_data.get('iGadgets')
            for igadget in igadgets:
                UpdateIGadget(igadget, user, tab)
            transaction.commit()
            return HttpResponse('ok')
        except Tab.DoesNotExist:
            msg = _('refered tab %(tab_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadgets cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 16
0
    def create(self, request):
        user = get_user_authentication(request)

        if not request.POST.has_key('workspace'):
            return HttpResponseBadRequest(get_xml_error(_("workspace JSON expected")), mimetype='application/xml; charset=UTF-8')

        #TODO we can make this with deserializers (simplejson)
        received_json = request.POST['workspace']

        try:
            ts = simplejson.loads(received_json)
            
            if not ts.has_key('name'):
                raise Exception(_('Malformed workspace JSON: expecting workspace uri.'))
            
            workspace_name = ts.get('name')

            ids = createWorkSpace (workspace_name, user)          
            
            workspaces = get_list_or_404(WorkSpace, users__id=user.id, pk=ids['workspace']['id'])
            data = serializers.serialize('python', workspaces, ensure_ascii=False)
            
            
            concept_data = {}
            concept_data['user'] = user
            workspace_data = get_global_workspace_data(data[0], workspaces[0], concept_data, user)
            
            return HttpResponse(json_encode(workspace_data), mimetype='application/json; charset=UTF-8')
            
        except Exception, e:
            transaction.rollback()
            msg = _("workspace cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 17
0
    def create(self, request, workspace_id):
        if not request.REQUEST.has_key('data'):
            return HttpResponseBadRequest(
                get_xml_error(_("mashup data expected")),
                mimetype='application/xml; charset=UTF-8')

        received_json = request.REQUEST['data']
        try:
            mashup = simplejson.loads(received_json)
            if not mashup.has_key('name'):
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup name.'))
            if not mashup.has_key('vendor'):
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup vendor.'))
            if not mashup.has_key('version'):
                raise Exception(
                    _('Malformed mashup JSON: expecting mashup version.'))

        except Exception, e:
            transaction.rollback()
            msg = _("mashup cannot be published: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 18
0
    def update(self, request, workspace_id, tab_id, igadget_id, var_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'value')

        # Gets value parameter from request
        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("iGadget JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        new_value = received_json

        tab = Tab.objects.get(workspace__users__id=user.id,
                              workspace__pk=workspace_id,
                              pk=tab_id)
        variable = get_object_or_404(Variable,
                                     igadget__tab=tab,
                                     igadget__pk=igadget_id,
                                     vardef__pk=var_id)
        try:
            variable.value = new_value
            variable.save()
        except Exception, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(
                get_xml_error(e), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 19
0
    def create(self, request, user_name=None):
        user = get_user_authentication(request)
        if request.POST.has_key('url'):
            templateURL = request.POST['url']
        else:
            return HttpResponseServerError('<error>Url not specified</error>', mimetype='application/xml; charset=UTF-8')

        ########### Template Parser
        templateParser = None
        
        try:
            # Gadget is created only once
            templateParser = TemplateParser(templateURL)
            gadget_uri = templateParser.getGadgetUri()

            try:
                gadget = Gadget.objects.get(uri=gadget_uri)
            except Gadget.DoesNotExist:
                # Parser creates the gadget. It's made only if the gadget does not exist
                templateParser.parse()
                gadget = templateParser.getGadget()
            
            # A new user has added the gadget in his showcase 
            gadget.users.add(user) 
            transaction.commit()
        except TemplateParseException, e:
            log(e, request)
            transaction.rollback()

            return HttpResponseServerError(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 20
0
    def update(self, request, workspace_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'variables')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("variables JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            variables = eval(received_json)

            igadgetVariables = variables['igadgetVars']
            workSpaceVariables = variables['workspaceVars']

            for wsVar in workSpaceVariables:
                wsVarDAO = WorkSpaceVariable.objects.get(pk=wsVar['id'])

                wsVarDAO.abstract_variable.value = wsVar['value']
                wsVarDAO.abstract_variable.save()

            for igVar in igadgetVariables:
                igVarDAO = Variable.objects.get(pk=igVar['id'])

                igVarDAO.abstract_variable.value = igVar['value']
                igVarDAO.abstract_variable.save()

            return HttpResponse(str('OK'))
        except Exception, e:
            transaction.rollback()
            msg = _("cannot update variables: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 21
0
    def delete(self,request,user_name,vendor,name,version, tag):

        try:
            user = user_authentication(request, user_name)
        except Http403, e:
            msg = _("This tag cannot be deleted: ") + unicode(e)
            log (msg, request)
            return HttpResponseForbidden(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 22
0
 def create(self, request, account_id=None, wallet_id=None):
     # Gets the attached wallet
     try:
         user_wallet = Wallet.objects.get(id=wallet_id)
         account = Account.objects.get(id=account_id)
     except Exception, e:
         log(e, request)
         return HttpResponseServerError(get_xml_error(_("Error getting objects")), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 23
0
    def delete(self,request,user_name,vendor,name,version, tag):

        try:
            user = user_authentication(request, user_name)
	except Http403, e:
            msg = _("This tag cannot be deleted: ") + unicode(e)
            log (msg, request)
            return HttpResponseForbidden(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 24
0
 def create(self, request, account_id=None, wallet_id=None):
     # Gets the attached wallet
     try:
         user_wallet = Wallet.objects.get(id=wallet_id)
         account = Account.objects.get(id=account_id)
     except Exception, e:
         log(e, request)
         return HttpResponseServerError(get_xml_error(_("Error getting objects")), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 25
0
    def read(self, request, username, vendor, name, version):
        # Get info deployment
        info = InfoDeployment(request)

        try:
            user_authentication(request, request.user.username)
        except Http403, e:
            msg = _("This gadget could not be exported") + unicode(e)
            log(msg, request)
            return HttpResponseForbidden(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 26
0
 def read(self, request):
     user = get_user_authentication(request)
     
     data_list = {}
     try:
         workspaces = WorkSpace.objects.filter(users__id=user.id)
         if workspaces.count()==0:
             createWorkSpace('MyWorkSpace', user)
             
             workspaces = WorkSpace.objects.filter(users__id=user.id)
     except Exception, e:
         log(e, request)
         return HttpResponseBadRequest(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 27
0
    def update(self, request, user_name, vendor, name, version):
        user = user_authentication(request, user_name)
        gadget = get_object_or_404(Gadget, user=user, vendor=vendor, name=name, version=version)

        xhtml = gadget.xhtml;

        try:
            xhtml.code = download_http_content(xhtml.url)
            xhtml.save()
        except Exception, e:
            msg = _("XHTML code is not accessible")
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg))
Exemplo n.º 28
0
    def update(self, request, user_name, vendor, name, version):
        user = user_authentication(user_name)
        gadget = get_object_or_404(Gadget, user=user, vendor=vendor, name=name, version=version)

        xhtml = gadget.xhtml;

        try:
            urlcleanup()
            xhtml.code = urlopen(xhtml.url).read()
            xhtml.save()
        except Exception, e:
            log(e, 'PUT', 'user/id/gadgets/xhtml', user_name)
            return HttpResponseServerError(_("XHTML code is not accessible"))
Exemplo n.º 29
0
 def read(self, request):
     user = get_user_authentication(request)
     
     data_list = {}
     try:
         workspaces = WorkSpace.objects.filter(users__id=user.id)
         if workspaces.count()==0:
             createWorkSpace('MyWorkSpace', user)
             
             workspaces = WorkSpace.objects.filter(users__id=user.id)
     except Exception, e:
         log(e, request)
         return HttpResponseBadRequest(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 30
0
    def create(self, request):
        # Deployment Info
        info = InfoDeployment(request)

        user_action = True
        if 'user_action' in request.POST:
            user_action = request.POST['user_action'] == '1'

        try:
            user = user_authentication(request, request.user.username)
        except Http403, e:
            msg = _("This gadget cannot be created") + unicode(e)
            log(msg, request)
            return HttpResponseForbidden(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 31
0
    def create(self,request, user_name):
	
        template_uri = request.__getitem__('template_uri')
        templateParser = None

	try:
            templateParser = TemplateParser(template_uri, user_name)

            templateParser.parse()
            transaction.commit()
        except IntegrityError, e:
            # Gadget already exists. Rollback transaction
            transaction.rollback()
            log(e, 'POST', 'user/id/resources', user_name)
	    return HttpResponseServerError(get_xml_error(str(sys.exc_info()[1])),mimetype='text/xml; charset=UTF-8')
Exemplo n.º 32
0
    def update(self, request, vendor, name, version, user_name=None):
        user = user_authentication(request, user_name)
        gadget = get_object_or_404(Gadget, users=user, vendor=vendor, name=name, version=version)

        xhtml = gadget.xhtml;

        try:
            xhtml.code = download_http_content(xhtml.url)
            xhtml.save()
        except Exception:
            msg = _("XHTML code is not accessible")
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg))
        
        return HttpResponse('ok')
Exemplo n.º 33
0
    def create(self,request, user_name):

        user = user_authentication(request, user_name)

        template_uri = request.POST.__getitem__('template_uri')
        templateParser = None

        try:
            templateParser = TemplateParser(template_uri, user)
            templateParser.parse()
            transaction.commit()
        except IntegrityError, e:
            # Gadget already exists. Rollback transaction
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(get_xml_error(unicode(sys.exc_info()[1])), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 34
0
class GadgetsCollection(Resource):
    @transaction.commit_manually
    def create(self, request, user_name):

        template_uri = request.__getitem__('template_uri')
        templateParser = None

        try:
            templateParser = TemplateParser(template_uri, user_name)

            templateParser.parse()
            transaction.commit()
        except IntegrityError, e:
            # Gadget already exists. Rollback transaction
            transaction.rollback()
            log(e, 'POST', 'user/id/resources', user_name)
            return HttpResponseServerError(get_xml_error(str(
                sys.exc_info()[1])),
                                           mimetype='text/xml; charset=UTF-8')
        except TemplateParseException, e:
            transaction.rollback()
            log(e, 'POST', 'user/id/resources', user_name)
            return HttpResponseServerError(
                "<error>%s</error>" % e,
                mimetype='application/xml; charset=UTF-8')
Exemplo n.º 35
0
 def read(self, request, workspace_id):
     workspace = get_object_or_404(WorkSpace, id=workspace_id)
     
     user = get_user_authentication(request)
     
     #Checking if user is already linked to workspace
     if (len(workspace.users.filter(id=user.id))>0):
             msg = _("already linked workspace")
             log(msg, request)
             return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
     
     packageLinker = PackageLinker()
     
     packageLinker.link_workspace(workspace, user)
     
     return HttpResponse("{'result': 'ok'}", mimetype='application/json; charset=UTF-8')
Exemplo n.º 36
0
    def update(self, request, user_name):
        user = get_user_authentication(request)
        received_json = PUT_parameter(request, 'preferences')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("Platform Preferences JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            preferences_json = simplejson.loads(received_json)
            update_preferences(user, preferences_json)
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("Platform Preferences cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 37
0
class GadgetsCollection(Resource):
    @transaction.commit_manually
    def create(self, request, user_name):

        user = user_authentication(request, user_name)

        template_uri = request.__getitem__('template_uri')
        templateParser = None

        try:
            templateParser = TemplateParser(template_uri, user)

            templateParser.parse()
            transaction.commit()
        except IntegrityError, e:
            # Gadget already exists. Rollback transaction
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(
                get_xml_error(unicode(sys.exc_info()[1])),
                mimetype='application/xml; charset=UTF-8')
        except TemplateParseException, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(
                get_xml_error(unicode(e)),
                mimetype='application/xml; charset=UTF-8')
Exemplo n.º 38
0
class GadgetCollection(Resource):
    def read(self, request, user_name):
        user = user_authentication(user_name)
        gadgets = Gadget.objects.filter(user=user)
        data = serializers.serialize('python', gadgets, ensure_ascii=False)
        data_list = []
        for d in data:
            data_fields = get_gadget_data(d)
            data_list.append(data_fields)
        return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')

    @transaction.commit_manually
    def create(self, request, user_name):
        user = user_authentication(user_name)
        if request.POST.has_key('url'):
            templateURL = request.POST['url']
        else:
            return HttpResponseServerError('<error>Url not specified</error>', mimetype='application/xml; charset=UTF-8')

        ########### Template Parser
        templateParser = None
        
        try:
            templateParser = TemplateParser(templateURL, user)
            templateParser.parse()
            transaction.commit()
        except TemplateParseException, e:
            log(e, 'POST', 'user/id/gadgets', user_name)
            transaction.rollback()

            return HttpResponseServerError(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
        except IntegrityError:
            log(_("Gadget already exists"), 'POST', 'user/id/gadgets', user_name)
            # Gadget already exists. Rollback transaction
            transaction.rollback()
Exemplo n.º 39
0
class PaypalTransactionIPN(Resource):
    """
    Registers a Payment transaction and updates the wallet balance
    """
    def create(self, request, account_id=None, wallet_id=None):
        # Gets the attached wallet
        try:
            user_wallet = Wallet.objects.get(id=wallet_id)
            account = Account.objects.get(id=account_id)
        except Exception, e:
            log(e, request)
            return HttpResponseServerError(get_xml_error(_("Error getting objects")), mimetype='application/xml; charset=UTF-8')


        # Creates the transaction
        try:
            transaction = Transaction()
            transaction.wallet = user_wallet
            transaction.creation_date = datetime.now()
            transaction.transaction_type = 'R'
            transaction.concept = _('Wallet Recharge')
            transaction.amount = Decimal(request.POST.__getitem__("mc_gross"))
            if(request.POST.__getitem__("payment_status")=="Completed"):
                transaction.status = 'C'
            if(request.POST.__getitem__("payment_status")=="Pending"):
                transaction.status = 'P'
            transaction.gadget_pricing = None
            transaction.finish_date = transaction.creation_date
            transaction.payment_account = account
            transaction.save()
        except Exception, e:
            log(e, request)
            return HttpResponseServerError(get_xml_error(_("Error creating transaction")), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 40
0
class GadgetVotesCollection(Resource):
    def create(self, request, user_name, vendor, name, version):

        try:
            format = request.GET.__getitem__('format')
        except:
            format = 'default'

        user = user_authentication(request, user_name)

        # Get the vote from the request
        vote = request.POST.__getitem__('vote')

        # Get the gadget's id for those vendor, name and version
        gadget = get_object_or_404(GadgetResource,
                                   short_name=name,
                                   vendor=vendor,
                                   version=version)

        # Insert the vote for these resource and user in the database
        try:
            UserVote.objects.create(vote=vote, idUser=user, idResource=gadget)
        except Exception, ex:
            log(ex, request)
            return HttpResponseServerError(
                get_xml_error(unicode(ex)),
                mimetype='application/xml; charset=UTF-8')

        try:
            update_popularity(gadget)
        except Exception, ex:
            log(ex, request)
            return HttpResponseServerError(
                get_xml_error(unicode(ex)),
                mimetype='application/xml; charset=UTF-8')
Exemplo n.º 41
0
    def create(self, request, user_name, vendor, name, version):

        try:
            format = request.POST.__getitem__('format')
        except:
            format = 'default'

        user = user_authentication(request, user_name)

        # Get the xml containing the tags from the request
        tags_xml = request.POST.__getitem__('tags_xml')

        tags_xml = tags_xml.encode("utf-8")
        # Parse the xml containing the tags
        parser = make_parser()
        handler = TagsXMLHandler()

        # Tell the parser to use our handler
        parser.setContentHandler(handler)

        # Parse the input
        try:
            from StringIO import StringIO
        except ImportError:
            from cStringIO import StringIO

        inpsrc = InputSource()
        inpsrc.setByteStream(StringIO(tags_xml))
        parser.parse(inpsrc)

        # Get the gadget's id for those vendor, name and version
        gadget = get_object_or_404(GadgetResource,
                                   short_name=name,
                                   vendor=vendor,
                                   version=version)

        # Insert the tags for these resource and user in the database
        for e in handler._tags:
            try:
                UserTag.objects.get_or_create(tag=e,
                                              idUser=user,
                                              idResource=gadget)
            except Exception, ex:
                log(ex, request)
                return HttpResponseServerError(
                    get_xml_error(unicode(ex)),
                    mimetype='application/xml; charset=UTF-8')
Exemplo n.º 42
0
    def create(self, request, user_name, vendor, name, version):
        format = request.GET.get('format', 'default')

        user = user_authentication(request, user_name)

        # Get the vote from the request
        vote = request.POST.get('vote')

        resource = get_object_or_404(CatalogueResource, short_name=name, vendor=vendor, version=version)

        # Insert the vote for these resource and user in the database
        try:
            UserVote.objects.create(vote=vote, idUser=user, idResource=resource)
        except Exception, ex:
            log(ex, request)
            return HttpResponseServerError(get_xml_error(unicode(ex)),
                                           mimetype='application/xml; charset=UTF-8')
Exemplo n.º 43
0
    def __call__(self, request, *args, **kwargs):      
        try:
            return self.dispatch(request, self, *args, **kwargs)
        except HttpMethodNotAllowed:
            response = HttpResponseNotAllowed(self.permitted_methods)
            response.mimetype = self.mimetype
            return response
        except:
            exc_info = sys.exc_info()
            msg_array = traceback.format_exception(exc_info[0], exc_info[1], exc_info[2])
            msg = ""
            for line in msg_array:
              msg += line
            log(msg, request)

            msg = "[" + unicode(exc_info[0]) + "] " + unicode(exc_info[1])
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 44
0
 def delete(self, request, workspace_id):
     user = get_user_authentication(request)
     
     workspaces = WorkSpace.objects.filter(users__id=user.id).exclude(pk=workspace_id)
     
     if workspaces.count()==0:
         msg = _("workspace cannot be deleted")
         log(msg, request)
         return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
         
     # Gets Igadget, if it does not exist, a http 404 error is returned
     workspace = get_object_or_404(WorkSpace, users__id=user.id, pk=workspace_id)
     
     workspace.delete()
     #set a new active workspace (first workspace by default)
     activeWorkspace=workspaces[0]
     setActiveWorkspace(user, activeWorkspace)
     return HttpResponse('ok')
Exemplo n.º 45
0
    def create(self, request, user_name):
        user = user_authentication(user_name)
        if request.POST.has_key('url'):
            templateURL = request.POST['url']
        else:
            return HttpResponseServerError('<error>Url not specified</error>', mimetype='application/xml; charset=UTF-8')

        ########### Template Parser
        templateParser = None
        
        try:
            templateParser = TemplateParser(templateURL, user)
            templateParser.parse()
            transaction.commit()
        except TemplateParseException, e:
            log(e, 'POST', 'user/id/gadgets', user_name)
            transaction.rollback()
            return HttpResponseServerError("<error>%s</error>" % e, mimetype='application/xml; charset=UTF-8')
Exemplo n.º 46
0
    def read(self, request, workspace_id):
        workspace = get_object_or_404(WorkSpace, id=workspace_id)

        user = get_user_authentication(request)

        #Checking if user is already linked to workspace
        if (len(workspace.users.filter(id=user.id)) > 0):
            msg = _("already linked workspace")
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')

        packageLinker = PackageLinker()

        packageLinker.link_workspace(workspace, user)

        return HttpResponse("{'result': 'ok'}",
                            mimetype='application/json; charset=UTF-8')
Exemplo n.º 47
0
 def delete(self, request, workspace_id):
     user = get_user_authentication(request)
     
     workspaces = WorkSpace.objects.filter(users__id=user.id).exclude(pk=workspace_id)
     
     if workspaces.count()==0:
         msg = _("workspace cannot be deleted")
         log(msg, request)
         return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
         
     # Gets Igadget, if it does not exist, a http 404 error is returned
     workspace = get_object_or_404(WorkSpace, users__id=user.id, pk=workspace_id)
     
     workspace.delete()
     #set a new active workspace (first workspace by default)
     activeWorkspace=workspaces[0]
     setActiveWorkspace(user, activeWorkspace)
     return HttpResponse('ok')
Exemplo n.º 48
0
    def update(self, request, user_name):
        user = get_user_authentication(request)
        received_json = PUT_parameter(request, 'preferences')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("Platform Preferences JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            preferences_json = simplejson.loads(received_json)
            update_preferences(user, preferences_json)
            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("Platform Preferences cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 49
0
    def create(self, request, user_name):
        user = user_authentication(user_name)
        if request.POST.has_key('url'):
            templateURL = request.POST['url']
        else:
            return HttpResponseServerError('<error>Url not specified</error>', mimetype='application/xml; charset=UTF-8')

        ########### Template Parser
        templateParser = None
        
        try:
            templateParser = TemplateParser(templateURL, user)
            templateParser.parse()
            transaction.commit()
        except TemplateParseException, e:
            log(e, 'POST', 'user/id/gadgets', user_name)
            transaction.rollback()

            return HttpResponseServerError(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 50
0
    def create(self, request, workspace_id):
        if not request.REQUEST.has_key('data'):
            return HttpResponseBadRequest(get_xml_error(_("mashup data expected")), mimetype='application/xml; charset=UTF-8')
            
        received_json = request.REQUEST['data']
        try:
            mashup = simplejson.loads(received_json) 
            if not mashup.has_key('name'):
            	raise Exception(_('Malformed mashup JSON: expecting mashup name.'))
            if not mashup.has_key('vendor'):
                raise Exception(_('Malformed mashup JSON: expecting mashup vendor.'))
            if not mashup.has_key('version'):
                raise Exception(_('Malformed mashup JSON: expecting mashup version.'))

        except Exception, e:
            transaction.rollback()
            msg = _("mashup cannot be published: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 51
0
    def update(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        received_json = PUT_parameter(request, 'tab')

        if not received_json:
            return HttpResponseBadRequest(
                get_xml_error(_("tab JSON expected")),
                mimetype='application/xml; charset=UTF-8')

        try:
            t = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id,
                                  workspace__pk=workspace_id,
                                  pk=tab_id)

            if t.has_key('visible'):
                visible = t.get('visible')
                if (visible == 'true'):
                    #Only one visible tab
                    setVisibleTab(user, workspace_id, tab)
                else:
                    tab.visible = False

            if t.has_key('name'):
                tab.name = t.get('name')

            if t.has_key('locked'):
                if t.get('locked') == 'true':
                    tab.locked = True
                else:
                    tab.locked = False

            tab.save()

            return HttpResponse('ok')
        except Exception, e:
            transaction.rollback()
            msg = _("tab cannot be updated: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(
                get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 52
0
 def update(self, request, workspace_id, tab_id, igadget_id, var_id):
     user = get_user_authentication(request)
     
     received_json = PUT_parameter(request, 'value')
     
     # Gets value parameter from request
     if not received_json:
         return HttpResponseBadRequest(get_xml_error(_("iGadget JSON expected")), mimetype='application/xml; charset=UTF-8')
     
     new_value = received_json
     
     tab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=workspace_id, pk=tab_id) 
     variable = get_object_or_404(Variable, igadget__tab=tab, igadget__pk=igadget_id, vardef__pk=var_id)
     try:
         variable.value = new_value
         variable.save()
     except Exception, e:
         transaction.rollback()
         log(e, request)
         return HttpResponseServerError(get_xml_error(e), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 53
0
    def update(self, request, user_name, igadget_id, var_name, screen_id=None):
        user = user_authentication(request, user_name)
        
        # Gets value parameter from request
        if not request.PUT.has_key('value'):
            return HttpResponseBadRequest(get_xml_error(_("iGadget JSON expected")), mimetype='application/xml; charset=UTF-8')
        new_value = request.PUT['value']
        
        #TODO by default. Remove in final release
        if not screen_id:
            screen_id = 1

        screen = Screen.objects.get(user=user, code=screen_id)
        variable = get_object_or_404(Variable, igadget__screen=screen, igadget__code=igadget_id, vardef__name=var_name)
        try:
            variable.value = new_value
            variable.save()
	except Exception, e:
            transaction.rollback()
            log(e, request)
            return HttpResponseServerError(get_xml_error(e), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 54
0
    def create(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)

        if not request.POST.has_key('igadget'):
            return HttpResponseBadRequest(get_xml_error(_("iGadget JSON expected")), mimetype='application/xml; charset=UTF-8')

        try:
            received_json = request.POST['igadget']
            igadget = simplejson.loads(received_json)
            tab = Tab.objects.get(workspace__users__id=user.id, workspace__pk=workspace_id, pk=tab_id) 
            ids = SaveIGadget(igadget, user, tab)
            return HttpResponse(json_encode(ids), mimetype='application/json; charset=UTF-8')
        except WorkSpace.DoesNotExist:
            msg = _('referred workspace %(workspace_id)s does not exist.')
            log(msg, request)
            return HttpResponseBadRequest(get_xml_error(msg))
        except Exception, e:
            transaction.rollback()
            msg = _("iGadget cannot be created: ") + unicode(e)
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 55
0
    def create(self,request, user_name, vendor, name, version):

        try:
            format = request.__getitem__('format')
        except:
            format = 'default'

        user = user_authentication(request, user_name)

        # Get the vote from the request
        vote = request.__getitem__('vote')

        # Get the gadget's id for those vendor, name and version
        gadget = get_object_or_404(GadgetResource, short_name=name,vendor=vendor,version=version)

        # Insert the vote for these resource and user in the database
        try:
            UserVote.objects.create(vote=vote, idUser=user, idResource=gadget)
        except Exception, ex:
            log (ex, request)
            return HttpResponseServerError(get_xml_error(unicode(ex)), mimetype='application/xml; charset=UTF-8')
Exemplo n.º 56
0
    def delete(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)
        
        tabs = Tab.objects.filter(workspace__pk=workspace_id).exclude(pk=tab_id)
        
        if tabs.count()==0:
            msg = _("tab cannot be deleted")
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')

        # Gets Igadget, if it does not exist, a http 404 error is returned
        tab = get_object_or_404(Tab, workspace__pk=workspace_id, pk=tab_id)
        
        #Delete WorkSpace variables too!
        deleteTab(tab, user)
        
        #set a new visible tab (first tab by default)
        activeTab=tabs[0]
        setVisibleTab(user, workspace_id, activeTab)

        return HttpResponse('ok')
Exemplo n.º 57
0
    def delete(self, request, workspace_id, tab_id):
        user = get_user_authentication(request)
        
        tabs = Tab.objects.filter(workspace__pk=workspace_id).exclude(pk=tab_id)
        
        if tabs.count()==0:
            msg = _("tab cannot be deleted")
            log(msg, request)
            return HttpResponseServerError(get_xml_error(msg), mimetype='application/xml; charset=UTF-8')

        # Gets Igadget, if it does not exist, a http 404 error is returned
        tab = get_object_or_404(Tab, workspace__pk=workspace_id, pk=tab_id)
        
        #Delete WorkSpace variables too!
        deleteTab(tab, user)
        
        #set a new visible tab (first tab by default)
        activeTab=tabs[0]
        setVisibleTab(user, workspace_id, activeTab)

        return HttpResponse('ok')