Browse Source

update models, views, forms, urls

kateshev14 5 months ago
parent
commit
4029dd656b
6 changed files with 159 additions and 36 deletions
  1. 37 3
      forms.py
  2. 15 21
      models/webservice_running.py
  3. 33 0
      tables.py
  4. 15 0
      templates/webservice_running/order_list.html
  5. 5 2
      urls.py
  6. 54 10
      views.py

+ 37 - 3
forms.py

@@ -4,10 +4,32 @@ from django.contrib.auth import get_user_model
 from webservice_running.models import OrdersLocal 
 from django.contrib.auth.forms import UserCreationForm
 
+GUIDE_TYPE = [
+    ('one', '1'),
+    ('two', '2'),
+    ('three', '3'),
+]
+MOVEMENT_WAY = [
+    ('one', 'Автобус'),
+    ('two', 'Машина'),
+    ('three', 'Пешком'),
+]
+
+
 class OrderRegForm(forms.ModelForm):
+    place_start = forms.CharField(label="Точка 1")  
+    place_end = forms.CharField(label="Точка 2")  
+    guide_type = forms.ChoiceField(choices=GUIDE_TYPE, label="Тип гида")
+    movement_way = forms.ChoiceField(choices=MOVEMENT_WAY, label="Вид передвижения")
+    numb_of_people = forms.IntegerField(label="Количество человек")
+    service_date = forms.DateField(label="Дата", help_text=datetime.date.today)
+    service_time = forms.TimeField(label="Время")
+    discription = forms.CharField(label="Пожелания")
+    price = forms.IntegerField(label="Предварительная стоимость")  
+  
     class Meta: 
         model = OrdersLocal
-        fields = '__all__'
+        fields = ['place_start', 'place_end', 'guide_type', 'movement_way', 'numb_of_people', 'service_date', 'service_time', 'discription', 'price']
 
     def __init__(self, *args, **kwargs):
       super().__init__(*args, **kwargs)
@@ -22,9 +44,21 @@ class RegisterUserForm(UserCreationForm):
     password2 = forms.CharField(label="Подтверждение пароля",
         widget=forms.PasswordInput(attrs={'class':'form-control'}))
 
