Evgeny Polivanov 1 год назад
Родитель
Сommit
b6a33a165c

+ 32 - 2
SharixAdmin/forms.py

@@ -1,9 +1,11 @@
 from django.contrib.auth.forms import AuthenticationForm
 
-from metaservicesynced.models import Service
+from metaservicesynced.models import *
 from .models import SharixUser
 from django import forms
 from metaservicesynced.models import ServiceType, Service
+from .models import SharixUser
+from django import forms
 
 class LoginUserForm(AuthenticationForm):
 
@@ -111,12 +113,12 @@ class ServiceInformationCreateForm(forms.ModelForm):
     
     def __init__(self, *args, **kwargs):
         super(ServiceInformationCreateForm, self).__init__(*args, **kwargs)
-
         # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
         for field in iter(self.fields):
             if 'class' not in self.fields[field].widget.attrs:
                 self.fields[field].widget.attrs.update({'class':'form-control'})
 
+
     class Meta:
         model = Service
         fields = ["servicetype_id", "id_provider"]
@@ -129,4 +131,32 @@ class ServiceInformationCreateForm(forms.ModelForm):
             #'repr_id': forms.Select(attrs={'class': 'form-select'}),
             # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
             # 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
+        }
+
+class PartnerInformationUpdateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(PartnerInformationUpdateForm, self).__init__(*args, **kwargs)
+        # Добавляет стиль бутстрапа form-control всем полям таблицы если у них нет своих стилей
+        for field in iter(self.fields):
+            if 'class' not in self.fields[field].widget.attrs:
+                self.fields[field].widget.attrs.update({'class':'form-control'})
+
+    class Meta:
+        model = Company
+        fields = ['legal_name', 'address', 'repr_id' ]
+        widgets = {
+            'description': forms.Select(attrs={'class': 'form-select'}),
+            'repr_id': forms.Select(attrs={'class': 'form-select'}),
+        }
+        
+class PartnerInformationCreateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(PartnerInformationCreateForm, self).__init__(*args, **kwargs)          
+    class Meta:
+        model = Company
+        fields = ['legal_name', 'address', 'repr_id']
+        
+        widgets = {
+            'description': forms.Select(attrs={'class': 'form-select'}),
+            'repr_id': forms.Select(attrs={'class': 'form-select'}),
         }

+ 30 - 0
SharixAdmin/tables.py

@@ -4,6 +4,7 @@ from .models import *
 from django.utils.html import format_html
 from metaservicesynced.models import *
 
+
 class TransactionsWalletTable(tables.Table):
     # id = tables.Column(order_by=True)
     id = tables.Column(verbose_name='#', orderable=False,                                       attrs={"td":{"width":"5%"}})
@@ -71,6 +72,7 @@ class ProviderTable(tables.Table):
 
     id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
     user_id = tables.Column(accessor='user_id.full_name', order_by=('user_id.first_name', 'user_id.last_name'), verbose_name='ФИО', attrs={"td":{"width":"15%"}})
