ob-dj-store 0.0.15.4__py3-none-any.whl → 0.0.15.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ob_dj_store/apis/stores/rest/serializers/serializers.py +46 -22
- {ob_dj_store-0.0.15.4.dist-info → ob_dj_store-0.0.15.6.dist-info}/METADATA +1 -1
- {ob_dj_store-0.0.15.4.dist-info → ob_dj_store-0.0.15.6.dist-info}/RECORD +5 -5
- {ob_dj_store-0.0.15.4.dist-info → ob_dj_store-0.0.15.6.dist-info}/WHEEL +1 -1
- {ob_dj_store-0.0.15.4.dist-info → ob_dj_store-0.0.15.6.dist-info}/top_level.txt +0 -0
@@ -9,11 +9,13 @@ from django.conf import settings
|
|
9
9
|
from django.contrib.contenttypes.models import ContentType
|
10
10
|
from django.contrib.gis.geos import Point
|
11
11
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
12
|
+
from django.core.validators import validate_email
|
12
13
|
from django.db import models
|
13
14
|
from django.shortcuts import get_object_or_404
|
14
15
|
from django.utils.module_loading import import_string
|
15
16
|
from django.utils.timezone import localtime, now
|
16
17
|
from django.utils.translation import gettext_lazy as _
|
18
|
+
from phonenumber_field.phonenumber import to_python
|
17
19
|
from rest_framework import serializers
|
18
20
|
|
19
21
|
from config import settings as store_settings
|
@@ -250,6 +252,47 @@ class OrderSerializer(serializers.ModelSerializer):
|
|
250
252
|
{"store": _("Delivery is not supported by this store.")}
|
251
253
|
)
|
252
254
|
|
255
|
+
def _validate_digital_product(self, gift_details, attrs):
|
256
|
+
errors = []
|
257
|
+
for key in settings.DIGITAL_PRODUCTS_REQUIRED_KEYS:
|
258
|
+
if not (key in gift_details.keys() and len(str(gift_details.get(key)))):
|
259
|
+
errors.append({key: "This field should be filled."})
|
260
|
+
if len(errors) > 0:
|
261
|
+
raise serializers.ValidationError(errors)
|
262
|
+
email = gift_details.get("email")
|
263
|
+
phone_number = gift_details.get("phone_number")
|
264
|
+
|
265
|
+
if email and phone_number:
|
266
|
+
raise serializers.ValidationError(
|
267
|
+
_("Both Email and Phone number cannot be provided.")
|
268
|
+
)
|
269
|
+
elif not email and not phone_number:
|
270
|
+
raise serializers.ValidationError(_("Email or Phone number is required."))
|
271
|
+
elif phone_number and not to_python(phone_number).is_valid():
|
272
|
+
raise serializers.ValidationError(_("Invalid Phone number format."))
|
273
|
+
elif email:
|
274
|
+
try:
|
275
|
+
validate_email(email)
|
276
|
+
except ValidationError:
|
277
|
+
raise serializers.ValidationError(_("Invalid Email format."))
|
278
|
+
|
279
|
+
if not pycountry.currencies.get(alpha_3=gift_details["currency"]):
|
280
|
+
raise serializers.ValidationError("Gift currency is not valid")
|
281
|
+
try:
|
282
|
+
product = Product.objects.get(id=gift_details["digital_product"])
|
283
|
+
except ObjectDoesNotExist:
|
284
|
+
raise serializers.ValidationError(_("Digital product does not exist!"))
|
285
|
+
if product.type == Product.ProductTypes.PHYSICAL:
|
286
|
+
raise serializers.ValidationError(
|
287
|
+
_("You must not fill extra infos for physical products.")
|
288
|
+
)
|
289
|
+
|
290
|
+
gift_minimun_amount = store_settings.GIFT_MINIMUM_AMOUNT.get(
|
291
|
+
attrs["store"].currency, 5
|
292
|
+
)
|
293
|
+
if gift_details["price"] <= gift_minimun_amount - 1:
|
294
|
+
raise serializers.ValidationError(_("Gift card amount is not valid!"))
|
295
|
+
|
253
296
|
def validate(self, attrs):
|
254
297
|
user = self.context["request"].user
|
255
298
|
attrs["store"] = self._get_store()
|
@@ -258,28 +301,7 @@ class OrderSerializer(serializers.ModelSerializer):
|
|
258
301
|
stores = Store.objects.filter(store_items__cart=user.cart).distinct()
|
259
302
|
gift_details = attrs["extra_infos"].get("gift_details", None)
|
260
303
|
if gift_details:
|
261
|
-
|
262
|
-
for key in settings.DIGITAL_PRODUCTS_REQUIRED_KEYS:
|
263
|
-
if not (key in gift_details.keys() and len(str(gift_details.get(key)))):
|
264
|
-
errors.append({key: "This field should be filled."})
|
265
|
-
if len(errors) > 0:
|
266
|
-
raise serializers.ValidationError(errors)
|
267
|
-
if not pycountry.currencies.get(alpha_3=gift_details["currency"]):
|
268
|
-
raise serializers.ValidationError("Gift currency is not valid")
|
269
|
-
try:
|
270
|
-
product = Product.objects.get(id=gift_details["digital_product"])
|
271
|
-
except ObjectDoesNotExist:
|
272
|
-
raise serializers.ValidationError(_("Digital product does not exist!"))
|
273
|
-
if product.type == Product.ProductTypes.PHYSICAL:
|
274
|
-
raise serializers.ValidationError(
|
275
|
-
_("You must not fill extra infos for physical products.")
|
276
|
-
)
|
277
|
-
|
278
|
-
gift_minimun_amount = store_settings.GIFT_MINIMUM_AMOUNT.get(
|
279
|
-
attrs["store"].currency, 5
|
280
|
-
)
|
281
|
-
if gift_details["price"] <= gift_minimun_amount - 1:
|
282
|
-
raise serializers.ValidationError(_("Gift card amount is not valid!"))
|
304
|
+
self._validate_digital_product(gift_details, attrs)
|
283
305
|
currency = gift_details["currency"]
|
284
306
|
# The Cart items must not be empty
|
285
307
|
elif not user.cart.items.exists():
|
@@ -722,6 +744,7 @@ class ProductSerializer(FavoriteMixin, serializers.ModelSerializer):
|
|
722
744
|
"id",
|
723
745
|
"name",
|
724
746
|
"slug",
|
747
|
+
"label",
|
725
748
|
"description",
|
726
749
|
"product_images",
|
727
750
|
"product_variants",
|
@@ -744,6 +767,7 @@ class ProductListSerializer(serializers.ModelSerializer):
|
|
744
767
|
"id",
|
745
768
|
"name",
|
746
769
|
"slug",
|
770
|
+
"label",
|
747
771
|
"description",
|
748
772
|
"product_images",
|
749
773
|
"type",
|
@@ -3,7 +3,7 @@ ob_dj_store/apis/stores/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
3
3
|
ob_dj_store/apis/stores/filters.py,sha256=dl2ncAu871774RP6JrBQpbi46k89GEy_OEE_kkzkPXs,8555
|
4
4
|
ob_dj_store/apis/stores/urls.py,sha256=P4d0iamg2R5lTwc5DTIuhLzJTMSH4f5QpHzGR1_PWE0,1676
|
5
5
|
ob_dj_store/apis/stores/views.py,sha256=lDMhlAkxt_q0npVkvm2eAxUmZ_Jbm5v9P63_sXFIIzo,38039
|
6
|
-
ob_dj_store/apis/stores/rest/serializers/serializers.py,sha256=
|
6
|
+
ob_dj_store/apis/stores/rest/serializers/serializers.py,sha256=ohA0C_qEmZt2NQ2GXSaDlmPP0fiJREPEbua4czX4c68,49682
|
7
7
|
ob_dj_store/apis/tap/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
8
|
ob_dj_store/apis/tap/serializers.py,sha256=KPrBK4h2-fWvEVf6vOj2ww5-USV9WqpyYicIqoHIiXI,1065
|
9
9
|
ob_dj_store/apis/tap/urls.py,sha256=bnOTv6an11kxpo_FdqlhsizlGPLVpNxBjCyKcf3_C9M,367
|
@@ -131,7 +131,7 @@ ob_dj_store/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
131
131
|
ob_dj_store/utils/helpers.py,sha256=o7wgypM7mI2vZqZKkhxnTcnHJC8GMQDOuYMnRwXr6tY,2058
|
132
132
|
ob_dj_store/utils/model.py,sha256=DV7hOhTaZL3gh9sptts2jTUFlTArKG3i7oPioq9HLFE,303
|
133
133
|
ob_dj_store/utils/utils.py,sha256=8UVAFB56qUSjJJ5f9vnermtw638gdFy4CFRCuMbns_M,1342
|
134
|
-
ob_dj_store-0.0.15.
|
135
|
-
ob_dj_store-0.0.15.
|
136
|
-
ob_dj_store-0.0.15.
|
137
|
-
ob_dj_store-0.0.15.
|
134
|
+
ob_dj_store-0.0.15.6.dist-info/METADATA,sha256=Si48BUWpsafl_ZvAxOggl2mcBGxnM04MdA8cVgKdJFk,2827
|
135
|
+
ob_dj_store-0.0.15.6.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
136
|
+
ob_dj_store-0.0.15.6.dist-info/top_level.txt,sha256=CZG3G0ptTkzGnc0dFYN-ZD7YKdJBmm47bsmGwofD_lk,12
|
137
|
+
ob_dj_store-0.0.15.6.dist-info/RECORD,,
|
File without changes
|