How to use get_image_url method in avocado

Best Python code snippet using avocado_python

serializers.py

Source:serializers.py Github

copy

Full Screen

...4from django.conf import settings5class ChildCategoryListSerializer(serializers.ModelSerializer):6 """Подкатегория"""7 image = serializers.SerializerMethodField('get_image_url')8 def get_image_url(self, obj):9 return f'{settings.APP_PATH}{obj.image.url}'10 class Meta:11 model = Category12 exclude = ('description', 'order', 'full_description')13class CategoryListSerializer(serializers.ModelSerializer):14 """Категория (список)"""15 image = serializers.SerializerMethodField('get_image_url')16 child = ChildCategoryListSerializer(many=True, read_only=True)17 def get_image_url(self, obj):18 return f'{settings.APP_PATH}{obj.image.url}'19 class Meta:20 model = Category21 exclude = ('description', 'order', 'full_description')22class BrandListSerializer(serializers.ModelSerializer):23 """Бренд (список)"""24 image = serializers.SerializerMethodField('get_image_url')25 def get_image_url(self, obj):26 return f'{settings.APP_PATH}{obj.image.url}'27 class Meta:28 model = Brand29 exclude = ('description', 'order', 'full_description')30class LabelListSerializer(serializers.ModelSerializer):31 """Список меток"""32 class Meta:33 model = Label34 fields = '__all__'35class ProductListSerializer(serializers.ModelSerializer):36 """Товары (список)"""37 image = serializers.SerializerMethodField('get_image_url')38 def get_image_url(self, obj):39 if obj.image:40 return f'{settings.APP_PATH}{obj.image.url}'41 class Meta:42 model = Product43 fields = ('id', 'title', 'category', 'price', 'old_price', 'image', 'miniature_url', 'rating', 'image_contain',44 'price_comment')45class ProductWithLabelsListSerializer(serializers.ModelSerializer):46 """Товары (список)"""47 image = serializers.SerializerMethodField('get_image_url')48 labels = LabelListSerializer(many=True)49 def get_image_url(self, obj):50 if obj.image:51 return f'{settings.APP_PATH}{obj.image.url}'52 class Meta:53 model = Product54 fields = ('id', 'title', 'category', 'price', 'old_price', 'image', 'rating', 'image_contain', 'labels')55class ImageSerializer(serializers.ModelSerializer):56 """Дополнительные изображения товаров"""57 image = serializers.SerializerMethodField('get_image_url')58 def get_image_url(self, obj):59 return f'{settings.APP_PATH}{obj.image.url}'60 class Meta:61 model = Image62 fields = '__all__'63class ReviewSerializer(serializers.ModelSerializer):64 """ОТзывы к товарам"""65 class Meta:66 model = Review67 exclude = ('pub_date',)68class ChildCategoryDetailSerializer(serializers.ModelSerializer):69 """Категория (детали)"""70 image = serializers.SerializerMethodField('get_image_url')71 products = ProductWithLabelsListSerializer(many=True, read_only=True)72 def get_image_url(self, obj):73 return f'{settings.APP_PATH}{obj.image.url}'74 class Meta:75 model = Category76 fields = '__all__'77class CharacteristicSerializer(serializers.ModelSerializer):78 """Харакетристики товара"""79 type = serializers.SlugRelatedField(slug_field='title', read_only=True, many=False)80 class Meta:81 model = Characteristic82 fields = '__all__'83class CharacteristicTypeSerializer(serializers.ModelSerializer):84 """Типы харакетристик"""85 characteristics = CharacteristicSerializer(many=True, read_only=True)86 class Meta:87 model = CharacteristicType88 exclude = ('category', 'order')89class CategoryDetailSerializer(serializers.ModelSerializer):90 """Категория (детали)"""91 image = serializers.SerializerMethodField('get_image_url')92 child = ChildCategoryDetailSerializer(many=True, read_only=True)93 parent = ChildCategoryListSerializer(many=False, read_only=True)94 characteristic_types = CharacteristicTypeSerializer(many=True, read_only=True)95 def get_image_url(self, obj):96 return f'{settings.APP_PATH}{obj.image.url}'97 class Meta:98 model = Category99 fields = '__all__'100class BrandDetailSerializer(serializers.ModelSerializer):101 """Бренд (детали)"""102 image = serializers.SerializerMethodField('get_image_url')103 def get_image_url(self, obj):104 return f'{settings.APP_PATH}{obj.image.url}'105 class Meta:106 model = Brand107 fields = '__all__'108class LabelDetailSerializer(serializers.ModelSerializer):109 """Метка (детали)"""110 class Meta:111 model = Label112 fields = '__all__'113class VideoSerializer(serializers.ModelSerializer):114 """Дополнительное видео товара"""115 class Meta:116 model = Video117 exclude = ('order', 'product')118class VariationsSerializer(serializers.ModelSerializer):119 """Вариации товара"""120 type = serializers.SlugRelatedField(slug_field='title', read_only=True, many=False)121 class Meta:122 model = Variation123 exclude = ('order',)124class ProductDetailSerializer(serializers.ModelSerializer):125 """Товар (детали)"""126 full_image = serializers.SerializerMethodField('get_full_image_url')127 image = serializers.SerializerMethodField('get_image_url')128 category = CategoryListSerializer(many=False)129 brand = BrandListSerializer(many=False)130 labels = LabelListSerializer(many=True, read_only=True)131 reviews = ReviewSerializer(many=True, read_only=True)132 images = ImageSerializer(many=True, read_only=True)133 videos = VideoSerializer(many=True, read_only=True)134 variations = VariationsSerializer(many=True, read_only=True)135 characteristics = CharacteristicSerializer(many=True, read_only=True)136 def get_image_url(self, obj):137 if obj.image:138 return f'{settings.APP_PATH}{obj.image.url}'139 def get_full_image_url(self, obj):140 if obj.full_image:141 return f'{settings.APP_PATH}{obj.full_image.url}'142 class Meta:143 model = Product144 exclude = ('future', 'hit', 'latest', 'public', 'order', 'pub_date', 'update', 'purchase_price')145class CreateProductSerializer(serializers.ModelSerializer):146 class Meta:147 model = Product,...

