Browse Source

Create ticket when creating order; fixed: service field source attr pointed at object instead of pk; correct apps.py, fixing merged code etc.; Deleted trash files; edited readme; edited .gitignore to ignore migrations and __pycache__

yobafromstarvvars 1 year ago
parent
commit
cb9cd829c5
10 changed files with 34 additions and 32 deletions
  1. 3 2
      .gitignore
  2. 1 1
      admin.py
  3. 2 2
      apiviews/orders_local.py
  4. 3 3
      apps.py
  5. 0 10
      factory.py
  6. 0 3
      models.py
  7. 1 1
      models/__init__.py
  8. 1 1
      models/webservice_running.py
  9. 20 6
      serializer/orders_local.py
  10. 3 3
      urls.py

+ 3 - 2
.gitignore

@@ -3,11 +3,12 @@
 
 # Python
 __pycache__/
+*/__pycache__
 *.py[cod]
 *$py.class
 
 # Django
-migrations/
-!__init___.py
+migrations/*
+!migrations/__init___.py
 # Desktop Services Store
 .DS_Store

+ 1 - 1
admin.py

@@ -1,5 +1,5 @@
 from django.contrib import admin
-from openlocal.models import OrdersLocal
+from webservice_running.models import OrdersLocal
 
 
 admin.site.register(OrdersLocal)

+ 2 - 2
apiviews/orders_local.py

@@ -1,10 +1,10 @@
 from django.http import Http404, HttpResponse
 from django.shortcuts import get_object_or_404
-from openlocal.serializer import OrdersLocalSerializer
+from webservice_running.serializer import OrdersLocalSerializer
 from rest_framework import viewsets, permissions, status
 from rest_framework.response import Response
 from rest_framework.exceptions import NotFound
-from openlocal.models import OrdersLocal
+from webservice_running.models import OrdersLocal
 # from metaservicesynced.models import Orders, Service, ServiceType, Provider, Client
 # from SharixAdmin.models import SharixUser
 # from tickets.models import Task

+ 3 - 3
apps.py

@@ -5,6 +5,6 @@ class WebserviceRunningConfig(AppConfig):
     default_auto_field = 'django.db.models.BigAutoField'
     name = 'webservice_running'
 
-class OpenlocalConfig(AppConfig):
-    default_auto_field = "django.db.models.BigAutoField"
-    name = "openlocal"
+# class OpenlocalConfig(AppConfig):
+#     default_auto_field = "django.db.models.BigAutoField"
+#     name = "openlocal"

+ 0 - 10
factory.py

@@ -1,10 +0,0 @@
-import factory
-from factory.faker import faker
-from openlocal.models import *
-from metaservicesynced.models import *
-
-class OrdersLocalFactory(factory.django.DjangoModelFactory):
-    class Meta:
-        model = OrdersLocal
-
-    

+ 0 - 3
models.py

@@ -1,3 +0,0 @@
-from django.db import models
-
-# Create your models here.

+ 1 - 1
models/__init__.py

@@ -1 +1 @@
-from .orders_local import OrdersLocal
+from .webservice_running import OrdersLocal

+ 1 - 1
models/orders_local.py → models/webservice_running.py

@@ -5,7 +5,7 @@ class OrdersLocal(models.Model):
     """
     OrdersLocal - таблица с заказами
     """
-    order_synced = models.ForeignKey(Orders, null=True, on_delete=models.DO_NOTHING)
+    order_synced = models.ForeignKey(Orders, on_delete=models.DO_NOTHING)
     resource_id = models.ForeignKey(Resource, null=True, on_delete=models.DO_NOTHING)
     rating_id = models.IntegerField(null=True)#Need create table with rating
     payment_transaction_id = models.IntegerField(null=True)#Need create table with payment_transaction or it get from platform (i dont know)

+ 20 - 6
serializer/orders_local.py

@@ -1,5 +1,5 @@
 from rest_framework import serializers
-from openlocal.models import OrdersLocal
+from webservice_running.models import OrdersLocal
 from tickets.models import *
 from metaservicesynced.models import Orders
 from SharixAdmin.models import SharixUser
@@ -8,14 +8,25 @@ from tickets.serializer import TaskSerializer
 from rest_framework.utils import model_meta
 import pprint
 from django.db import connection
+from webservice_running.exceptions import *
+
+
+class OrderNotDefined(Exception):
+    """
+    If order_synced field is not defined throw exception
+    """
+    def __init__(self, message="order_synced is not defined"):
+        self.message = message
+        super().__init__(self.message)
+
 
 class OrdersLocalSerializer(serializers.ModelSerializer):
-    service = serializers.IntegerField(source="order_synced.service", allow_null=True)    
-    service_type = serializers.IntegerField(source="order_synced.service_type", allow_null=True) 
+    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.CharField(source="order_synced.provider.pk", 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) 
 
     receiver = serializers.IntegerField(source="order_synced.receiver.pk", allow_null=True)
@@ -54,9 +65,12 @@ class OrdersLocalSerializer(serializers.ModelSerializer):
 
     def update(self, instance, validated_data):
         # pprint.pprint(connection.queries)
-        order_instance = instance.order_synced
+
+        order_instance = instance.order_synced #if "order_synced" not in validated_data else validated_data["order_synced"]
+        if not order_instance:
+            raise OrderNotDefined()
         ticket_instance = instance.order_synced.ticket
-        
+
         for attr, value in validated_data.items():
             if attr == "order_synced":
                 for order_synced_attr, order_synced_value in value.items():

+ 3 - 3
urls.py

@@ -1,4 +1,4 @@
-from openlocal.apiviews import *
+from webservice_running.apiviews import *
 from rest_framework import routers
 from django.urls import path, include, re_path
 from . import views
@@ -6,9 +6,9 @@ from . import views
 app_name = 'webservice'
 
 router = routers.DefaultRouter()
-router.register(r'orderslocal', OrdersLocalMVS)
+router.register(r'webservice', OrdersLocalMVS)
 
 urlpatterns = [
     path("", views.order_reg, name="order_reg"),
-    path('api/', include(router.urls), name="openlocalapi"),
+    path('api/', include(router.urls), name="webservice_running_api"),
 ]