Esempio n. 1
0
    def update(self, request, user_name, concept_name):
        user_authentication(request, user_name)

        received_json = PUT_parameter(request, 'json')

        if not received_json:
            return HttpResponseBadRequest(get_xml_error(_("JSON parameter not specified")))

        try:
            received_data = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(get_xml_error(_("Expecting data in JSON format.")))

        for received_concept in received_data:
            concept = None
            try:
                concept = Concept.objects.get(concept=concept_name)
                concept.adaptor = received_concept['adaptor']
                concept.save()

            except Concept.DoesNotExist:
                return HttpResponseBadRequest(get_xml_error(_("Concept does not exist. You must use POST HTTP method in this case")))

            cname = ConceptName(name=received_concept['name'], concept=concept)
            cname.save()

        return HttpResponse('ok')
Esempio n. 2
0
    def create(self, request, user_name):
        user_authentication(request, user_name)

        if 'json' in request.POST:
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(get_xml_error(_("JSON parameter not specified")))

        try:
            received_data = simplejson.loads(received_json)
        except:
            return HttpResponseBadRequest(get_xml_error(_("Expecting data in JSON format.")))

        for received_concept in received_data['concepts']:
            concept = None
            try:
                concept = Concept.objects.get(concept=received_concept['concept'])
                if not concept.adaptor == received_concept['adaptor']:
                    return HttpResponseBadRequest(get_xml_error(_(u'Attempted update. You must use PUT HTTP method in this case')))

            except Concept.DoesNotExist:
                concept = Concept(concept=received_concept['concept'], adaptor=received_concept['adaptor'])
                concept.save()

            try:
                #Checks if concept name exits in database
                ConceptName.objects.get(name=received_concept['name'], concept=concept)

            except ConceptName.DoesNotExist:
                cname = ConceptName(name=received_concept['name'], concept=concept)
                cname.save()

        return HttpResponse('ok')
Esempio n. 3
0
 def read(self, request, user_name=None):
     user_authentication(request, user_name)
     try:
         request.POST['url']
     except KeyError:
         return HttpResponseServerError('<error>Url not specified</error>',
                                        mimetype='application/xml; charset=UTF-8')
Esempio n. 4
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')
Esempio n. 5
0
 def read(self, request, user_name, concept_name):
     user = user_authentication(user_name)
     
     data_res = {}
     
     if concept_name == 'username':
         user = user_authentication(user_name)
         data_res ['username'] = user_name  
     else:
         raise Http404;
     
     return HttpResponse(json_encode(data_res), mimetype='application/json; charset=UTF-8')
Esempio n. 6
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_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')
Esempio n. 7
0
    def update(self, request, user_name, vendor, name, version):
        user = user_authentication(request, user_name)

        # Get the gadget data from the request
        preferred = PUT_parameter(request, 'preferred')

        if preferred != None:
            # Set all version of this gadget as no preferred
            old_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor, gadget__short_name=name, user=user, preferred_by=True)
            for old_version in old_preferred_versions:
                old_version.preferred_by = False
                old_version.save()

            new_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor, gadget__short_name=name, gadget__version=version, user=user)

            userRelated = None
            if len(new_preferred_versions) == 0:
                resource = get_object_or_404(GadgetResource, short_name=name,
                                             vendor=vendor, version=version)
                userRelated = UserRelatedToGadgetResource()
                userRelated.gadget = resource
                userRelated.user = user
                userRelated.added_by = False
            else:
                userRelated = new_preferred_versions[0]

            userRelated.preferred_by = True
            userRelated.save()

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

            return get_resource_response([resource], 'json', 1, user)
Esempio n. 8
0
    def read(self, request, user_name, pag=0, offset=0):

        user = user_authentication(request, user_name)
        isIE = is_ie(request)

        format = request.GET.get('format', 'default')
        orderby = request.GET.get('orderby', '-creation_date')
        scope = request.GET.get('scope', 'all')

        #paginate
        a = int(pag)
        b = int(offset)

        # Get all the gadgets in the catalogue
        gadgetlist = get_resources_that_must_be_shown(user, isIE).order_by(orderby)
        gadgetlist = filter_gadgets_by_organization(user, gadgetlist, user.groups.all(), scope)
        items = len(gadgetlist)

        if not(a == 0 or b == 0):
        # Get the requested gadgets
            c = ((a - 1) * b)
            d = (b * a)

            if a == 1:
                c = 0
            gadgetlist = gadgetlist[c:d]

        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 9
