Explorar o código

Created Order Form

Sasha Pi hai 5 meses
pai
achega
01c583c488
Modificáronse 5 ficheiros con 115 adicións e 8 borrados
  1. 34 2
      forms.py
  2. 20 3
      models/webservice_running.py
  3. 22 0
      templates/webservice_running/order_local.html
  4. 2 0
      urls.py
  5. 37 3
      views.py

+ 34 - 2
forms.py

@@ -1,6 +1,6 @@
 from django import forms
 from django.contrib.auth import get_user_model
-
+from dbsynce.models import ServiceType, Service, Orders, Resource
 from webservice_running.models import OrdersLocal 
 from django.contrib.auth.forms import UserCreationForm
 
@@ -27,4 +27,36 @@ class RegisterUserForm(UserCreationForm):
 
     class Meta:
         model = get_user_model()
-        fields = ['username', 'password1', 'password2']
+        fields = ['username', 'password1', 'password2']
+
+class OrderLocalForm(forms.ModelForm):
+    order_synced = forms.ModelChoiceField(queryset = Orders.objects.all(), label="Заказ")
+    resource_id = forms.ModelChoiceField(queryset = Resource.objects.all(), label="Ресурс")
+    specialization = forms.CharField(label="Специализация рабочего места")
+    address = forms.CharField(label="Адрес коворкинга")
+    daily_price = forms.CharField(label="Стоимость в день")
+    payment_transaction_id = forms.CharField(label="Транзакция платежа")
+    attempts = forms.CharField(label="Попытка")
+    order_place_type = forms.CharField(label="Тип заказа")
+
+    def __init__(self, *args, **kwargs):
+        super(OrderLocalForm, self).__init__(*args, **kwargs)
+
+    class Meta: 
+        model = OrdersLocal
+        fields = [
+        'order_synced',
+        'resource_id', 
+        'specialization',
+        'address',
+        'daily_price',
+        'payment_transaction_id',
+        'attempts',
+        'order_place_type',
+        ]
+        #fields = '__all__'
+
+    def __init__(self, *args, **kwargs):
+      super().__init__(*args, **kwargs)
+      for field in self.fields.values():
+          field.widget.attrs['class'] = 'form-control'

+ 20 - 3
models/webservice_running.py

@@ -5,8 +5,9 @@ class OrdersLocal(models.Model):
     """
     OrdersLocal - таблица с заказами
     """
-    order_synced = models.ForeignKey(Orders, on_delete=models.DO_NOTHING, help_text="ID заказа в 'Orders'")
-    resource_id = models.ForeignKey(Resource, null=True, on_delete=models.DO_NOTHING, help_text="ID коворкинга")    
+    order_synced = models.ForeignKey(Orders, on_delete=models.DO_NOTHING)
+    resource_id = models.ForeignKey(Resource, null=True, on_delete=models.DO_NOTHING)
+
     address = models.CharField(null=True, max_length=150, help_text="Адрес коворкинга")
     specialization = models.CharField(null=True, max_length=150, help_text="Специализация")
     daily_price = models.IntegerField(null=True, help_text="Стоимость в день (руб.)")
@@ -14,7 +15,23 @@ class OrdersLocal(models.Model):
     date_end = models.DateField(null=True, help_text="Дата завершения аренды")
     days = models.IntegerField(null=True, help_text="Количество дней")
     total_price = models.IntegerField(null=True, help_text="Итоговая стоимость (руб.)")
-    time_order_created = models.DateTimeField(auto_now_add=True, editable=False, help_text="Время создания заказа")
+
+    #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"

+ 22 - 0
templates/webservice_running/order_local.html

@@ -0,0 +1,22 @@
+{% extends 'SharixAdmin/index.html' %}
+{% load render_table from django_tables2 %}
+{% load i18n %}
+{% load static %}
+
+{% block contenthome %}
+
+    <div class="container">
+      <h1 class="mainHeader">Форма отправки заказа</h1>
+      <p class="description_service">Если вы мастер или специалист сферы красоты - наш сервис поможет вам арендовать рабочее место. Данная форма поможет Вам создать заказ на бронирование рабочего места в коворкинге!</p>
+        <div class="container" style="padding: 2px;">
+          <div class="row justify-content-center fs-6">
+            <div class="col-6">
+              <form action="" method="post">
+                {% csrf_token %}
+                {{ form.as_p }}
+                <button type="submit" class="btn btn-primary">Оформить заказ</button>
+              </form>
+            </div>
+          </div>
+        </div>
+{% endblock contenthome %}

+ 2 - 0
urls.py

@@ -2,6 +2,7 @@ from webservice_running.apiviews import *
 from rest_framework import routers
 from django.urls import path, include, re_path
 from webservice_running import views
+from webservice_running.views import order_new
 
 app_name = 'webservice_running'
 
@@ -9,6 +10,7 @@ router = routers.DefaultRouter()
 router.register(r'webservice', OrdersLocalMVS)
 
 urlpatterns = [
+    path('order_new/', views.order_new.as_view(), name="order_new"),
     path('order_reg/', views.order_reg, name="order_reg"),
     path('', views.registration, name="registration"),
     path('api/', include(router.urls), name="webservice_running_api"),

+ 37 - 3
views.py

@@ -1,10 +1,14 @@
-from django.urls import reverse_lazy
+from django.urls import reverse_lazy, reverse
 import requests
 from django.http import HttpResponse
 from webservice_running.apps import api
 from core.settings import API_URL
-from webservice_running.forms import OrderRegForm, RegisterUserForm
+from webservice_running.forms import OrderRegForm, RegisterUserForm, OrderLocalForm
+from webservice_running.models import OrdersLocal
 from django.shortcuts import redirect, render
+from django.views.generic.edit import CreateView
+from django.utils.translation import gettext as _
+#from django.contrib.auth.mixins import UserPassesTestMixin
 
 def order_reg(request):
     if request.method == 'POST':
@@ -25,4 +29,34 @@ def registration(request):
         return redirect('authweb')
     else:
        form = RegisterUserForm()
-    return render(request, 'webservice_running/registration.html', {'form': form})
+    return render(request, 'webservice_running/registration.html', {'form': form})
+
+#class order_new(UserPassesTestMixin, CreateView):
+class order_new(CreateView):
+    model = OrdersLocal
+    form_class = OrderLocalForm
+    template_name = "webservice_running/order_local.html"
+
+    def get_context_data(self, **kwargs):
+
+        page_context = super().get_context_data(**kwargs)
+        base_context = {
+            'title': _('Заказ - создание'),
+            'object': self.object,
+            'current_page': 'order_new'
+        }
+        context = dict(list(base_context.items()) + list(page_context.items()))
+        return context
+
+    def testing(self, queryset, is_descending):
+        queryset = queryset.annotate.order_by("-" if is_descending else "")
+        return (queryset, True)
+
+    def get_success_url(self):
+        return reverse('webservice_running:order_new')
+
+    def test_func(self) -> bool or None:
+        group_names = ('METASERVICE-ADMIN')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
+            return True
+        return False