-    username = forms.CharField(label="Номер телефона",
+    phone_number = forms.CharField(label="Номер телефона",
+        widget=forms.TextInput(attrs={'class':'form-control'}))
+    
+    email = forms.CharField(label="Email",
+        widget=forms.TextInput(attrs={'class':'form-control'}))
+    
+    username = forms.CharField(label="Имя пользователя",
+        widget=forms.TextInput(attrs={'class':'form-control'}))
+    
+    first_name = forms.CharField(label="Имя",
         widget=forms.TextInput(attrs={'class':'form-control'}))
 
+    last_name = forms.CharField(label="Фамилия",
+        widget=forms.TextInput(attrs={'class':'form-control'}))    
+    
     class Meta:
         model = get_user_model()
-        fields = ['username', 'password1', 'password2']
+        fields = ['username', 'first_name', 'last_name', 'avatar', 'phone_number', "email", 'password1', 'password2' ]

+ 15 - 21
models/webservice_running.py

@@ -7,31 +7,25 @@ class OrdersLocal(models.Model):
     OrdersLocal - таблица с заказами
     """
     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)
-    attempts = models.IntegerField(null=True, help_text="Попытки")
+   # 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)
-
-    comment = models.CharField(null=True, max_length=300)
-    journey_places = ArrayField(models.CharField(max_length=200), blank=True, default=list)
+    name_order = models.CharField(null=True, max_length=300)
+    comment = models.CharField(null=True, max_length=300, default="-")
+    place_start = models.CharField(null=True, max_length=100)
+    place_end = models.CharField(null=True, max_length=100)
     guide_type = models.IntegerField(null=True)
     movement_way = models.IntegerField(null=True)
     numb_of_people = models.IntegerField(null=True)
-    is_with_payment_document = models.BooleanField(default=False)
-    asap = models.BooleanField(default=False)
-    due_date = models.DateTimeField(null=True)
+   # is_with_payment_document = models.BooleanField(default=False)
+   # asap = models.BooleanField(default=False)
+   # due_date = models.DateTimeField(null=True)
+    service_date = models.DateTimeField(null=True)
+    service_time = models.TimeField(null=True)
+    discription = models.CharField(null=True, max_length=300)
+    price = models.IntegerField(null=True)
 
     class Meta:
         db_table = "orders_local"

+ 33 - 0
tables.py

@@ -0,0 +1,33 @@
+import django_tables2 as tables
+from models import *
+from models import OrdersLocal 
+
+class OrderList(tables.Table):
+
+    id = tables.Column(attrs={"td":{"width":"5%"}})
+    
+    name_order = tables.Column(verbose_name=('Экскурсия'))
+    price = tables.Column(verbose_name=('Цена'))
+
+    class Meta:
+        model = OrdersLocal
+        attrs = {"class": "table table-layout-fixed"}
+        exclude = ('rating_id',
+                   'resource_id',
+                   'order_synced', 
+                   'payment_transaction_id', 
+                   'attempts', 
+                   'order_place_type', 
+                   'order_place_start',
+                   #'is_with_payment_document', 
+                   #'asap', 
+                   'comment', 
+                   'guide_type', 
+                   'numb_of_people', 
+                   #'due_date',
+                   'is_global', 
+                   'is_visible', 
+                   'place_start', 
+                   'place_end', 
+                   'movement_way', 
+                   'discription')

+ 15 - 0
templates/webservice_running/order_list.html

@@ -0,0 +1,15 @@
+{% extends 'SharixAdmin/index.html' %}
+{% load render_table from django_tables2 %}
+
+
+{% block contenthome %}
+    <h1 class="mainHeader">{{ title }}</h1>
+    <p class="description_service">Список всех сделанных пользователями заказов, их статус и дата оформления. 
+      Здесь также доступна информация о стоимости каждого заказа. Пользователи могут отслеживать статус своих заказов.</p>
+    <div class="container text-center mt-2">
+      {% render_table table %}
+    </div>
+    <div class="container text-end mt-2">
+      <a class="btn btn-primary" id="bord" href="{% url 'webservice_running:order_reg' %}">Добавить</a>
+    </div>
+{% endblock contenthome %}

+ 5 - 2
urls.py

@@ -1,7 +1,9 @@
-from webservice_running.apiviews import *
+from apiviews import *
 from rest_framework import routers
 from django.urls import path, include, re_path
+from django.contrib.auth.decorators import login_required
 from webservice_running import views
+from webservice_running.views import *
 
 app_name = 'webservice_running'
 
@@ -9,7 +11,8 @@ router = routers.DefaultRouter()
 router.register(r'webservice', OrdersLocalMVS)
 
 urlpatterns = [
-    path('order_reg/', views.order_reg, name="order_reg"),
+    path('order_list/', login_required(OrdersListView.as_view()), name="order_list"),
+    path('order_reg/', login_required(OrderReg.as_view()), name="order_reg"),
     path('', views.registration, name="registration"),
     path('api/', include(router.urls), name="webservice_running_api"),
 ]

+ 54 - 10
views.py

@@ -1,21 +1,65 @@
 from django.urls import reverse_lazy
 import requests
+from webservice_running.models import OrdersLocal
 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 django.shortcuts import redirect, render
+from django.contrib.auth.mixins import UserPassesTestMixin
+from django_tables2 import SingleTableView
+from django.urls import reverse
+from django.views.generic.edit import UpdateView, CreateView, DeleteView
+from webservice_running.tables import OrderList
 
-def order_reg(request):
-    if request.method == 'POST':
-      form = OrderRegForm(request.POST)
-      if form.is_valid():
-        data = request.POST
-        responce = requests.post(f'{API_URL}/webservice/api/webservice/', data = data, headers=api.headers)
-        return HttpResponse(responce.text)
-    else:
-      form = OrderRegForm()
-    return render(request, 'webservice_running/order_reg.html', {'form': form})
+
+class OrderReg(CreateView):
+    model = OrdersLocal
+    form_class = OrderRegForm
+    template_name = "webservice_running/order_reg.html"
+
+    def get_context_data(self, **kwargs):
+
+        context = super().get_context_data(**kwargs)
+        context.update({
+            'title': ('Заявка на экскурсию'),
+            'object': self.object,
+            "current_page": "order_reg"
+        })
+        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_reg')
+
+    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:
+            return True
+        return False
+
+class OrdersListView(UserPassesTestMixin, SingleTableView):
+    table_class = OrderList
+    queryset = OrdersLocal.objects.all()
+    template_name = 'webservice_running/order_list.html'
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context.update({
+            'title': 'Мои заказы',
+            'object_list': context['object_list'],
+            "current_page": "order_list"
+        })
+        return context
+    
+    def test_func(self) -> bool or None:
+        group_names = ('PROVIDER')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user:
+            return True
+        return False
 
 def registration(request):
     if request.method == 'POST':