Explorar el Código

не сделано: форма содержит не правильные поля; сделано: url, view, forms, template

skavronsky hace 1 año
padre
commit
11e186c4c3

+ 48 - 1
SharixAdmin/forms.py

@@ -1,7 +1,7 @@
 from django.contrib.auth.forms import AuthenticationForm
 from .models import SharixUser
 from django import forms
-from metaservicesynced.models import ServiceType
+from metaservicesynced.models import ServiceType, Service
 
 class LoginUserForm(AuthenticationForm):
 
@@ -51,3 +51,50 @@ class ServiceTypeCreateForm(forms.ModelForm):
         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'}),
+        }

+ 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 %}

+ 3 - 1
SharixAdmin/urls.py

@@ -19,13 +19,15 @@ urlpatterns = [
     path('logout/', logout_view, name='logoutweb'),
     path('balance/', balance, name='balance'),
     path('test/', testPage, name='test-page'),
-    path('servicetype/', servicetype, name='servicetype'),
     
     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'),

+ 34 - 0
SharixAdmin/views.py

@@ -118,6 +118,7 @@ menu = [
     {'title':'Техподдержка',            'link':'test-page', 'sel':'gear'},
     {'title':'Мои заявки',              'link':'tickets', 'sel':'tikets'},
     {'title':'Услуги сервиса',          'link':'service_type', 'sel':'hdd-network'},
+    {'title':'Информация о сервисе',    'link':'partner_information/add/', 'sel':'hdd-network'},
 ]
 
 def get_context(request, page_context) -> dict:
@@ -163,6 +164,7 @@ class ServiceTypeCreate(CreateView):
     def get_success_url(self):
         return reverse('service_type')
     
+
 class ServiceTypeDelete(DeleteView):
     model = ServiceType
     template_name = "SharixAdmin/service_type_delete.html"
@@ -194,7 +196,39 @@ class ServiceTypeListView(SingleTableView):
         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