Przeglądaj źródła

add vitalii changes

Evgeny Polivanov 1 rok temu
rodzic
commit
abb76d9bed

+ 74 - 0
SharixAdmin/forms.py

@@ -3,6 +3,7 @@ from django.contrib.auth.forms import AuthenticationForm
 from metaservicesynced.models import Service
 from .models import SharixUser
 from django import forms
+from metaservicesynced.models import ServiceType, Service
 
 class LoginUserForm(AuthenticationForm):
 
@@ -16,15 +17,18 @@ class LoginUserForm(AuthenticationForm):
         model = SharixUser
         fields = ['username', 'password']
 
+
 class ServiceTariffUpdateForm(forms.ModelForm):
     def __init__(self, *args, **kwargs):
         super(ServiceTariffUpdateForm, 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 = ['status','ticket_status','servicetype_id','id_provider',
                   'resource_id','requirements','price_alg','price_km','price_min','price_amount','service_status',
@@ -47,6 +51,7 @@ class ServiceTariffCreateForm(forms.ModelForm):
                 self.fields[field].widget.attrs.update({'class':'form-control'})
     
     class Meta:
+
         model = Service
         fields = '__all__'
 
@@ -55,4 +60,73 @@ class ServiceTariffCreateForm(forms.ModelForm):
             'id_provider': forms.Select(attrs={'class': 'form-select'}),
             'resource_id': forms.Select(attrs={'class': 'form-select'}),
             'ticket_status': forms.Select(attrs={'class': 'form-select'}),
+        }
+
+class ServiceTypeUpdateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(ServiceTypeUpdateForm, self).__init__(*args, **kwargs)
+        model = ServiceType
+        fields = ['status','ticket_status','id_metaservice','codename',
+                  'description','requirements','price_type','link_agreement',
+                  'is_global','is_visible']
+        widgets = {
+            'status': forms.TextInput(attrs={'readonly': True}),
+            'ticket_status': forms.TextInput(attrs={'readonly': True}),
+        }
+
+class ServiceTypeCreateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(ServiceTypeCreateForm, self).__init__(*args, **kwargs)
+        model = ServiceType
+        fields = '__all__'
+
+        widgets = {
+            'ticket_status': forms.Select(attrs={'class': 'form-select'}),
+        }
+
+class ServiceInformationUpdateForm(forms.ModelForm):
+
+    def __init__(self, *args, **kwargs):
+        super(ServiceInformationUpdateForm, 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']
+
+        widgets = {
+            # 'status': forms.TextInput(attrs={'readonly': True}),
+            # 'ticket_status': forms.TextInput(attrs={'readonly': True}),
+            
+             'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
+            #'repr_id': forms.Select(attrs={'class': 'form-select'}),
+            # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
+        }
+        
+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"]
+        exclude = ["resource_id"]
+
+        widgets = {
+            #'servicetype_id': forms.CharField(max_length=255)
+            # 'legal_name': forms.TextInput(label = 'Название')
+            # 'servicetype_id': forms.Select(attrs={'class': 'form-select'}),
+            #'repr_id': forms.Select(attrs={'class': 'form-select'}),
+            # 'resource_id': forms.Select(attrs={'class': 'form-select'}),
+            # 'ticket_status': forms.Select(attrs={'class': 'form-select'}),
         }

+ 22 - 2
SharixAdmin/tables.py

@@ -26,7 +26,6 @@ class TransactionsWalletTable(tables.Table):
         return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
         
 class PartnersTable(tables.Table):
-
     id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
     legal_name = tables.Column(verbose_name='Юрлицо', attrs={'th':{'scope':'col'}, "td":{"width":"20%"}})
     repr_id = tables.Column(accessor='repr_id.full_name', order_by=('repr_id.first_name', 'repr_id.last_name'), verbose_name='Ответственный', attrs={"td":{"width":"15%"}})
@@ -109,4 +108,25 @@ class ServiceTariffTable(tables.Table):
         if record.status == 'active':
             return format_html('<input class="form-check-input status-toggle" disabled  checked type="checkbox"')
         else:
-            return format_html('<input class="form-check-input status-toggle" disabled  type="checkbox"')
+            return format_html('<input class="form-check-input status-toggle" disabled  type="checkbox"')
+
+class ServiceTypeTable(tables.Table):
+
+    id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
+    caption = tables.LinkColumn('service_type/edit/', verbose_name='Название услуги', text = lambda record: record.caption,
+        args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"100%"},})
+    deletee = tables.LinkColumn('service_type/delete/', verbose_name='', text = "Удалить",
+        args=[tables.A('pk')], attrs={'th':{'scope':'col'}, "td":{"width":"auto"},})
+    
+    class Meta:
+        model = ServiceType
+        attrs = {"class": "table table-layout-fixed text-start"}
+        exclude = ('codename','description','requirements',
+                   'price_type','status','ticket_status', 
+                   'id_metaservice', 'link_agreement',
+                   'is_global', 'is_visible',)
+
+    def render_delete(self, value, record):
+        return format_html('<a href="/service_type/delete" class="btn btn-outline-danger">Удалить</a>')
+        
+

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

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

