ソースを参照

update forms and views

kateshev14 5 ヶ月 前
コミット
1a12052237
4 ファイル変更67 行追加0 行削除
  1. 5 0
      tables.py
  2. 14 0
      templates/webservice_running/order_reg_delete.html
  3. 2 0
      urls.py
  4. 46 0
      views.py

+ 5 - 0
tables.py

@@ -8,6 +8,11 @@ class OrderList(tables.Table):
     
     name_order = tables.Column(verbose_name=('Экскурсия'))
     price = tables.Column(verbose_name=('Цена'))
+    edit = tables.LinkColumn('order_reg/edit/', verbose_name='', orderable=False, text = "E",
+        args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"edit_col"}})
+    delete = tables.LinkColumn('order_reg/delete/', verbose_name='', orderable=False, text = "D",
+        args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"class":"delete_col"}})
+
 
     class Meta:
         model = OrdersLocal

+ 14 - 0
templates/webservice_running/order_reg_delete.html

@@ -0,0 +1,14 @@
+{% extends 'SharixAdmin/index.html' %}
+{% load i18n %}
+
+{% block contenthome %}
+<form method="post">
+    {% csrf_token %}
+    <div class="container m-2">
+        <p>{% blocktrans %}Are you sure you want to delete \"%(object.caption)s\"?{% endblocktrans %}</p>
+    </div>
+    <div class="text-center mt-2 mb-5">
+        <input class="btn btn-primary center" type="submit" name="apply" value="{% trans 'Delete' %}"/>
+    </div>
+</form>
+{% endblock %}

+ 2 - 0
urls.py

@@ -11,6 +11,8 @@ router = routers.DefaultRouter()
 router.register(r'webservice', OrdersLocalMVS)
 
 urlpatterns = [
+    path('order_reg/edit/<int:pk>', login_required(OrderRegUpdateView.as_view()), name='order_reg/edit/'),
+    path('order_reg/delete/<int:pk>', login_required(OrderRegDelete.as_view()), name='order_reg/delete/'),
     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"),

+ 46 - 0
views.py

@@ -41,6 +41,52 @@ class OrderReg(CreateView):
             return True
         return False
 
+class OrderRegUpdateView(UserPassesTestMixin, UpdateView):
+    model = OrdersLocal
+    form_class = OrderRegForm
+    template_name = "SharixAdmin/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 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
+    
+    def get_success_url(self):
+        return reverse('order_reg')
+
+class OrderRegDelete(UserPassesTestMixin, DeleteView):
+    model = OrdersLocal
+    template_name = "SharixAdmin/order_reg_delete.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 get_success_url(self):
+        return reverse('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.is_superuser:
+            return True
+        return False
+
 class OrdersListView(UserPassesTestMixin, SingleTableView):
     table_class = OrderList
     queryset = OrdersLocal.objects.all()