|
@@ -1,42 +1,43 @@
|
|
|
+from django.forms.models import model_to_dict
|
|
|
from rest_framework import serializers
|
|
|
from webservice_running.models import Event
|
|
|
from webservice_running.exceptions import OrderNotDefined
|
|
|
|
|
|
|
|
|
class EventSerializer(serializers.ModelSerializer):
|
|
|
- service = serializers.IntegerField(source="order_synced.service.pk", allow_null=True)
|
|
|
- service_type = serializers.IntegerField(source="order_synced.service_type.pk", allow_null=True)
|
|
|
- state = serializers.CharField(source="order_synced.state", allow_null=True)
|
|
|
- id_metaservice = serializers.IntegerField(source="order_synced.id_metaservice", allow_null=True)
|
|
|
-
|
|
|
- provider = serializers.IntegerField(source="order_synced.provider.pk", allow_null=True)
|
|
|
- provider_screen_name = serializers.CharField(source="order_synced.provider.user_id.full_name", allow_null=True)
|
|
|
+ service = serializers.IntegerField(source="order_synced.service.pk", allow_null=True, required=False)
|
|
|
+ service_type = serializers.IntegerField(source="order_synced.service_type.pk", allow_null=True, required=False)
|
|
|
+ state = serializers.CharField(source="order_synced.state", allow_null=True, required=False)
|
|
|
+ id_metaservice = serializers.IntegerField(source="order_synced.id_metaservice", allow_null=True, required=False)
|
|
|
|
|
|
- receiver = serializers.IntegerField(source="order_synced.receiver.pk", allow_null=True)
|
|
|
- receiver_screen_name = serializers.CharField(source="order_synced.receiver.full_name", allow_null=True)
|
|
|
-
|
|
|
- client_id = serializers.CharField(source="order_synced.client_id.pk", allow_null=True)
|
|
|
- client_screen_name = serializers.CharField(source="order_synced.client.user.full_name", allow_null=True)
|
|
|
+ provider = serializers.IntegerField(source="order_synced.provider.pk", allow_null=True, required=False)
|
|
|
+ provider_screen_name = serializers.CharField(source="order_synced.provider.user_id.full_name", allow_null=True, required=False)
|
|
|
|
|
|
- #time_created = serializers.DateTimeField(source="order_synced.time_created", allow_null=True)
|
|
|
- time_placed = serializers.DateTimeField(source="order_synced.time_placed", allow_null=True)
|
|
|
- time_start = serializers.DateTimeField(source="order_synced.time_start", allow_null=True)
|
|
|
- time_start_real = serializers.DateTimeField(source="order_synced.time_start_real", allow_null=True)
|
|
|
- time_start_predicted = serializers.DateTimeField(source="order_synced.time_start_predicted", allow_null=True)
|
|
|
- time_finish_predicted = serializers.DateTimeField(source="order_synced.time_finish_predicted", allow_null=True)
|
|
|
- time_finish_real = serializers.DateTimeField(source="order_synced.time_finish_real", allow_null=True)
|
|
|
-
|
|
|
- predicted_price = serializers.FloatField(source="order_synced.predicted_price", allow_null=True)
|
|
|
- real_price = serializers.FloatField(source="order_synced.real_price", allow_null=True)
|
|
|
- is_global = serializers.BooleanField(source="order_synced.is_global", allow_null=True)
|
|
|
- is_visible = serializers.BooleanField(source="order_synced.is_visible", allow_null=True)
|
|
|
- ticket = serializers.IntegerField(source="order_synced.ticket.pk", allow_null=True)
|
|
|
- status = serializers.IntegerField(source="order_synced.ticket.stauts", allow_null=True)
|
|
|
- priority = serializers.IntegerField(source="order_synced.ticket.priority", allow_null=True)
|
|
|
- title = serializers.CharField(source="order_synced.ticket.title", allow_null=True)
|
|
|
- note = serializers.CharField(source="order_synced.ticket.note", allow_null=True)
|
|
|
- due_date = serializers.DateField(source="order_synced.ticket.due_date", allow_null=True)
|
|
|
- status_changed_date = serializers.DateTimeField(source="order_synced.ticket.status_changed_date", allow_null=True)
|
|
|
+ receiver = serializers.IntegerField(source="order_synced.receiver.pk", allow_null=True, required=False)
|
|
|
+ receiver_screen_name = serializers.CharField(source="order_synced.receiver.full_name", allow_null=True, required=False)
|
|
|
+
|
|
|
+ client_id = serializers.CharField(source="order_synced.client_id.pk", allow_null=True, required=False)
|
|
|
+ client_screen_name = serializers.CharField(source="order_synced.client.user.full_name", allow_null=True, required=False)
|
|
|
+
|
|
|
+ #time_created = serializers.DateTimeField(source="order_synced.time_created", allow_null=True)
|
|
|
+ time_placed = serializers.DateTimeField(source="order_synced.time_placed", allow_null=True, required=False)
|
|
|
+ time_start = serializers.DateTimeField(source="order_synced.time_start", allow_null=True, required=False)
|
|
|
+ time_start_real = serializers.DateTimeField(source="order_synced.time_start_real", allow_null=True, required=False)
|
|
|
+ time_start_predicted = serializers.DateTimeField(source="order_synced.time_start_predicted", allow_null=True, required=False)
|
|
|
+ time_finish_predicted = serializers.DateTimeField(source="order_synced.time_finish_predicted", allow_null=True, required=False)
|
|
|
+ time_finish_real = serializers.DateTimeField(source="order_synced.time_finish_real", allow_null=True, required=False)
|
|
|
+
|
|
|
+ predicted_price = serializers.FloatField(source="order_synced.predicted_price", allow_null=True, required=False)
|
|
|
+ real_price = serializers.FloatField(source="order_synced.real_price", allow_null=True, required=False)
|
|
|
+ is_global = serializers.BooleanField(source="order_synced.is_global", allow_null=True, required=False)
|
|
|
+ is_visible = serializers.BooleanField(source="order_synced.is_visible", allow_null=True, required=False)
|
|
|
+ ticket = serializers.IntegerField(source="order_synced.ticket.pk", allow_null=True, required=False)
|
|
|
+ status = serializers.IntegerField(source="order_synced.ticket.stauts", allow_null=True, required=False)
|
|
|
+ priority = serializers.IntegerField(source="order_synced.ticket.priority", allow_null=True, required=False)
|
|
|
+ title = serializers.CharField(source="order_synced.ticket.title", allow_null=True, required=False)
|
|
|
+ note = serializers.CharField(source="order_synced.ticket.note", allow_null=True, required=False)
|
|
|
+ due_date = serializers.DateField(source="order_synced.ticket.due_date", allow_null=True, required=False)
|
|
|
+ status_changed_date = serializers.DateTimeField(source="order_synced.ticket.status_changed_date", allow_null=True, required=False)
|
|
|
# order_synced = OrdersSerializer(read_only=True)
|
|
|
|
|
|
class Meta:
|
|
@@ -54,9 +55,12 @@ class EventSerializer(serializers.ModelSerializer):
|
|
|
if not order_instance:
|
|
|
raise OrderNotDefined()
|
|
|
ticket_instance = instance.order_synced.ticket
|
|
|
-
|
|
|
+ # ОШИБКА ЕСЛИ В validated_data УКАЗАТЬ order_synced
|
|
|
for attr, value in validated_data.items():
|
|
|
if attr == "order_synced":
|
|
|
+ print("="*100)
|
|
|
+ #print(model_to_dict(value))
|
|
|
+ print("="*100)
|
|
|
for order_synced_attr, order_synced_value in value.items():
|
|
|
if order_synced_attr == "ticket":
|
|
|
for ticket_attr, ticket_value in order_synced_value.items():
|
|
@@ -72,11 +76,3 @@ class EventSerializer(serializers.ModelSerializer):
|
|
|
order_instance.save()
|
|
|
return instance
|
|
|
|
|
|
- def create(self, request, *args, **kwargs):
|
|
|
- serializer = self.get_serializer(data=request.data)
|
|
|
- serializer.is_valid(raise_exception=True)
|
|
|
- self.perform_create(serializer)
|
|
|
- headers = self.get_success_headers(serializer.data)
|
|
|
- return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
|
|
-
|
|
|
-
|