Răsfoiți Sursa

Добавила страницы о ресурсах и партнерах

sayapinavalentina 1 an în urmă
părinte
comite
016bf68ef4

+ 43 - 1
SharixAdmin/tables.py

@@ -1,4 +1,5 @@
 import django_tables2 as tables
+from metaservicesynced.models import *
 from .models import *
 from django.utils.html import format_html
 
@@ -20,9 +21,50 @@ class TransactionsWalletTable(tables.Table):
                    "transaction_type",
                    "doc_num",
                    "service_id")
-
     def render_name_operation(self, value, record):
         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%"}})
+   
+    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
+    class Meta:
+        model = Company
+        attrs = {"class": "table table-layout-fixed"}
+        exclude = ('inn','kpp','ogrn', 'bank_name', 
+                   'bik', 'ks', 'rs', 
+                   'address', 'requirements', 
+                   'id_metaservice', 'is_global', 'is_visible', 'ticket_status')
+
+    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-partners-id="{}">', record.id)
+        else:
+            return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-partners-id="{}">', record.id)
+
+class ResourceTable(tables.Table):
+
+    id = tables.Column(verbose_name='ID', attrs={"td":{"width":"5%"}})
+    #В user_id ссылка LinkColumn на страницу Аси "Информация о партнере" страница partner_information_form
+    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
+    class Meta:
+        model = Resource
+        attrs = {"class": "table table-layout-fixed"}
+        exclude = ('type_id','requirements','ticket_status', 'id_metaservice', 
+                   '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-resource-id="{}">', record.id)
+        else:
+            return format_html('<input class="form-check-input status-toggle" type="checkbox" id="flexCheckDefault" data-resource-id="{}">', record.id)
 
     

+ 38 - 0
SharixAdmin/templates/SharixAdmin/partners.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 partners_id = $(this).data('partners-id');
+        var new_status = $(this).prop('checked') ? 'active' : 'deactivated';
+        $.ajax({
+          url: '{% url "partners/change_status" %}',
+          type: 'POST',
+          data: {
+            'partners_id': partners_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 %}

+ 38 - 0
SharixAdmin/templates/SharixAdmin/resource.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 resource_id = $(this).data('resource-id');
+        var new_status = $(this).prop('checked') ? 'active' : 'deactivated';
+        $.ajax({
+          url: '{% url "resource/change_status" %}',
+          type: 'POST',
+          data: {
+            'resource_id': resource_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 %}

+ 6 - 0
SharixAdmin/urls.py

@@ -19,6 +19,12 @@ urlpatterns = [
     path('logout/', logout_view, name='logoutweb'),
     path('balance/', balance, name='balance'),
     path('test/', testPage, name='test-page'),
+   
+    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'),
     
     #path('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),

+ 54 - 2
SharixAdmin/views.py

@@ -1,7 +1,7 @@
 
 import json
 from django.shortcuts import render
-from django.http import HttpResponseRedirect, HttpResponse
+from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
 from django.contrib.auth.views import LoginView
 from django.urls import reverse_lazy, resolve, reverse
 from django.contrib.auth.decorators import login_required
@@ -9,6 +9,7 @@ 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
 # Create your views here.
@@ -103,6 +104,8 @@ menu = [
     {'title':'Сотрудничество',          'link':'test-page', 'sel':'sotrud'},
     {'title':'Техподдержка',            'link':'test-page', 'sel':'gear'},
     {'title':'Мои заявки',              'link':'tickets', 'sel':'tikets'},
+     {'title':'Партнеры',            'link':'partners', 'sel':'people'},
+    {'title':'Ресурсы',            'link':'resource', 'sel':'sotrud'},
 ]
 
 def get_context(request, page_context) -> dict:
@@ -114,8 +117,57 @@ 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()
+    template_name = 'SharixAdmin/partners.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
+    
+class ResourceListView(SingleTableView):
+    table_class =  ResourceTable
+    queryset = Resource.objects.all()
+    template_name = 'SharixAdmin/resource.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_partners_status(request):
+    if request.method == 'POST':
+        partners_id = request.POST.get('partners_id')
+        new_status = request.POST.get('new_status')
+        
+        partners = Company.objects.get(pk=partners_id)
+        partners.status = new_status
+        partners.save()
+        return JsonResponse({'status': 'success'})
+    else:
+        return JsonResponse({'status': 'error'})
 
-
+@login_required
+def change_resource_status(request):
+    if request.method == 'POST':
+        resource_id = request.POST.get('resource_id')
+        new_status = request.POST.get('new_status')
+        
+        resource = Resource.objects.get(pk=resource_id)
+        resource.status = new_status
+        resource.save()
+        return JsonResponse({'status': 'success'})
+    else:
+        return JsonResponse({'status': 'error'})
 
 #Shema views
 @login_required

+ 0 - 26
core/config_template.py

@@ -1,26 +0,0 @@
-#Create file config.py with this setting or rename this file to config.py
-
-#BASE
-DEBUG=True
-SECRET_KEY='secret-key(absolutely any character)'
-ALLOWED_HOSTS = ['127.0.0.1']
-CSRF_TRUSTED_ORIGINS = []
-
-#DATABSE
-DB_NAME=None
-DB_USER=None
-DB_PASSWORD=None
-DB_HOST=None
-
-#GUNICORN
-BIND = "127.0.0.1:8000"
-WORKERS = 2
-THREADS = 4
-
-#STATIC
-from pathlib import Path
-import os
-BASE_DIR = Path(__file__).resolve().parent.parent
-STATIC_URL = '/static/'
-STATICFILES_DIRS = [BASE_DIR / "SharixAdmin/static/", BASE_DIR / "tickets/static/"]
-STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")