Best Python code snippet using SeleniumBase
serializers.py
Source:serializers.py
...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,...
caching.py
Source:caching.py
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,)...
serializer.py
Source:serializer.py
...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...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!