+ 25 - 0
SharixAdmin/templates/SharixAdmin/service_information_form.html

@@ -0,0 +1,25 @@
+{% extends 'SharixAdmin/index.html' %}
+
+{% block contenthome %}
+<h1 class="mb-4">{{ title }}</h1>
+{{object.servicetype_id.caption}}
+{{object.id_provider.company_id.address}}
+{{object.id_provider.company_id.repr_id}}
+{{object.servicetype_id.description}}
+<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 %}

+ 48 - 0
SharixAdmin/templates/SharixAdmin/service_type.html

@@ -0,0 +1,48 @@
+{% 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 %}
+
+          {% comment %} {% if table.page %}
+            <nav aria-label="...">
+              <ul class="pagination">
+                {% if table.page.has_previous %}
+                <li class="page-item">
+                  <a class="page-link" href="?page={{ table.page.previous_page_number }}" tabindex="-1">Previous</a>
+                </li>
+                {% else %}
+                <li class="page-item disabled">
+                  <span class="page-link">Previous</span>
+                </li>
+                {% endif %}
+                {% for page in table.page_range %}
+                  {% if page == table.page.number %}
+                  <li class="page-item active">
+                    <span class="page-link">{{ page }} <span class="sr-only">(current)</span></span>
+                  </li>
+                  {% else %}
+                  <li class="page-item">
+                    <a class="page-link" href="?page={{page }}">{{ page }}</a>
+                  </li>
+                  {% endif %}
+                {% endfor %}
+                {% if table.page.has_next %}
+                <li class="page-item">
+                  <a class="page-link" href="?page={{ table.page.next_page_number }}">Next</a>
+                </li>
+                {% else %}
+                <li class="page-item disabled">
+                  <span class="page-link">Next</span>
+                </li>
+                {% endif %}
+              </ul>
+            </nav>
+          {% endif %} {% endcomment %}
+    </div>
+    <div class="container text-end mt-2">
+      <a class="btn btn-primary" href="/service_type/add">Добавить</a>
+    </div>
+{% endblock contenthome %}

+ 14 - 0
SharixAdmin/templates/SharixAdmin/service_type_delete.html

@@ -0,0 +1,14 @@
+{% extends 'SharixAdmin/index.html' %}
+
+{% block contenthome %}
+<h1 class="mb-4">{{ title }}</h1>
+<form method="post">
+    {% csrf_token %}
+    <div class="container m-2">
+        <p>Вы уверены, что хотите удалить "{{ object.caption }}"?</p>
+    </div>
+    <div class="text-center mt-2 mb-5">
+        <input class="btn btn-primary center" type="submit" name="apply" value="Удалить" />
+    </div>
+</form>
+{% endblock %}

+ 21 - 0
SharixAdmin/templates/SharixAdmin/service_type_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 %}

+ 1 - 1
SharixAdmin/templates/SharixAdmin/transactions.html

@@ -12,4 +12,4 @@
       {% comment %} {% render_table  table %} {% endcomment %}
       
     
-{% endblock contenthome %}
+{% endblock contenthome %} 

+ 10 - 1
SharixAdmin/urls.py