0
    def read(self, request, user_name, pag=0, offset=0):
        user = user_authentication(request, user_name)

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

        try:
            orderby = request.GET.__getitem__('orderby')
        except:
            orderby = '-creation_date'

        #paginate
        a= int(pag)
        b= int(offset)

        items = get_resources_that_must_be_shown(user=user).count()

        # Get all the gadgets in the catalogue
        if a == 0 or b == 0:
            gadgetlist = get_resources_that_must_be_shown(user=user).order_by(orderby)
        # Get the requested gadgets
        else:
            c=((a-1)*b)
            d= (b*a)

            if a==1:
                c=0
            gadgetlist = get_resources_that_must_be_shown(user=user).order_by(orderby)[c:d]

        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 10
0
 def read(self, request, user_name):
     user = user_authentication(user_name)
     concepts = Concept.objects.all()
     data = serializers.serialize('python', concepts, ensure_ascii=False)
     data_list = {} 
     data_list ['concepts'] = [get_concept_data(d) for d in  data]
     return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')
Esempio n. 11
0
 def read(self, request, user_name, concept_name):
     user = user_authentication(request, user_name)
     concepts = get_list_or_404(Concept, concept=concept_name)
     concept_values = {}
     concept_values['user'] = user
     data_list = get_concept_data(concepts, concept_values)
     return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')
Esempio n. 12
0
    def read(self, request, user_name=None):
        user = user_authentication(request, user_name)

        gadgets = Gadget.objects.filter(users=user)

        data_list = [get_gadget_data(gadget) for gadget in gadgets]
        return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')
Esempio n. 13
0
    def create(self,request, user_name, vendor, name, version):
        user = user_authentication(user_name)

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

        # 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:
	        return HttpResponseServerError(get_xml_error(str(sys.exc_info()[1])),mimetype='text/xml; charset=UTF-8')

        response = '<?xml version="1.0" encoding="UTF-8" ?>\n'
	response += get_tags_by_resource(gadget, user)
	return HttpResponse(response,mimetype='text/xml; charset=UTF-8')