+
     status = tables.Column(verbose_name='Статус', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}}) 
     check = tables.BooleanColumn(verbose_name='', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
     paginate_by = 10
@@ -129,4 +131,32 @@ class ServiceTypeTable(tables.Table):
     def render_delete(self, value, record):
         return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">Удалить</a>')
         
+    def render_name_operation(self, value, record):
+        return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
+   
+class ServiceTable(tables.Table):
+
+    id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
+    servicetype_id = tables.Column(verbose_name='Описание услуги (сервиса)', accessor = 'servicetype_id.caption',
+        attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    
+    # description = tables.Column(verbose_name='Название тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    # description = tables.Column(verbose_name='Описание строки тарифов', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    # price_type = tables.Column(verbose_name='Тип тарифа', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    
+    price_km = tables.Column(verbose_name='Стоимость км.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    price_min = tables.Column(verbose_name='Стоимость мин.', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+    price_amount = tables.Column(verbose_name='Стоимость услуги', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
+
+    class Meta:
+        model = Service
+        attrs = {"class": "table table-layout-fixed"}
+        exclude = ('resource_id', 'requirements', 'id_provider',
+                   'id_metaservice', 'price_alg', 'service_status', 'ticket_status',
+                    'is_global', 'is_visible')
 
+    def render_check(self, value, record):
+        if record.status == 'active':
+            return format_html('<input class="form-check-input status-toggle" checked type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)
+        else:
+            return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-service-id="{}">', record.id)     

+ 0 - 1
SharixAdmin/templates/SharixAdmin/index.html

@@ -57,7 +57,6 @@
                   </li>
                   {% endif%}
                   {% endfor %}
-                  
                 </ul>
                 <hr>
                 <div class="dropdown">

+ 21 - 0
SharixAdmin/templates/SharixAdmin/partner_information_form.html

@@ -0,0 +1,21 @@
+{% extends 'SharixAdmin/index.html' %}
+
+{% block contenthome %}
+<h1 class="mb-4">{{ title }}</h1>
+<form method="post" style="overflow: auto">
+    {% csrf_token %}
+    <div class="container m-2">
+        {% for field in form %}
+        {{field.errors}}
+        <div class="row">
+            {{field.label_tag}}
+            {{field}}
+            <p class="fs-6 fst-italic">{{field.help_text|truncatewords:20}}</p>
+        </div>
+        {% endfor %}
+    </div>
+    <div class="text-center mt-2 mb-5">
+        <input class="btn btn-primary center" type="submit" name="apply" value="Отправить" />
+    </div>
+</form>
+{% endblock %}

+ 38 - 0
SharixAdmin/templates/SharixAdmin/service.html

@@ -0,0 +1,38 @@
+{% extends 'SharixAdmin/index.html' %}
+{% load render_table from django_tables2 %}
+
+{% block contenthome %}
+    <h1 >{{ title }}</h1>
+
+    <div class="container text-center mt-2">
+      {% render_table table %}
+    </div>
+    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
+    <script>
+      // Запрос на изменения статуса исполнителя
+      $('.status-toggle').change(function() {
+        var service_id = $(this).data('service-id');
+        var new_status = $(this).prop('checked') ? 'active' : 'deactivated';
+        $.ajax({
+          url: '{% url "service/change_status" %}',
+          type: 'POST',
+          data: {
+            'service_id': service_id,
+            'new_status': new_status,
+            'csrfmiddlewaretoken': '{{ csrf_token }}'
+          },
+          success: function(response) {
+            var scrollTop = window.pageYOffset;
+            location.reload();
+            window.scrollTo(0, scrollTop);
+          },
+          error: function(xhr, status, error) {
+            console.log(xhr.responseText);
+          }
+        });
+      });
+    </script>
+    
+
+    
+{% endblock contenthome %}

+ 2 - 3
SharixAdmin/templates/SharixAdmin/transactions.html

@@ -10,6 +10,5 @@
         <button class="btn btn-outline-success" type="submit">Search</button>
       </form>
       {% comment %} {% render_table  table %} {% endcomment %}
-      
-    
-{% endblock contenthome %} 
+{% endblock contenthome %} 
+

+ 6 - 0
SharixAdmin/urls.py

@@ -43,6 +43,12 @@ urlpatterns = [
 
 
 
+    
+    path('service/', ServiceListView.as_view(), name='service'),
+    path('service/change_status/', change_service_status, name='service/change_status'),
+    
+    path('partner_information/add/', login_required(PartnerInformationCreate.as_view()), name='partner_information/add/'),
+    path('partner_information/edit/<int:pk>', login_required(PartnerInformationUpdateView.as_view()), name='partner_information/edit/'),
     #path('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),
     path('platform/api/', include(router.urls), name="sharix-api"),

+ 71 - 5
SharixAdmin/views.py

@@ -6,19 +6,23 @@ from django.contrib.auth.views import LoginView
 from django.urls import reverse_lazy, resolve, reverse
 from django.contrib.auth.decorators import login_required
 from django_tables2 import SingleTableView
+
+from metaservicesynced.models import *
 from .forms import *
 from SharixAdmin.models import *
 from django.contrib.auth import logout
 from django.db.models import Q
+
 from django_tables2 import SingleTableView
 from .tables import *
 from django import template
 from django.views.generic.edit import UpdateView, CreateView
-from metaservicesynced.models import ServiceType
 from django.core import serializers
 from django_tables2 import SingleTableView
 from django.views.generic.edit import UpdateView, CreateView, DeleteView
 
+
+
 # Create your views here.
 
 
@@ -56,9 +60,6 @@ def servicetype(request):
 
 @login_required
 def trans_id(request, trans_id):
-    
-    
-    
     context = get_context(request, {
         'title':'Услуга'
         })
@@ -127,9 +128,17 @@ menu = [
     {'title':'Ресурсы',                 'link':'resource', 'sel':'sotrud'},
     {'title':'Услуги сервиса',          'link':'service_type', 'sel':'hdd-network'},
     {'title':'Информация о сервисе',    'link':'partner_information/add/', 'sel':'hdd-network'},
-
+    {'title':'Информация о партнере',   'link':'partner_information/add/', 'sel':'person'},
+    {'title':'Тарифы',                  'link':'service', 'sel':'tikets'},
 ]
 
+def partner_information(request):
+    context = get_context(request, {
+        'title':'Информация о партнере',
+        })
+    
+    return render(request, 'SharixAdmin/partner_information.html', context)
+
 def get_context(request, page_context) -> dict:
     base_context = {
         "title":page_context['title'],
@@ -139,6 +148,7 @@ def get_context(request, page_context) -> dict:
     context = dict(list(base_context.items()) + list(page_context.items()))
     return context
 
+
 class PartnersListView(SingleTableView):
     table_class = PartnersTable
     queryset = Company.objects.all()
@@ -278,6 +288,7 @@ def change_partners_status(request):
     else:
         return JsonResponse({'status': 'error'})
 
+
 @login_required
 def change_resource_status(request):
     if request.method == 'POST':
@@ -356,6 +367,29 @@ class ServiceInformationCreate(CreateView):
     def get_success_url(self):
         return reverse('test-page')
 
+class ServiceListView(SingleTableView):
+    table_class = ServiceTable
+    queryset = Service.objects.all()
+    template_name = 'SharixAdmin/service.html'
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context.update(get_context(self.request, {
+            'title': 'Тарифы',
+            'object_list': context['object_list'],
+        }))
+        return context
+    
+@login_required
+def change_service_status(request):
+    if request.method == 'POST':
+        service_id = request.POST.get('service_id')
+        new_status = request.POST.get('new_status')
+        
+        service = Service.objects.get(pk=service_id)
+        service.status = new_status
+        service.save()
+
 #Shema views
 @login_required
 def schema_v3(request):
@@ -363,6 +397,38 @@ def schema_v3(request):
     return render(request, "SharixAdmin/schema.html")
 
 
+class PartnerInformationUpdateView(UpdateView):
+    model = Company
+    form_class = PartnerInformationUpdateForm
+    template_name = "SharixAdmin/partner_information_form.html"
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context.update(get_context(self.request, {
+            'title': 'Информация о партнере',
+            'object': self.object,
+        }))
+        return context
+    
+    def get_success_url(self):
+        return reverse('test-page')
+
+class PartnerInformationCreate(CreateView):
+    model = Company
+    form_class = PartnerInformationCreateForm
+    template_name = "SharixAdmin/partner_information_form.html"
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context.update(get_context(self.request, {
+            'title': 'Информация о партнере',
+            'object': self.object,
+        }))
+        return context
+    
+    def get_success_url(self):
+        return reverse('test-page')
+