@@ -22,7 +22,7 @@ urlpatterns = [
    
     path('partners/', login_required(PartnersListView.as_view()), name='partners'),
     path('partners/change_status/', change_partners_status, name='partners/change_status'),
-    
+
     path('resource/', login_required(ResourceListView.as_view()), name='resource'),
     path('resource/change_status/', change_resource_status, name='resource/change_status'),
     
@@ -33,6 +33,15 @@ urlpatterns = [
     path('service_tariff/add/', login_required(ServiceTariffCreate.as_view()), name='service_tariff/add/'),
     path('service_tariff/edit/<int:pk>', login_required(ServiceTariffUpdateView.as_view()), name='service_tariff/edit/'),
 
+    path('service_type/', login_required(ServiceTypeListView.as_view()), name='service_type'),
+    path('service_type/edit/<int:pk>', login_required(ServiceTypeUpdateView.as_view()), name='service_type/edit/'),
+    path('service_type/add/', login_required(ServiceTypeCreate.as_view()), name='service_type/add/'),
+    path('service_type/delete/<int:pk>', login_required(ServiceTypeDelete.as_view()), name='service_type/delete/'),
+
+    path('service_information/add/', login_required(ServiceInformationCreate.as_view()), name='partner_information/add/'),
+    path('service_information/edit/<int:pk>', login_required(ServiceInformationUpdateView.as_view()), name='partner_information/edit/'),
+
+
 
     #path('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),

+ 111 - 2
SharixAdmin/views.py

@@ -14,6 +14,11 @@ 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.
 
 
@@ -39,6 +44,16 @@ def transactions(request):
         
     return render(request, 'SharixAdmin/transactions.html', context)
 
+@login_required
+def servicetype(request):
+    service_types = ServiceType.objects.all()
+    context = get_context(request, {
+        'title':'Услуги сервиса',
+        'service_types':service_types,
+        })
+        
+    return render(request, 'SharixAdmin/servicetype.html', context)
+
 @login_required
 def trans_id(request, trans_id):
     
@@ -108,8 +123,10 @@ menu = [
     {'title':'Мои заявки',              'link':'tickets', 'sel':'tikets'},
     {'title':'Исполнители',             'link':'provider', 'sel':'people'},
     {'title':'Тарифы услуг',            'link':'service_tariff', 'sel':'person'},
-    {'title':'Партнеры',            'link':'partners', 'sel':'people'},
-    {'title':'Ресурсы',            'link':'resource', 'sel':'sotrud'},
+    {'title':'Партнеры',                'link':'partners', 'sel':'people'},
+    {'title':'Ресурсы',                 'link':'resource', 'sel':'sotrud'},
+    {'title':'Услуги сервиса',          'link':'service_type', 'sel':'hdd-network'},
+    {'title':'Информация о сервисе',    'link':'partner_information/add/', 'sel':'hdd-network'},
 
 ]
 
@@ -198,7 +215,18 @@ class ServiceTariffListView(SingleTableView):
     queryset = Service.objects.all()
     template_name = 'SharixAdmin/service_tariff.html'
     # paginate_by = 2
+    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
 
+class ServiceTypeUpdateView(UpdateView):
+    model = ServiceType
+    form_class = ServiceTypeUpdateForm
+    template_name = "SharixAdmin/service_type_form.html"
 
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
@@ -220,6 +248,22 @@ class ResourceListView(SingleTableView):
             'object_list': context['object_list'],
         }))
         return context
+
+class ServiceTypeCreate(CreateView):
+    model = ServiceType
+    form_class = ServiceTypeCreateForm
+    template_name = "SharixAdmin/service_type_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('service_type')
     
 @login_required
 def change_partners_status(request):
@@ -246,6 +290,71 @@ def change_resource_status(request):
         return JsonResponse({'status': 'success'})
     else:
         return JsonResponse({'status': 'error'})
+    
+
+class ServiceTypeDelete(DeleteView):
+    model = ServiceType
+    template_name = "SharixAdmin/service_type_delete.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('service_type')
+
+
+class ServiceTypeListView(SingleTableView):
+    table_class = ServiceTypeTable
+    queryset = ServiceType.objects.all()
+    template_name = 'SharixAdmin/service_type.html'
+    # paginate_by = 2
+
+    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
+
+
+class ServiceInformationUpdateView(UpdateView):
+    model = Service
+    form_class = ServiceInformationUpdateForm
+    template_name = "SharixAdmin/service_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 ServiceInformationCreate(CreateView):
+    model = Service
+    form_class = ServiceInformationCreateForm
+    template_name = "SharixAdmin/service_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')
 
 #Shema views
 @login_required