Example #1
0
    def update(self, instance, validated_data):
        if 'file' in validated_data:
            file = validated_data.pop('file')
            media = AbMedias.objects.filter(
                mediable_type='App\\Advertisements', mediable_id=instance.id)
            if media.exists():
                media.first()._delete_file()
                media.first().delete()

            AbMedias(mediable_type='App\\Advertisements',
                     mediable_id=instance.id,
                     path='Advertisements',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()
        else:
            media = AbMedias.objects.filter(
                mediable_type='App\\Advertisements', mediable_id=instance.id)
            if media.exists():
                media.first()._delete_file()
                media.first().delete()

        return super(AdvertisementsSerializer,
                     self).update(instance, validated_data)
Example #2
0
    def update(self, instance, validated_data):
        if 'file' in validated_data:
            file = validated_data.pop('file')

            # delete old one
            media = AbMedias.objects.filter(mediable_type='App\\Category',
                                            mediable_id=instance.id)
            if media.exists():
                media.first()._delete_file()
                media.first().delete()

            AbMedias(mediable_type='App\\Category',
                     mediable_id=instance.id,
                     path='Category',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()
        else:
            media = AbMedias.objects.filter(mediable_type='App\\Category',
                                            mediable_id=instance.id)
            if media.exists():
                media.first()._delete_file()
                media.first().delete()

        instance.description = validated_data.get('description',
                                                  instance.description)
        instance.name = validated_data.get('name', instance.name)
        instance.is_active = validated_data.get('is_active',
                                                instance.is_active)
        instance.save()
        return instance
Example #3
0
 def create(self, validated_data):
     if 'file' in validated_data:
         file = validated_data.pop('file')
         seos = super(SeoSerializer, self).create(validated_data)
         AbMedias(mediable_type='App\\Seo',
                  mediable_id=seos.id,
                  path='Seo',
                  original_file_name=file,
                  is_active=1,
                  accessibility=1,
                  is_featured=0).save()
     else:
         seos = super(SeoSerializer, self).create(validated_data)
     return seos
Example #4
0
 def create(self, validated_data):
     if 'file' in validated_data:
         file = validated_data.pop('file')
         company = super(CompanySerializer, self).create(validated_data)
         AbMedias(mediable_type='App\\Company',
                  mediable_id=company.id,
                  path='Company',
                  original_file_name=file,
                  is_active=1,
                  accessibility=1,
                  is_featured=0).save()
     else:
         company = super(CompanySerializer, self).create(validated_data)
     return company
Example #5
0
 def create(self, validated_data):
     if 'file' in validated_data:
         file = validated_data.pop('file')
         advertisements = super(AdvertisementsSerializer,
                                self).create(validated_data)
         AbMedias(mediable_type='App\\Advertisements',
                  mediable_id=advertisements.id,
                  path='Advertisements',
                  original_file_name=file,
                  is_active=1,
                  accessibility=1,
                  is_featured=0).save()
     else:
         advertisements = super(AdvertisementsSerializer,
                                self).create(validated_data)
     return advertisements
Example #6
0
    def create(self, validated_data):
        if 'file' in validated_data:
            file = validated_data.pop('file')
            category = AbCategories.objects.create(**validated_data)
            AbMedias(mediable_type='App\\Category',
                     mediable_id=category.id,
                     path='Category',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()

        else:
            category = AbCategories.objects.create(**validated_data)

        return category
Example #7
0
 def create(self, validated_data):
     if 'file' in validated_data:
         file = validated_data.pop('file')
         type = super(TypesSerializer, self).create(validated_data)
         AbMedias(
             mediable_type='App\\Type',
             mediable_id=type.id,
             path='Type',
             original_file_name=file,
             is_active=1,
             accessibility=1,
             is_featured=0
         ).save()
     else:
         type = super(TypesSerializer, self).create(validated_data)
     return type
Example #8
0
 def create(self, validated_data):
     if 'file' in validated_data:
         file = validated_data.pop('file')
         manufacturer = super(ManufacturersSerializer, self).create(validated_data)
         AbMedias(
             mediable_type='App\\Manufacturer',
             mediable_id=manufacturer.id,
             path='Manufacturer',
             original_file_name=file,
             is_active=1,
             accessibility=1,
             is_featured=0
         ).save()
     else:
         manufacturer = super(ManufacturersSerializer, self).create(validated_data)
     return manufacturer
Example #9
0
    def create(self, validated_data):
        validated_data['creator'] = self.context['request'].user
        if 'file' in validated_data:
            file = validated_data.pop('file')
            contact = super(ContactSerializer, self).create(validated_data)
            AbMedias(mediable_type='App\\Contact',
                     mediable_id=contact.id,
                     path='Contact',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()

        else:
            contact = super(ContactSerializer, self).create(validated_data)

        return contact
Example #10
0
    def create(self, validated_data):
        customs_datas = validated_data.pop('custom')
        file = None
        if 'file' in validated_data:
            file = validated_data.pop('file')
        plans = AbPlans.objects.create(**validated_data)
        for customs_data in customs_datas:
            AbCustom.objects.create(plan=plans, **customs_data)

        if file is not None:
            # plans = super(PlansSerializer, self).create(validated_data)
            AbMedias(mediable_type='App\\Plans',
                     mediable_id=plans.id,
                     path='Plans',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()
        return plans
Example #11
0
    def update(self, instance, validated_data):
        customs_data = validated_data.pop('custom')
        customs_dict = dict((i.id, i) for i in instance.custom.all())
        for custom in customs_data:
            if 'id' in custom:
                custom_obj = customs_dict.pop(custom['id'])
                custom_obj.label = custom.get('label', custom_obj.label)
                custom_obj.value = custom.get('value', custom_obj.value)
                custom_obj.save()
            else:
                AbCustom.objects.create(plan=instance, **custom)

        # delete remaining elements because they're not present in my update call
        if len(customs_dict) > 0:
            for custom in customs_dict.values():
                custom.delete()

        if 'file' in validated_data:
            file = validated_data.pop('file')
            media = AbMedias.objects.filter(mediable_type='App\\Plans',
                                            mediable_id=instance.id)
            if media.exists():
                media.first()._delete_file()
                media.first().delete()
            AbMedias(mediable_type='App\\Plans',
                     mediable_id=instance.id,
                     path='Plans',
                     original_file_name=file,
                     is_active=1,
                     accessibility=1,
                     is_featured=0).save()
        instance.title = validated_data.get('title', instance.title)
        instance.sub_title = validated_data.get('sub_title',
                                                instance.sub_title)
        instance.price_label = validated_data.get('price_label',
                                                  instance.price_label)
        instance.price = validated_data.get('price', instance.price)
        instance.discount = validated_data.get('discount', instance.discount)
        instance.button_label = validated_data.get('button_label',
                                                   instance.button_label)
        instance.aircraft_label = validated_data.get('aircraft_label',
                                                     instance.aircraft_label)
        instance.aircraft_value = validated_data.get('aircraft_value',
                                                     instance.aircraft_value)
        instance.engine_label = validated_data.get('engine_label',
                                                   instance.engine_label)
        instance.engine_value = validated_data.get('engine_value',
                                                   instance.engine_value)
        instance.apu_label = validated_data.get('apu_label',
                                                instance.apu_label)
        instance.apu_value = validated_data.get('apu_value',
                                                instance.apu_value)
        instance.wanted_label = validated_data.get('wanted_label',
                                                   instance.wanted_label)
        instance.wanted_value = validated_data.get('wanted_value',
                                                   instance.wanted_value)
        instance.parts_label = validated_data.get('parts_label',
                                                  instance.parts_label)
        instance.parts_value = validated_data.get('parts_value',
                                                  instance.parts_value)
        instance.is_active = validated_data.get('is_active',
                                                instance.is_active)
        instance.save()
        return instance