Full Screen

Full Screen

caching.py

Source:caching.py Github

copy

Full Screen

1from django.core.cache import get_cache, cache, InvalidCacheBackendError2from django.db.models.signals import pre_save, pre_delete3from django.dispatch import receiver4from thumblr.models import Image5from thumblr.dto import ImageMetadata, ImageUrlSpec6from thumblr.services.query import get_image_by_id7try:8 thumblr_cache = get_cache('thumblr')9except InvalidCacheBackendError:10 thumblr_cache = cache11# pinging on cache12thumblr_cache.get("FOO")13def _get_key(f, *args, **kwargs):14 return "{func_name}:{arg}:{kwarg}".format(15 func_name=f.func_name,16 arg="_".join(map(str, args)),17 kwarg="_".join(map(str, map(lambda item: "{}:{}".format(*item), kwargs.items()))),18 )19def cached(f):20 """Simple cache for functions, cached function **must** get only **positional** arguments, which have unique21 __str__ return value"""22 def cached_f(*args, **kwargs):23 key = _get_key(f, *args, **kwargs)24 val = thumblr_cache.get(key)25 if val:26 return val27 val = f(*args, **kwargs)28 thumblr_cache.set(key, val)29 return val30 cached_f.func_name = f.func_name31 return cached_f32def drop_cache_for(f, *args, **kwargs):33 key = _get_key(f, *args, **kwargs)34 thumblr_cache.delete(key)35@receiver(pre_save, sender=Image)36@receiver(pre_delete, sender=Image)37def __drop_url_cache(sender, instance, *args, **kwargs):38 assert isinstance(instance, Image)39 from thumblr.usecases import get_image_url40 if instance.id:41 old_inst = get_image_by_id(instance.pk)42 dto = ImageMetadata(43 image_file_id=old_inst.id,44 file_name=old_inst.file_name,45 size_slug=old_inst.size.name,46 content_type_id=old_inst.content_type_id,47 object_id=old_inst.object_id,48 )49 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.CDN_URL,)50 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.CDN_URL, one=True)51 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.CDN_URL, one=False)52 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.S3_URL,)53 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.S3_URL, one=True)54 drop_cache_for(get_image_url, dto.extend(image_file_id=None, file_name=None), ImageUrlSpec.S3_URL, one=False)55 drop_cache_for(get_image_url, dto, ImageUrlSpec.CDN_URL,)56 drop_cache_for(get_image_url, dto, ImageUrlSpec.CDN_URL, one=True,)57 drop_cache_for(get_image_url, dto, ImageUrlSpec.CDN_URL, one=False,)58 drop_cache_for(get_image_url, dto, ImageUrlSpec.S3_URL,)59 drop_cache_for(get_image_url, dto, ImageUrlSpec.S3_URL, one=True,)...

Full Screen

Full Screen

serializer.py

Source:serializer.py Github

copy

Full Screen

...9 image_url = serializers.SerializerMethodField('get_image_url')10 class Meta:11 model = FotoPrincipal12 fields = '__all__'13 def get_image_url(self, obj):14 return obj.foto_principal.url15class FotosAcoesSerializer(serializers.ModelSerializer):16 image_url = serializers.SerializerMethodField('get_image_url')17 class Meta:18 model = FotosAcoes19 fields = ('id', 'foto', 'image_url', 'frase')20 def get_image_url(self, obj):21 return obj.foto.url22class TimeVoluntariosSerializer(serializers.ModelSerializer):23 image_url = serializers.SerializerMethodField('get_image_url')24 class Meta:25 model = TimeVoluntarios26 fields = '__all__'27 def get_image_url(self, obj):28 return obj.foto.url29class DepoimentosSerializer(serializers.ModelSerializer):30 image_url = serializers.SerializerMethodField('get_image_url')31 class Meta:32 model = Depoimentos33 fields = '__all__'34 def get_image_url(self, obj):35 return obj.foto.url36class NewsLetterSerializer(serializers.ModelSerializer):37 class Meta:38 model = NewsLetter39 fields = '__all__'40class LocaisTrabalhadosSerializer(serializers.ModelSerializer):41 class Meta:42 model = LocaisTrabalhados43 fields = '__all__'44class NossosDadosSerializer(serializers.ModelSerializer):45 class Meta:46 model = NossosDados...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful