Sfoglia il codice sorgente

Merge branch 'local' into unstable

1Mike21 1 anno fa
parent
commit
abbbd28952
12 ha cambiato i file con 203 aggiunte e 3 eliminazioni
  1. 1 0
      .gitignore
  2. 3 1
      admin.py
  3. 1 0
      apiviews/__init__.py
  4. 69 0
      apiviews/orders_local.py
  5. 4 0
      apps.py
  6. 10 0
      factory.py
  7. 1 0
      models/__init__.py
  8. 30 0
      models/orders_local.py
  9. 1 0
      serializer/__init__.py
  10. 75 0
      serializer/orders_local.py
  11. 7 1
      urls.py
  12. 1 1
      views.py

+ 1 - 0
.gitignore

@@ -8,5 +8,6 @@ __pycache__/
 
 # Django
 migrations/
+!__init___.py
 # Desktop Services Store
 .DS_Store

+ 3 - 1
admin.py

@@ -1,3 +1,5 @@
 from django.contrib import admin
+from openlocal.models import OrdersLocal
 
-# Register your models here.
+
+admin.site.register(OrdersLocal)

+ 1 - 0
apiviews/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocalMVS

+ 69 - 0
apiviews/orders_local.py

@@ -0,0 +1,69 @@
+from django.http import Http404, HttpResponse
+from django.shortcuts import get_object_or_404
+from openlocal.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 metaservicesynced.models import Orders, Service, ServiceType, Provider, Client
+# from SharixAdmin.models import SharixUser
+# from tickets.models import Task
+# from tickets.serializer import TaskSerializer
+
+class OrdersLocalMVS(viewsets.ModelViewSet):
+    queryset = OrdersLocal.objects.all()
+    serializer_class = OrdersLocalSerializer
+    #permission_classes = [IsOwnerOrReadOnly]
+    permission_classes = [permissions.IsAuthenticated]
+    
+
+    def get_object(self):
+        """
+        Returns the object the view is displaying.
+
+        You may want to override this if you need to provide non-standard
+        queryset lookups.  Eg if objects are referenced using multiple
+        keyword arguments in the url conf.
+        """
+        # queryset = self.filter_queryset(self.get_queryset())
+        queryset = OrdersLocal.objects.select_related('order_synced__ticket')
+
+        # Perform the lookup filtering.
+        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
+
+        assert lookup_url_kwarg in self.kwargs, (
+            'Expected view %s to be called with a URL keyword argument '
+            'named "%s". Fix your URL conf, or set the `.lookup_field` '
+            'attribute on the view correctly.' %
+            (self.__class__.__name__, lookup_url_kwarg)
+        )
+
+        filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
+        obj = get_object_or_404(queryset, **filter_kwargs)
+
+        # May raise a permission denied
+        self.check_object_permissions(self.request, obj)
+
+        return obj
+
+
+    def update(self, request, *args, **kwargs):
+        partial = kwargs.pop('partial', False)
+        instance = self.get_object()# OrdersLocal.objects.select_related('order_synced__ticket').get(id=1)
+        serializer = self.get_serializer(instance, data=request.data, partial=partial)
+        # for serializer in serializers:
+        serializer.is_valid(raise_exception=True)
+        self.perform_update(serializer)
+
+        if getattr(instance, '_prefetched_objects_cache', None):
+            # If 'prefetch_related' has been applied to a queryset, we need to
+            # forcibly invalidate the prefetch cache on the instance.
+            instance._prefetched_objects_cache = {}
+
+        return Response(serializer.data)
+
+    
+    
+    
+    
+    

+ 4 - 0
apps.py

@@ -4,3 +4,7 @@ from django.apps import AppConfig
 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"

+ 10 - 0
factory.py

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

+ 1 - 0
models/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocal

+ 30 - 0
models/orders_local.py

@@ -0,0 +1,30 @@
+from django.db import models
+from metaservicesynced.models import Orders, Resource
+
+class OrdersLocal(models.Model):
+    """
+    OrdersLocal - таблица с заказами
+    """
+    order_synced = models.ForeignKey(Orders, null=True, 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)
+    attempts = models.IntegerField(null=True, help_text="Попытки")
+
+    order_place_type = models.CharField(null=True, max_length=150)
+    order_place_start = models.CharField(null=True, max_length=150)
+    order_place_start_gps = models.CharField(null=True, max_length=150)
+    order_place_start_sector = models.IntegerField(null=True)
+    order_place_start_real = models.CharField(null=True, max_length=150)
+    order_place_start_real_gps = models.CharField(null=True, max_length=150)
+    order_place_finish_predicted = models.CharField(null=True, max_length=150)
+    order_place_finish_predicted_gps = models.CharField(null=True, max_length=150)
+    order_place_finish_sector = models.IntegerField(null=True)
+    order_place_finish_real = models.CharField(null=True, max_length=150)
+    order_place_finish_real_gps = models.CharField(null=True, max_length=150)
+
+
+    class Meta:
+        db_table = "orders_local"
+        verbose_name = "Заказ (local)"
+        verbose_name_plural = "Заказы (local)"

+ 1 - 0
serializer/__init__.py

@@ -0,0 +1 @@
+from .orders_local import OrdersLocalSerializer

+ 75 - 0
serializer/orders_local.py

@@ -0,0 +1,75 @@
+from rest_framework import serializers
+from openlocal.models import OrdersLocal
+from tickets.models import *
+from metaservicesynced.models import Orders
+from SharixAdmin.models import SharixUser
+from tickets.serializer import TaskSerializer
+# from metaservicesynced.serializer import OrdersSerializer
+from rest_framework.utils import model_meta
+import pprint
+from django.db import connection
+
+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) 
+    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_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)
+    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) 
+
+    #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)
+    # order_synced = OrdersSerializer(read_only=True)
+    
+    class Meta:
+        model = OrdersLocal
+        fields = "__all__"
+        # fields = ["order", "order_synced"]
+        # depth = 2
+
+
+    def update(self, instance, validated_data):
+        # pprint.pprint(connection.queries)
+        order_instance = instance.order_synced
+        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():
+                    if order_synced_attr == "ticket":
+                        for ticket_attr, ticket_value in order_synced_value.items():
+                            setattr(ticket_instance, ticket_attr, ticket_value)
+                            continue
+                    else:
+                        setattr(order_instance, order_synced_attr, order_synced_value)
+            else:
+                setattr(instance, attr, value)
+
+        instance.save()
+        ticket_instance.save()
+        order_instance.save()
+        return instance

+ 7 - 1
urls.py

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

+ 1 - 1
views.py

@@ -6,4 +6,4 @@ def order_reg(request):
       form = OrderRegForm(request.POST)
       if form.is_valid():
           form.save()
-    return render(request, 'webservice/order_reg.html', {'form': form})
+    return render(request, 'webservice/order_reg.html', {'form': form})