merged from develop, added merge migration and refactored a little bit
This commit is contained in:
parent
471239983e
commit
387e164510
14
apps/collection/migrations/0026_merge_20191217_1151.py
Normal file
14
apps/collection/migrations/0026_merge_20191217_1151.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.7 on 2019-12-17 11:51
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('collection', '0024_auto_20191213_0859'),
|
||||||
|
('collection', '0025_collection_description'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
|
|
@ -94,54 +94,3 @@ class CollectionBindObjectSerializer(serializers.Serializer):
|
||||||
raise RemovedBindingObjectNotFound()
|
raise RemovedBindingObjectNotFound()
|
||||||
attrs['related_object'] = product
|
attrs['related_object'] = product
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
class GuideBindObjectSerializer(serializers.Serializer):
|
|
||||||
"""Serializer for binding collection and objects"""
|
|
||||||
|
|
||||||
ESTABLISHMENT = 'establishment'
|
|
||||||
PRODUCT = 'product'
|
|
||||||
|
|
||||||
TYPE_CHOICES = (
|
|
||||||
(ESTABLISHMENT, 'Establishment'),
|
|
||||||
(PRODUCT, 'Product'),
|
|
||||||
)
|
|
||||||
|
|
||||||
type = serializers.ChoiceField(TYPE_CHOICES)
|
|
||||||
object_id = serializers.IntegerField()
|
|
||||||
|
|
||||||
def validate(self, attrs):
|
|
||||||
view = self.context.get('view')
|
|
||||||
request = self.context.get('request')
|
|
||||||
|
|
||||||
obj_type = attrs.get('type')
|
|
||||||
obj_id = attrs.get('object_id')
|
|
||||||
|
|
||||||
collection = view.get_object()
|
|
||||||
attrs['collection'] = collection
|
|
||||||
|
|
||||||
if obj_type == self.ESTABLISHMENT:
|
|
||||||
establishment = Establishment.objects.filter(pk=obj_id).\
|
|
||||||
first()
|
|
||||||
if not establishment:
|
|
||||||
raise BindingObjectNotFound()
|
|
||||||
if request.method == 'POST' and collection.establishments.\
|
|
||||||
filter(pk=establishment.pk).exists():
|
|
||||||
raise ObjectAlreadyAdded()
|
|
||||||
if request.method == 'DELETE' and not collection.\
|
|
||||||
establishments.filter(pk=establishment.pk).\
|
|
||||||
exists():
|
|
||||||
raise RemovedBindingObjectNotFound()
|
|
||||||
attrs['related_object'] = establishment
|
|
||||||
elif obj_type == self.PRODUCT:
|
|
||||||
product = Product.objects.filter(pk=obj_id).first()
|
|
||||||
if not product:
|
|
||||||
raise BindingObjectNotFound()
|
|
||||||
if request.method == 'POST' and collection.products.\
|
|
||||||
filter(pk=product.pk).exists():
|
|
||||||
raise ObjectAlreadyAdded()
|
|
||||||
if request.method == 'DELETE' and not collection.products.\
|
|
||||||
filter(pk=product.pk).exists():
|
|
||||||
raise RemovedBindingObjectNotFound()
|
|
||||||
attrs['related_object'] = product
|
|
||||||
return attrs
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,8 @@ from rest_framework import serializers
|
||||||
|
|
||||||
from collection import models
|
from collection import models
|
||||||
from location import models as location_models
|
from location import models as location_models
|
||||||
from utils.serializers import TranslatedField
|
|
||||||
from main.models import SiteSettings
|
|
||||||
from main.serializers import SiteShortSerializer
|
from main.serializers import SiteShortSerializer
|
||||||
|
from utils.serializers import TranslatedField
|
||||||
|
|
||||||
|
|
||||||
class CollectionBaseSerializer(serializers.ModelSerializer):
|
class CollectionBaseSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user