Parcourir la source

Add page become_partner_form

misha il y a 10 mois
Parent
commit
ec14933fa9

+ 33 - 0
SharixAdmin/forms.py

@@ -168,6 +168,39 @@ class PartnerInformationCreateForm(forms.ModelForm):
             'repr_id': forms.Select(attrs={'class': 'form-select'}),
         }
 
+class BecomePartnerUpdateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(BecomePartnerUpdateForm, 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 = ['repr_id', 'ticket_status', 'status', 'id_metaservice', 'requirements' ]
+        widgets = {
+            'description': forms.Select(attrs={'class': 'form-select'}),
+            'repr_id': forms.Select(attrs={'class': 'form-select'}),
+        }
+
+
+class BecomePartnerCreateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(BecomePartnerCreateForm, self).__init__(*args, **kwargs)       
+        for field in iter(self.fields):
+            if 'class' not in self.fields[field].widget.attrs:
+                self.fields[field].widget.attrs.update({'class':'form-control'})
+   
+    # legal_name = forms.Fi()
+    class Meta:
+        model = Company
+        fields = ['repr_id', 'ticket_status', 'status', 'id_metaservice', 'requirements' ]
+        widgets = {
+            'description': forms.Select(attrs={'class': 'form-select'}),
+            'repr_id': forms.Select(attrs={'class': 'form-select'}),
+        }
+
 
         #     username = forms.CharField(label="Номер телефона",
         # widget=forms.TextInput(attrs={'class':'form-control'}))

+ 2 - 1
SharixAdmin/groups.py

@@ -17,7 +17,8 @@ def create_groups(sender, **kwargs):
     Group.objects.get_or_create(name='GUEST')
     Group.objects.get_or_create(name='CLIENT')
     Group.objects.get_or_create(name='PROVIDER')
-    
+    Group.objects.get_or_create(name='COOPERATION')    
+    Group.objects.get_or_create(name='BECOME-PARTNER')    
 
 
 # Функция позволяющая определить принадлежность к группе, перенаправляет на авторизацию

+ 47 - 0
SharixAdmin/tables.py

@@ -2,8 +2,55 @@ import django_tables2 as tables
 from metaservicesynced.models import *
 from .models import *
 from django.utils.html import format_html
+from django.http import HttpResponse
 from metaservicesynced.models import *
 
+class CooperationTable(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 become_partnerTable(tables.Table):
+    id = tables.Column(verbose_name='айди', attrs={"td":{"width":"20%"}})
+    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 TransactionsWalletTable(tables.Table):
     # id = tables.Column(order_by=True)

+ 13 - 2
SharixAdmin/urls.py

@@ -12,7 +12,8 @@ router.register(r'sharix-users', SharixUserMVS)
 router.register(r'group', GroupMVS)
 
 urlpatterns = [
-    #path('auth/', LoginSharix.as_view(), name='auth'),
+    #path('auth/', LoginSharix.as_view(), name='auth')
+
     path('accounts/login/', LoginSharix.as_view(), name='authweb'),
     path('', index, name='home'),
     path('transactions/', transactions, name='trans'),
@@ -20,7 +21,13 @@ urlpatterns = [
     path('logout/', logout_view, name='logoutweb'),
     path('balance/', balance, name='balance'),
     path('test/', testPage, name='test-page'),
-   
+
+    path('cooperation/', login_required(CooperationListView.as_view()), name='cooperation'),
+    path('cooperation/change_status/', change_cooperation_status, name='cooperation/change_status'),
+
+    path('become_partner/', login_required(become_partnerListView.as_view()), name='become_partner'),
+    path('become_partner/change_status/', change_become_partner_status, name='become_partner/change_status'),
+
     path('partners/', login_required(PartnersListView.as_view()), name='partners'),
     path('partners/change_status/', change_partners_status, name='partners/change_status'),
 
@@ -30,6 +37,7 @@ urlpatterns = [
     path('provider/', login_required(ProviderListView.as_view()), name='provider'),
     path('provider/change_status/', change_provider_status, name='provider/change_status'),
 
+
     path('service_tariff/', login_required(ServiceTariffListView.as_view()), name='service_tariff'),
     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/'),
@@ -48,6 +56,9 @@ urlpatterns = [
     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('become_partner_form/add/', login_required(BecomePartnerCreate.as_view()), name='become_partner_form/add/'),
+    path('become_partner_form/edit/<int:pk>', login_required(BecomePartnerUpdateView.as_view()), name='become_partner_form/edit/'),
+
     path('user_information', login_required(UserListView.as_view()), name='user_information'),
 
     path('api/v1/auth/', include('djoser.urls.authtoken'), name="api-auth"),

+ 3 - 0
SharixAdmin/views/__init__.py

@@ -7,6 +7,9 @@ from .service_tariff import *
 from .service_info import *
 from .resource import *
 from .partners import *
+from .cooperation import *
+from .become_partner_form import *
+from .become_partner import *
 from .partner_info import *
 from .provider import *
 from .login import *

+ 42 - 0
SharixAdmin/views/become_partner.py

@@ -0,0 +1,42 @@
+from django_tables2 import SingleTableView
+from django.contrib.auth.mixins import UserPassesTestMixin
+from SharixAdmin.groups import group_required
+from SharixAdmin.tables import become_partnerTable
+from django.contrib.auth.decorators import login_required
+from metaservicesynced.models import Company
+from SharixAdmin.views.context import get_context
+from django.http import JsonResponse
+from django.http import HttpResponse
+
+
+class become_partnerListView(UserPassesTestMixin, SingleTableView):
+    table_class = become_partnerTable
+    queryset = Company.objects.all()
+    template_name = 'SharixAdmin/become_partner.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
+    
+    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
+
+@login_required
+@group_required('METASERVICE-ADMIN')
+def change_become_partner_status(request):
+    if request.method == 'POST':
+        become_partner_id = request.POST.get('become_partner_id')
+        new_status = request.POST.get('new_status')
+        become_partner = Company.objects.get(pk=become_partner_id)
+        become_partner.status = new_status
+        coopertion.save()
+        return JsonResponse({'status': 'success'})
+    else:
+        return JsonResponse({'status': 'error'})

+ 59 - 0
SharixAdmin/views/become_partner_form.py

@@ -0,0 +1,59 @@
+from django.shortcuts import render
+from SharixAdmin.forms import BecomePartnerCreateForm, BecomePartnerUpdateForm
+from SharixAdmin.groups import group_required
+from metaservicesynced.models import Company
+from django.contrib.auth.mixins import UserPassesTestMixin
+from django.views.generic.edit import UpdateView, CreateView
+from SharixAdmin.views.context import get_context
+from django.urls import reverse
+
+class BecomePartnerCreate(UserPassesTestMixin, CreateView):
+    model = Company
+    form_class = BecomePartnerCreateForm
+    template_name = "SharixAdmin/become_partner_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')
+    
+    def test_func(self) -> bool or None:
+        group_names = ('PARTNER-ADMIN')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
+            return True
+        return False
+    
+class BecomePartnerUpdateView(UserPassesTestMixin, UpdateView):
+    model = Company
+    form_class = BecomePartnerUpdateForm
+    template_name = "SharixAdmin/become_partner_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')
+    
+    def test_func(self) -> bool or None:
+        group_names = ('PARTNER-ADMIN')
+        if bool(self.request.user.groups.filter(name=group_names)) or self.request.user.is_superuser:
+            return True
+        return False
+    
+def become_partner(request):
+    context = get_context(request, {
+        'title':'Информация о партнере',
+        })
+    
+    return render(request, 'SharixAdmin/become_partner_form.html', context)

+ 4 - 1
SharixAdmin/views/context.py

@@ -8,7 +8,8 @@ menu = [
     {'title':'Личная информация',       'link':'test-page', 'sel':'person'},
     {'title':'Управление сервисами',    'link':'test-page', 'sel':'hdd-network'},
     {'title':'Мои связи',               'link':'test-page', 'sel':'people'},
-    {'title':'Сотрудничество',          'link':'test-page', 'sel':'sotrud'},
+#    {'title':'Сотрудничество',          'link':'cooperation', 'sel':'sotrud'},
+#    {'title':'Стать партнером',          'link':'become_partner', 'sel':'sotrud'},
     {'title':'Техподдержка',            'link':'test-page', 'sel':'gear'},
     {'title':'Мои заявки',              'link':'tickets', 'sel':'tikets'},
     {'title':'Исполнители',             'link':'provider', 'sel':'people', 
@@ -25,6 +26,8 @@ menu = [
      'roles':['METASERVICE-ADMIN']},
     {'title':'Информация о партнере',   'link':'partner_information/add/', 'sel':'person',
      'roles':['PARTNER-ADMIN']},
+    {'title':'Форма стать  партнером',   'link':'become_partner_form/add/', 'sel':'person',
+     'roles':['PARTNER-ADMIN']},
     {'title':'Тарифы',                  'link':'service', 'sel':'tikets',
      'roles':['PARTNER-ADMIN']},
     {'title':'Управление пользователями','link':'user_information', 'sel':'person'}

+ 40 - 0
SharixAdmin/views/cooperation.py

@@ -0,0 +1,40 @@
+from django_tables2 import SingleTableView
+from django.contrib.auth.mixins import UserPassesTestMixin
+from SharixAdmin.groups import group_required
+from SharixAdmin.tables import CooperationTable
+from django.contrib.auth.decorators import login_required
+from metaservicesynced.models import Company
+from SharixAdmin.views.context import get_context
+from django.http import JsonResponse
+
+class CooperationListView(UserPassesTestMixin, SingleTableView):
+    table_class = CooperationTable
+    queryset = Company.objects.all()
+    template_name = 'SharixAdmin/cooperation.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
+    
+    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
+
+@login_required
+@group_required('METASERVICE-ADMIN')
+def change_cooperation_status(request):
+    if request.method == 'POST':
+        cooperation_id = request.POST.get('cooperation_id')
+        new_status = request.POST.get('new_status')
+        cooperation = Company.objects.get(pk=cooperation_id)
+        cooperation.status = new_status
+        coopertion.save()
+        return JsonResponse({'status': 'success'})
+    else:
+        return JsonResponse({'status': 'error'})

+ 1 - 0
SharixAdmin/views/partners.py

@@ -6,6 +6,7 @@ from django.contrib.auth.decorators import login_required
 from metaservicesynced.models import Company
 from SharixAdmin.views.context import get_context
 from django.http import JsonResponse
+from django.http import HttpResponse
 
 class PartnersListView(UserPassesTestMixin, SingleTableView):
     table_class = PartnersTable