Beispiel #1
0
 def create(self ,  validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.listings'])
     m = media(**validated_data)
     m.user = u
     m.save()
     return m
Beispiel #2
0
    def update(self, instance, validated_data):
        u = self.context['request'].user
        has_application_permission(
            u, ['app.ecommerce', 'app.ecommerce.configure'])
        instance.title = validated_data.pop('title')
        instance.subtitle = validated_data.pop('subtitle')
        instance.level = validated_data.pop('level')
        instance.state = validated_data.pop('state')
        instance.params = validated_data.pop('params')
        try:
            instance.image = validated_data.pop('image')
        except:
            pass
        if offerBanner.objects.filter(
                active=True).count() >= 5 and not instance.active:
            content = {
                'details':
                'At any time only 5 offers can be active , please deactive an active one'
            }
            raise NotAcceptable(detail=content)
        else:
            instance.active = validated_data.pop('active')
            instance.save()

        return instance
Beispiel #3
0
 def create(self ,  validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.offerings'])
     o = offering(**validated_data)
     o.user = u
     o.service = service.objects.get(user = u)
     o.save()
     return o
Beispiel #4
0
 def create(self ,  validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.configure'])
     u = self.context['request'].user
     b = offerBanner(**validated_data)
     b.user = u
     b.save()
     return b
Beispiel #5
0
 def create(self, validated_data):
     u = self.context['request'].user
     has_application_permission(u,
                                ['app.ecommerce', 'app.ecommerce.listings'])
     m = media(**validated_data)
     m.user = u
     m.save()
     return m
Beispiel #6
0
 def create(self, validated_data):
     u = self.context['request'].user
     has_application_permission(
         u, ['app.ecommerce', 'app.ecommerce.configure'])
     u = self.context['request'].user
     b = offerBanner(**validated_data)
     b.user = u
     b.save()
     return b
Beispiel #7
0
 def create(self, validated_data):
     u = self.context['request'].user
     has_application_permission(
         u, ['app.ecommerce', 'app.ecommerce.offerings'])
     o = offering(**validated_data)
     o.user = u
     o.service = service.objects.get(user=u)
     o.save()
     return o
Beispiel #8
0
 def update(self , instance , validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.orders'])
     status = validated_data['status']
     if (status == 'inProgress' and not instance.status == 'new') or (status == 'complete' and not instance.status == 'inProgress') or \
         (status == 'canceledByVendor' and not instance.status == 'new') or (status == 'canceledByCustomer' and not instance.status == 'new') or status=='new':
         raise ValidationError({'NOT_ACCEPTABLE'})
     instance.status = status
     instance.save()
     return instance
Beispiel #9
0
 def update(self, instance, validated_data):
     u = self.context['request'].user
     has_application_permission(u,
                                ['app.ecommerce', 'app.ecommerce.orders'])
     status = validated_data['status']
     if (status == 'inProgress' and not instance.status == 'new') or (status == 'complete' and not instance.status == 'inProgress') or \
         (status == 'canceledByVendor' and not instance.status == 'new') or (status == 'canceledByCustomer' and not instance.status == 'new') or status=='new':
         raise ValidationError({'NOT_ACCEPTABLE'})
     instance.status = status
     instance.save()
     return instance
Beispiel #10
0
 def create(self , validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.configure'])
     gp = genericProduct()
     gp.productType = genericType.objects.get(pk = self.context['request'].data['productType'])
     gp.name = validated_data.pop('name')
     gp.save()
     for f in self.context['request'].data['fields']:
         gp.fields.add(field.objects.get(pk = f))
     gp.save()
     return gp
Beispiel #11
0
    def update(self , instance , validated_data):
        u = self.context['request'].user
        has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.configure'])

        instance.name = validated_data.pop('name')
        instance.productType = genericType.objects.get(pk = self.context['request'].data['productType'])
        instance.fields.clear()
        instance.save()
        for f in self.context['request'].data['fields']:
            instance.fields.add(field.objects.get(pk = f))
        instance.save()
        return instance
Beispiel #12
0
 def create(self ,  validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.listings'])
     l = listing(**validated_data)
     l.user =  u
     l.save()
     if 'files' in self.context['request'].data:
         for m in self.context['request'].data['files']:
             l.files.add(media.objects.get(pk = m))
     l.parentType = genericProduct.objects.get(pk = self.context['request'].data['parentType'])
     l.save()
     return l
Beispiel #13
0
 def create(self, validated_data):
     u = self.context['request'].user
     has_application_permission(
         u, ['app.ecommerce', 'app.ecommerce.configure'])
     gp = genericProduct()
     gp.productType = genericType.objects.get(
         pk=self.context['request'].data['productType'])
     gp.name = validated_data.pop('name')
     gp.save()
     for f in self.context['request'].data['fields']:
         gp.fields.add(field.objects.get(pk=f))
     gp.save()
     return gp
Beispiel #14
0
 def create(self, validated_data):
     u = self.context['request'].user
     has_application_permission(u,
                                ['app.ecommerce', 'app.ecommerce.listings'])
     l = listing(**validated_data)
     l.user = u
     l.save()
     if 'files' in self.context['request'].data:
         for m in self.context['request'].data['files']:
             l.files.add(media.objects.get(pk=m))
     l.parentType = genericProduct.objects.get(
         pk=self.context['request'].data['parentType'])
     l.save()
     return l
Beispiel #15
0
    def update(self, instance, validated_data):
        u = self.context['request'].user
        has_application_permission(
            u, ['app.ecommerce', 'app.ecommerce.configure'])

        instance.name = validated_data.pop('name')
        instance.productType = genericType.objects.get(
            pk=self.context['request'].data['productType'])
        instance.fields.clear()
        instance.save()
        for f in self.context['request'].data['fields']:
            instance.fields.add(field.objects.get(pk=f))
        instance.save()
        return instance
Beispiel #16
0
 def update(self , instance , validated_data):
     u = self.context['request'].user
     has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.listings'])
     for key in ['title' , 'description' , 'priceModel' , 'category' , 'specifications' , 'source' ]:
         try:
             setattr(instance , key , validated_data[key])
         except:
             pass
     instance.files.clear()
     if 'files' in self.context['request'].data:
         for m in self.context['request'].data['files']:
             instance.files.add(media.objects.get(pk = m))
     instance.save()
     return instance
Beispiel #17
0
 def update(self, instance, validated_data):
     u = self.context['request'].user
     has_application_permission(u,
                                ['app.ecommerce', 'app.ecommerce.listings'])
     for key in [
             'title', 'description', 'priceModel', 'category',
             'specifications', 'source'
     ]:
         try:
             setattr(instance, key, validated_data[key])
         except:
             pass
     instance.files.clear()
     if 'files' in self.context['request'].data:
         for m in self.context['request'].data['files']:
             instance.files.add(media.objects.get(pk=m))
     instance.save()
     return instance
Beispiel #18
0
    def update (self, instance, validated_data):
        u = self.context['request'].user
        has_application_permission(u , ['app.ecommerce' , 'app.ecommerce.configure'])
        instance.title = validated_data.pop('title')
        instance.subtitle = validated_data.pop('subtitle')
        instance.level = validated_data.pop('level')
        instance.state = validated_data.pop('state')
        instance.params = validated_data.pop('params')
        try:
            instance.image = validated_data.pop('image')
        except:
            pass
        if offerBanner.objects.filter(active = True).count() >= 5 and not instance.active:
            content = {'details' : 'At any time only 5 offers can be active , please deactive an active one'};
            raise NotAcceptable(detail=content)
        else:
            instance.active = validated_data.pop('active')
            instance.save()

        return instance
Beispiel #19
0
    def create(self, validated_data):
        u = self.context['request'].user
        has_application_permission(
            u, ['app.ecommerce', 'app.ecommerce.configure'])
        gp = genericProduct(**validated_data)
        gp.productType = genericType.objects.get(
            pk=self.context['request'].data['productType'])

        try:
            gp.visual = self.context['request'].FILES['visual']
        except:
            pass

        gp.save()
        flds = self.context['request'].data['fields']
        if isinstance(flds, str) or isinstance(flds, unicode):
            flds = flds.split(',')
        for f in flds:
            gp.fields.add(field.objects.get(pk=f))
        gp.save()
        return gp
Beispiel #20
0
 def update(self, instance, validated_data):
     u = self.context['request'].user
     has_application_permission(
         u, ['app.ecommerce', 'app.ecommerce.configure'])
     instance.name = validated_data.pop('name')
     instance.minCost = validated_data.pop('minCost')
     instance.productType = genericType.objects.get(
         pk=self.context['request'].data['productType'])
     try:
         instance.visual = self.context['request'].FILES['visual']
     except:
         pass
     instance.fields.clear()
     instance.save()
     flds = self.context['request'].data['fields']
     print flds, type(flds)
     if isinstance(flds, str) or isinstance(flds, unicode):
         flds = flds.split(',')
     print flds
     for f in flds:
         instance.fields.add(field.objects.get(pk=f))
     instance.save()
     return instance