Esempio n. 14
0
    def create(self, request, user_name=None):
        user = user_authentication(request, 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:
            # 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:
            transaction.rollback()
            msg = _("Error parsing template!")
            
            raise TracedServerError(e, {'url': templateURL}, request, msg)
Esempio n. 15
0
    def create(self, request, user_name, concept_name):
        user = user_authentication(request, user_name)

        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(get_xml_error(_("JSON parameter not specified")))

        try:
            received_concept = eval(received_json)
        except:
            return HttpResponseBadRequest(get_xml_error(_("Expecting data in JSON format.")))

        concept = None
        try:
            concept = Concept.objects.get(concept=concept_name)
            if not concept.adaptor == received_concept['adaptor']:
                return HttpResponseBadRequest(get_xml_error(_(u'Attempted update. You must use PUT HTTP method in this case')))

        except Concept.DoesNotExist:
            concept = Concept (concept=concept_name, adaptor=received_concept['adaptor'])
            concept.save()

        cname = ConceptName (name=received_concept['name'], concept=concept)
        cname.save()

        return HttpResponse('ok') 
Esempio n. 16
0
 def update(self, request, user_name, vendor, name, version):
     user = user_authentication(request, user_name)
     
     # Get the gadget data from the request
     preferred = PUT_parameter(request, 'preferred')
     
     if preferred != None:
         # Set all version of this gadget as no preferred 
         old_preferred_versions = UserRelatedToGadgetResource.objects.filter( 
             gadget__vendor=vendor, gadget__short_name=name, user=user, preferred_by=True)
         for old_version in old_preferred_versions:
             old_version.preferred_by = False
             old_version.save()
         
         new_preferred_versions = UserRelatedToGadgetResource.objects.filter(gadget__vendor=vendor, gadget__short_name=name, gadget__version=version, user=user)
         
         userRelated = None
         if len(new_preferred_versions) == 0:
             resource = get_object_or_404(GadgetResource, short_name=name,vendor=vendor,version=version)
             userRelated = UserRelatedToGadgetResource ()
             userRelated.gadget = resource;
             userRelated.user = user
             userRelated.added_by = False
         else:
             userRelated = new_preferred_versions[0]
         
         userRelated.preferred_by = True
         userRelated.save()
         
         xml_ok = '<ResponseOK>OK</ResponseOK>'
         return HttpResponse(xml_ok,mimetype='text/xml; charset=UTF-8')
Esempio n. 17
0
    def read(self,request, user_name, pag=0,offset=0):
        
	user = user_authentication(user_name)

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

	#paginate
	a= int(pag)
	b= int(offset)

	items = GadgetResource.objects.count()

        # Get all the gadgets in the catalogue
	if a == 0 or b == 0:
	    gadgetlist = GadgetResource.objects.all()
	# Get the requested gadgets
	else:
	    c=((a-1)*b)
	    d= (b*a)
	
	    if a==1:
	        c=0
            gadgetlist = GadgetResource.objects.all()[c:d]
	
        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 18
0
    def read(self, request, user_name, screen_id=1):
        user = user_authentication(user_name)
        wiring = {}
        
        # IGadgets list
        if not screen_id:
            screen_id=1

        try:
            screen = Screen.objects.get(user=user, code=screen_id)

            igadgets = IGadget.objects.filter(screen=screen)
            
            igadget_data_list = get_wiring_data(igadgets)
            
            wiring['iGadgetList'] = igadget_data_list
        except Screen.DoesNotExist:
            wiring['iGadgetList'] = []
        
        # InOut list
        inouts = InOut.objects.filter(user=user)
        inout_data = serializers.serialize('python', inouts, ensure_ascii=False)
        inout_data_list = [get_inout_data(d) for d in inout_data]
        wiring['inOutList'] = inout_data_list
        
        return HttpResponse(json_encode(wiring), mimetype='application/json; charset=UTF-8')
Esempio n. 19
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:
            url = xhtml.url
            if (url.startswith('http')):
                #Absolute URL
                xhtml.code = download_http_content(url, user=user)
            else:
                #Relative URL
                if (url.startswith('/deployment/gadgets')):
                    #GWT gadget package
                    xhtml.code = get_xhtml_content(url)
                else:
                    #Gadget with relative url and it's not a GWT package
                    url = gadget.get_resource_url(url, request)
                    xhtml.code = download_http_content(url, user=user)

            xhtml.save()
        except Exception, e:
            msg = _("XHTML code is not accessible")

            raise TracedServerError(e, {'vendor': vendor, 'name': name, 'version': version}, request, msg)
Esempio n. 20
0
 def read(self, request, user_name):
     user = user_authentication(request, user_name)
     concepts = Concept.objects.all()
     data_list = {}
     concept_values = {}
     concept_values['user'] = user
     data_list['concepts'] = [get_concept_data(concept, concept_values) for concept in concepts]
     return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')
Esempio 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')
Esempio n. 22
0
 def read(self, request, user_name, concept_name):
     user = user_authentication(request, user_name)
     concepts = get_list_or_404(Concept, concept=concept_name)
     data = serializers.serialize('python', concepts, ensure_ascii=False)
     concept_values = {}
     concept_values['user'] = user
     data_list = get_concept_data(data[0], concept_values)
     return HttpResponse(json_encode(data_list), mimetype='application/json; charset=UTF-8')
Esempio 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')
Esempio n. 24
0
 def read(self, request, user_name=None):
     user = user_authentication(request, user_name)
     gadgets = Gadget.objects.filter(users=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')
Esempio n. 25
0
 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')
Esempio n. 26
0
 def read(self, request, user_name, concept_name):
     user = user_authentication(request, user_name)
     concepts = get_list_or_404(Concept, concept=concept_name)
     data = serializers.serialize('python', concepts, ensure_ascii=False)
     concept_values = {}
     concept_values['user'] = user
     data_list = get_concept_data(data[0], concept_values)
     return HttpResponse(json_encode(data_list),
                         mimetype='application/json; charset=UTF-8')
Esempio n. 27
0
 def delete(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)
     gadget.delete()
     return HttpResponse('ok')
Esempio n. 28
0
    def read(self, request, user_name, criteria, value, pag=0, offset=0):

        user = user_authentication(user_name)

        criterialist = []
        gadgetlist = []

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

        if criteria == 'event':
            value = value.split(' ')
            for e in value:
                criterialist += GadgetWiring.objects.filter(
                    Q(friendcode__icontains=e), Q(wiring='out'))
            criterialist = get_uniquelist(criterialist)
        elif criteria == 'slot':
            value = value.split(' ')
            for e in value:
                criterialist += GadgetWiring.objects.filter(
                    Q(friendcode__icontains=e), Q(wiring='in'))
            criterialist = get_uniquelist(criterialist)

        elif criteria == 'tag':
            value = value.split(' ')
            for e in value:
                criterialist += UserTag.objects.filter(tag__icontains=e)
            criterialist = get_uniquelist(criterialist)

        elif criteria == 'connectSlot':
            #view compat out
            criterialist = GadgetWiring.objects.filter(Q(friendcode=value),
                                                       Q(wiring='out'))

        elif criteria == 'connectEvent':
            #view compat out
            criterialist = GadgetWiring.objects.filter(Q(friendcode=value),
                                                       Q(wiring='in'))

        for b in criterialist:
            gadgetlist += get_list_or_404(GadgetResource, id=b.idResource_id)

        items = len(gadgetlist)
        #paginate
        a = int(pag)
        b = int(offset)
        if a != 0 and b != 0:
            c = ((a - 1) * b)
            d = (b * a)

            if a == 1:
                c = 0
            gadgetlist = gadgetlist[c:d]

        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 29
0
 def read(self, request, user_name, concept_name):
     user = user_authentication(request, user_name)
     
     data_res ={}
     concept_data = {}
     concept_data['user'] = user
     data_res['value'] = get_concept_value(concept_name, concept_data)
     
     return HttpResponse(json_encode(data_res), mimetype='application/json; charset=UTF-8')
Esempio n. 30
0
 def read(self, request, vendor, name, version, user_name=None):
     user = user_authentication(request, user_name)
     gadget = get_object_or_404(Gadget, vendor=vendor, name=name, version=version, users=user)
     code = get_object_or_404(gadget.xhtml, id=gadget.xhtml.id)
     
     content_type = gadget.xhtml.content_type
     if (content_type):
         return HttpResponse(code.code, mimetype='%s; charset=UTF-8' % content_type)
     else:
         return HttpResponse(code.code, mimetype='text/html; charset=UTF-8')
Esempio n. 31
0
 def read(self, request, vendor, name, version, user_name=None):
     user = user_authentication(request, user_name)
     gadget = get_object_or_404(Gadget, vendor=vendor, name=name, version=version, users=user)
     code = get_object_or_404(gadget.xhtml, id=gadget.xhtml.id)
     
     content_type = gadget.xhtml.content_type
     if (content_type):
         return HttpResponse(code.code, mimetype='%s; charset=UTF-8' % content_type)
     else:
         return HttpResponse(code.code, mimetype='text/html; charset=UTF-8')
Esempio n. 32
0
 def read(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)
     template = get_object_or_404(gadget.template, id=gadget.template.id)
     return HttpResponse(json_encode(template),
                         mimetype='application/json; charset=UTF-8')
Esempio n. 33
0
    def read(self, request, user_name, vendor, name, version):
        format = request.GET.get('format', 'default')

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

        # Get the user's id for that user_name
        user = user_authentication(request, user_name)

        return get_vote_response(resource, user, format)
Esempio n. 34
0
    def read(self, request, user_name, concept_name):
        user = user_authentication(request, user_name)

        data_res = {}
        concept_data = {}
        concept_data['user'] = user
        data_res['value'] = get_concept_value(concept_name, concept_data)

        return HttpResponse(json_encode(data_res),
                            mimetype='application/json; charset=UTF-8')
Esempio n. 35
0
    def read(self, request, user_name, vendor, name, version):
        format = request.GET.get('format', 'default')

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

        # Get the user's id for that user_name
        user = user_authentication(request, user_name)

        return get_tag_response(gadget, user, format)
Esempio n. 36
0
    def read(self, request, user_name, value, criteria, pag=0, offset=0):

        user = user_authentication(user_name)

        gadgetlist = []

        value = value.split(' ')

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

        if criteria == 'and':
            gadgetlist = self.__get_gadgetlist__(value)
            gadgetlist = get_uniquelist(gadgetlist, value)

        elif criteria == 'or':
            gadgetlist = self.__get_gadgetlist__(value)
            gadgetlist = get_uniquelist(gadgetlist)

        elif criteria == 'not':
            count = 0
            for e in value:
                # Get a list of elements that doesn't match the given value
                if count == 0:
                    gadgetlist = GadgetResource.objects.exclude(
                        Q(short_name__icontains=e) | Q(vendor__icontains=e)
                        | Q(author__icontains=e) | Q(mail__icontains=e)
                        | Q(description__icontains=e)
                        | Q(version__icontains=e))
                    count = count + 1
                else:
                    gadgetlist = gadgetlist.exclude(
                        Q(short_name__icontains=e) | Q(vendor__icontains=e)
                        | Q(author__icontains=e) | Q(mail__icontains=e)
                        | Q(description__icontains=e)
                        | Q(version__icontains=e))

            gadgetlist = get_uniquelist(gadgetlist)

        items = len(gadgetlist)
        #paginate
        a = int(pag)
        b = int(offset)
        if a != 0 and b != 0:
            c = ((a - 1) * b)
            d = (b * a)

            if a == 1:
                c = 0
            gadgetlist = gadgetlist[c:d]

        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 37
0
 def read(self, request, user_name, vendor, name, version):
     user = user_authentication(request, user_name)
     gadgets = get_list_or_404(Gadget,
                               user=user,
                               vendor=vendor,
                               name=name,
                               version=version)
     data = serializers.serialize('python', gadgets, ensure_ascii=False)
     data_fields = get_gadget_data(data[0])
     return HttpResponse(json_encode(data_fields),
                         mimetype='application/json; charset=UTF-8')
Esempio n. 38
0
    def read(self, request, user_name, criteria, value, pag=0, offset=0):

        user = user_authentication(request, user_name)

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

        try:
            orderby = request.__getitem__('orderby')
        except:
            orderby = '-creation_date'

        gadgetlist = []

        if criteria == 'event':
            value = value.split()
            for e in value:
                gadgetlist += GadgetResource.objects.filter(Q(gadgetwiring__friendcode__icontains = e), Q(gadgetwiring__wiring = 'out'))
		print(gadgetlist)
        elif criteria == 'slot':
            value = value.split()
            for e in value:
                gadgetlist += GadgetResource.objects.filter(Q(gadgetwiring__friendcode__icontains = e), Q(gadgetwiring__wiring = 'in'))

        elif criteria == 'tag':
            value = value.split()
            for e in value:
                gadgetlist += GadgetResource.objects.filter(usertag__tag__icontains = e)

        elif criteria == 'connectSlot':
            #view compat out
            gadgetlist = GadgetResource.objects.filter(Q(gadgetwiring__friendcode = value), Q(gadgetwiring__wiring = 'out'))

        elif criteria == 'connectEvent':
            #view compat out
            gadgetlist = GadgetResource.objects.filter(Q(gadgetwiring__friendcode = value), Q(gadgetwiring__wiring = 'in'))

        gadgetlist = get_uniquelist(gadgetlist)
	gadgetlist = get_sortedlist(gadgetlist, orderby)
        items = len(gadgetlist)
        #paginate
        a= int(pag)
        b= int(offset)
        if a != 0 and b != 0:
            c=((a-1)*b)
            d= (b*a)
        
            if a==1:
                c=0
            gadgetlist = gadgetlist[c:d]

        return get_resource_response(gadgetlist, format, items, user)
Esempio n. 39
0
 def read(self, request, user_name, igadget_id, var_name, screen_id=None):
     user = user_authentication(request, user_name)
     
     #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_list_or_404(Variable, igadget__screen=screen, igadget__code=igadget_id, vardef__name=var_name)
     data = serializers.serialize('python', variable, ensure_ascii=False)
     var_data = get_variable_data(data[0])
     return HttpResponse(json_encode(var_data), mimetype='application/json; charset=UTF-8')
Esempio n. 40
0
    def create(self, request, user_name):
        user = user_authentication(user_name)
        
        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(string_concat(['<error>', _(u'JSON parameter not specified'), '</error>']))

        try:
            received_data = eval(received_json)
        except Exception, e:
            return HttpResponseBadRequest(string_concat(['<error>', _(e), '</error>']))
Esempio n. 41
0
 def read(self, request, user_name, igadget_id, var_name, screen_id=None):
     user = user_authentication(user_name)
     
     #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_list_or_404(Variable, igadget__screen=screen, igadget__code=igadget_id, vardef__name=var_name)
     data = serializers.serialize('python', variable, ensure_ascii=False)
     var_data = get_variable_data(data[0])
     return HttpResponse(json_encode(var_data), mimetype='application/json; charset=UTF-8')
Esempio n. 42
0
 def read(self, request, user_name):
     user = user_authentication(request, user_name)
     concepts = Concept.objects.all()
     data = serializers.serialize('python', concepts, ensure_ascii=False)
     data_list = {}
     concept_values = {}
     concept_values['user'] = user
     data_list['concepts'] = [
         get_concept_data(d, concept_values) for d in data
     ]
     return HttpResponse(json_encode(data_list),
                         mimetype='application/json; charset=UTF-8')
Esempio n. 43
0
 def read(self, request, user_name, igadget_id, screen_id=None):
     user = user_authentication(request, user_name)
     
     #TODO by default. Remove in final release
     if not screen_id:
         screen_id = 1
     
     screen = Screen.objects.get(user=user, code=screen_id)
     variables = Variable.objects.filter(igadget__screen=screen, igadget__code=igadget_id)
     data = serializers.serialize('python', variables, ensure_ascii=False)
     vars_data = [get_variable_data(d) for d in data]
     return HttpResponse(json_encode(vars_data), mimetype='application/json; charset=UTF-8')
Esempio n. 44
0
    def update(self, request, user_name, igadget_id=None, screen_id=None):
        user = user_authentication(user_name)

        # Gets JSON parameter from request
        if not request.PUT.has_key('variables'):
            return HttpResponseBadRequest('<error>iGadget variables JSON expected</error>')

        variables_JSON = request.PUT['variables']

        try:
            received_variables = eval(variables_JSON)
        except Exception, e:
            return HttpResponseBadRequest('<error>%s</error>' % e)
Esempio n. 45
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"))
Esempio n. 46
0
    def read(self, request, user_name, vendor, name, version):
        format = request.GET.get('format', 'default')

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

        # Get the user's id for that user_name
        user = user_authentication(request, user_name)

        return get_vote_response(gadget, user, format)
Esempio n. 47
0
    def update(self, request, user_name, igadget_id=None, screen_id=None):
        user = user_authentication(request, user_name)

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

        variables_JSON = request.PUT['variables']

        try:
            received_variables = eval(variables_JSON)
        except Exception, e:
            return HttpResponseBadRequest(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Esempio n. 48
0
    def create(self, request, user_name):
        user = user_authentication(user_name)

        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(
                "<error>JSON parameter not specified</error>")

        try:
            received_data = eval(received_json)
        except Exception, e:
            return HttpResponseBadRequest('<error>%s</error>' % e)
Esempio n. 49
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:
                tag, created = Tag.objects.get_or_create(name=e)
                UserTag.objects.get_or_create(tag=tag,
                                              idUser=user,
                                              idResource=gadget)
            except Exception, ex:
                transaction.rollback()
                msg = _("Error tagging resource!!")

                raise TracedServerError(ex, {
                    'resource': vendor + name + version,
                    'tags': tags_xml
                }, request, msg)
Esempio n. 50
0
    def create(self, request, user_name):

        user = user_authentication(request, user_name)

        template_uri = request.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()
Esempio n. 51
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')
Esempio n. 52
0
 def read(self, request, user_name, igadget_id, screen_id=None):
     user = user_authentication(request, user_name)
           
     #TODO by default. Remove in final release
     if not screen_id:
         screen_id = 1
     
     data_list = {}
     #Gets current user screen
     screen = Screen.objects.get(user=user, code=screen_id)
     
     igadget = get_list_or_404(IGadget, screen=screen, code=igadget_id)
     data = serializers.serialize('python', igadget, ensure_ascii=False)
     igadget_data = get_igadget_data(data[0])
     return HttpResponse(json_encode(igadget_data), mimetype='application/json; charset=UTF-8')
Esempio n. 53
0
    def read(self, request, user_name=None):
        user = user_authentication(request, user_name)

        #Getting all gadgets of the user
        #Done it against workspaces, not directly against gadgets!
        #Done like this, it's not necessary to keep updated relationships between gadgets and users
        gadgets = get_user_gadgets(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')
Esempio n. 54
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')
Esempio n. 55
0
    def read(self, request, user_name, vendor, name, version):

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

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

        # Get the user's id for that user_name
        user = user_authentication(request, user_name)

        return get_tag_response(gadget, user, format)
Esempio n. 56
0
    def create(self, request, user_name):
        user = user_authentication(user_name)

        if request.POST.has_key('json'):
            received_json = request.POST['json']
        else:
            return HttpResponseBadRequest(
                string_concat([
                    '<error>',
                    _(u'JSON parameter not specified'), '</error>'
                ]))

        try:
            received_data = eval(received_json)
        except Exception, e:
            return HttpResponseBadRequest(
                string_concat(['<error>', _(e), '</error>']))
Esempio n. 57
0
    def update(self, request, user_name, igadget_id, screen_id=None):
        user = user_authentication(user_name)

        #TODO by default. Remove in final release
        if not screen_id:
            screen_id = 1

        if not request.PUT.has_key('igadget'):
            return HttpResponseBadRequest('<error>iGadget JSON expected</error>')

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

        try:
            igadget = eval(received_json)
        except Exception, e:
            return HttpResponseBadRequest('<error>%s</error>' % e)
Esempio n. 58
0
    def update(self, request, user_name, igadget_id, var_name, screen_id=None):
        user = user_authentication(user_name)
        
        # Gets value parameter from request
        if not request.PUT.has_key('value'):
            return HttpResponseBadRequest('<error>iGadget JSON expected</error>')
        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)
        variable.value = new_value
        variable.save()
        return HttpResponse('ok')
Esempio n. 59
0
    def update(self, request, user_name, igadget_id, screen_id=None):
        user = user_authentication(request, user_name)

        #TODO by default. Remove in final release
        if not screen_id:
            screen_id = 1

        if not request.PUT.has_key('igadget'):
            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['igadget']

        try:
            igadget = eval(received_json)
        except Exception, e:
            return HttpResponseBadRequest(get_xml_error(unicode(e)), mimetype='application/xml; charset=UTF-8')
Esempio n. 60
0
    def update(self, request, user_name, vendor, name, version):
        user = user_authentication(request, user_name)

        # Get the gadget data from the request
        preferred = PUT_parameter(request, 'preferred')

        if preferred != None:
            # Set all version of this gadget as no preferred
            old_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor,
                gadget__short_name=name,
                user=user,
                preferred_by=True)
            for old_version in old_preferred_versions:
                old_version.preferred_by = False
                old_version.save()

            new_preferred_versions = UserRelatedToGadgetResource.objects.filter(
                gadget__vendor=vendor,
                gadget__short_name=name,
                gadget__version=version,
                user=user)

            userRelated = None
            if len(new_preferred_versions) == 0:
                resource = get_object_or_404(GadgetResource,
                                             short_name=name,
                                             vendor=vendor,
                                             version=version)
                userRelated = UserRelatedToGadgetResource()
                userRelated.gadget = resource
                userRelated.user = user
                userRelated.added_by = False
            else:
                userRelated = new_preferred_versions[0]

            userRelated.preferred_by = True
            userRelated.save()

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

            return get_resource_response([resource], 'json', 1, user)