Jelajahi Sumber

Услуг сервиса

skavronsky 1 tahun lalu
induk
melakukan
6854a22a45

+ 39 - 1
SharixAdmin/forms.py

@@ -1,6 +1,7 @@
 from django.contrib.auth.forms import AuthenticationForm
 from .models import SharixUser
 from django import forms
+from metaservicesynced.models import ServiceType
 
 class LoginUserForm(AuthenticationForm):
 
@@ -12,4 +13,41 @@ class LoginUserForm(AuthenticationForm):
 
     class Meta:
         model = SharixUser
-        fields = ['username', 'password']
+        fields = ['username', 'password']
+
+
+class ServiceTypeUpdateForm(forms.ModelForm):
+    def __init__(self, *args, **kwargs):
+        super(ServiceTypeUpdateForm, 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 = 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)
+        # Добавляет стиль бутстрапа 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 = ServiceType
+        fields = '__all__'
+
+        widgets = {
+            'ticket_status': forms.Select(attrs={'class': 'form-select'}),
+        }

+ 20 - 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
 
@@ -25,4 +26,22 @@ class TransactionsWalletTable(tables.Table):
         return format_html("<a href='{}'>{}</a>", record.get_absolute_url(), value)
         
 
-    
+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>')
+        

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

+ 0 - 329
SharixAdmin/templates/SharixAdmin/servicetype copy.html

@@ -1,329 +0,0 @@
-{% extends 'SharixAdmin/index.html' %} {% block contenthome %}
-<div class="d-flex justify-content-between align-items-center">
-  <h1>{{ title }}</h1>
-  <button type="button" class="btn btn-outline-success" data-bs-target="#modal-create" data-bs-toggle="modal"> Добавить услугу </button>
-</div>
-<div class="table-responsive">
-  <table class="table table-striped">
-    <thead>
-      <tr>
-        <th>ID</th>
-        <th colspan="2">Название</th>
-      </tr>
-    </thead>
-    <tbody>
-      {% comment %} <tr>
-        <th scope="row">1</th>
-        <td class="w-100">Larry the Bird</td>
-        <td>
-          <div class="btn-group">
-            <button
-              class="btn btn-outline-info"
-              data-bs-target="#modal-edit"
-              data-bs-toggle="modal"
-            >
-              Изменить
-            </button>
-            <button
-              class="btn btn-outline-danger"
-              data-bs-target="#modal-confirm-delete"
-              data-bs-toggle="modal"
-            >
-              Удалить
-            </button>
-          </div>
-        </td>
-      </tr> {% endcomment %}
-
-      {% for service_type in service_types %}
-      <tr>
-        <th scope="row">{{service_type.id}}</th>
-        <td class="w-100">{{service_type.caption}}</td>
-        <td>
-          <div class="btn-group">
-            <button
-              class="btn btn-outline-info"
-              data-bs-target="#modal-edit"
-              data-bs-toggle="modal"
-            >
-              Изменить
-            </button>
-            <button
-              class="btn btn-outline-danger"
-              data-bs-target="#modal-confirm-delete"
-              data-bs-toggle="modal"
-            >
-              Удалить
-            </button>
-          </div>
-        </td>
-      </tr>
-      {% endfor %}
-
-    </tbody>
-  </table>
-</div>
-{% comment %} modal new {% endcomment %}
-<form action="" novalidate class="form-modal">
-  <div class="modal fade" id="modal-create">
-    <div
-      class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg modal-fullscreen-lg-down"
-    >
-      <div class="modal-content">
-        <div class="modal-header">
-          <h2>Добавить услугу</h2>
-          <button class="btn-close" data-bs-dismiss="modal"></button>
-        </div>
-        <div class="modal-body">
-          {% comment %} Main information {% endcomment %}
-          <div class="input-group mb-3">
-            <span class="input-group-text">ID</span>
-            <span class="form-control">1</span>
-            <span class="input-group-text">Статус</span>
-            <span class="form-control text-secondary">1</span>
-          </div>
-          {% comment %} Caption {% endcomment %}
-          <div class="form-floating mb-3">
-            <input
-              class="form-control form-control-sm"
-              type="text"
-              name="caption"
-              id="caption"
-              placeholder="Caption of a service"
-              required
-            />
-            <label class="form-label" for="caption">Наименование</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Description {% endcomment %}
-          <div class="form-floating mb-3">
-            <textarea
-              class="form-control form-control-sm"
-              type="text"
-              name="description"
-              id="description"
-              placeholder="Description of a service"
-              required
-            ></textarea>
-            <label class="form-label" for="description">Описание</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Requirements {% endcomment %}
-          <div class="form-floating mb-3">
-            <input
-              class="form-control form-control-sm"
-              type="text"
-              name="requirements"
-              id="requirements"
-              placeholder="Pequirements of a service"
-              required
-            />
-            <label class="form-label" for="requirements">Требования</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Price type {% endcomment %}
-          <div class="form-floating mb-3">
-              <select
-              class="form-select form-select"
-              type="text"
-              name="price_type"
-              id="price_type"
-              placeholder="Тип ценнообразования"
-              required
-              >
-              <option>One</option>
-              <option>Two</option>
-            </select>
-            <label class="form-label" for="price_type">Тип ценообразования</label>
-          </div>
-          <div class="invalid-feedback">Поле обязательно</div>
-          {% comment %} Is visible {% endcomment %}
-          <div class="form-check">
-            <input
-              type="checkbox"
-              name="is_visible"
-              id="is_visible"
-              class="form-check-input"
-            />
-            <label for="is_visible">Видимость</label>
-          </div>
-          {% comment %} Is global {% endcomment %}
-          <div class="form-check">
-            <input
-              type="checkbox"
-              name="is_global"
-              id="is_global"
-              class="form-check-input"
-            />
-            <label for="is_global">Глобальность</label>
-          </div>
-        </div>
-        <div class="modal-footer">
-          <button class="btn btn-success">Сохранить</button>
-          <button
-            type="button"
-            class="btn btn-outline-danger"
-            data-bs-dismiss="modal"
-          >
-            Отмена
-          </button>
-        </div>
-      </div>
-    </div>
-  </div>
-</form>
-{% comment %} modal new ends {% endcomment %}
-
-{% comment %} modal edit {% endcomment %}
-<form action="" novalidate class="form-modal">
-  <div class="modal fade" id="modal-edit">
-    <div
-      class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg modal-fullscreen-lg-down"
-    >
-      <div class="modal-content">
-        <div class="modal-header">
-          <h2>Изменить услугу</h2>
-          <button class="btn-close" data-bs-dismiss="modal"></button>
-        </div>
-        <div class="modal-body">
-          {% comment %} Main information {% endcomment %}
-          <div class="input-group mb-3">
-            <span class="input-group-text">ID</span>
-            <span class="form-control">{{service_type.id}}</span>
-            <span class="input-group-text">Статус</span>
-            <span class="form-control">{{service_type.status}}</span>
-            <span class="input-group-text">Статус тикета</span>
-            <span class="form-control">{{service_type.ticket_status}}</span>
-          </div>
-          {% comment %} Caption {% endcomment %}
-          <div class="form-floating mb-3">
-            <input
-              class="form-control form-control-sm"
-              type="text"
-              name="caption"
-              id="caption"
-              placeholder="Caption of a service"
-              required
-            />
-            <label class="form-label" for="caption">Наименование</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Description {% endcomment %}
-          <div class="form-floating mb-3">
-            <textarea
-              class="form-control form-control-sm"
-              type="text"
-              name="description"
-              id="description"
-              placeholder="Description of a service"
-              required
-            ></textarea>
-            <label class="form-label" for="description">Описание</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Requirements {% endcomment %}
-          <div class="form-floating mb-3">
-            <input
-              class="form-control form-control-sm"
-              type="text"
-              name="requirements"
-              id="requirements"
-              placeholder="Pequirements of a service"
-              required
-            />
-            <label class="form-label" for="requirements">Требования</label>
-            <div class="invalid-feedback">Поле обязательно</div>
-          </div>
-          {% comment %} Price type {% endcomment %}
-          <div class="form-floating mb-3">
-              <select
-              class="form-select form-select"
-              type="text"
-              name="price_type"
-              id="price_type"
-              placeholder="Тип ценнообразования"
-              required
-              >
-              <option>One</option>
-              <option>Two</option>
-            </select>
-            <label class="form-label" for="price_type">Тип ценообразования</label>
-          </div>
-          <div class="invalid-feedback">Поле обязательно</div>
-          {% comment %} Is visible {% endcomment %}
-          <div class="form-check">
-            <input
-              type="checkbox"
-              name="is_visible"
-              id="is_visible"
-              class="form-check-input"
-            />
-            <label for="is_visible">Видимость</label>
-          </div>
-          {% comment %} Is global {% endcomment %}
-          <div class="form-check">
-            <input
-              type="checkbox"
-              name="is_global"
-              id="is_global"
-              class="form-check-input"
-            />
-            <label for="is_global">Глобальность</label>
-          </div>
-        </div>
-        <div class="modal-footer">
-          <button class="btn btn-success">Сохранить</button>
-          <button
-            type="button"
-            class="btn btn-outline-danger"
-            data-bs-dismiss="modal"
-          >
-            Отмена
-          </button>
-        </div>
-      </div>
-    </div>
-  </div>
-</form>
-{% comment %} modal edit ends {% endcomment %} {% comment %} modal confirm
-delete {% endcomment %}
-
-<form action="">
-  <div class="modal fade" id="modal-confirm-delete">
-    <div class="modal-dialog modal-dialog-centered modal-fullscreen-sm-down">
-      <div class="modal-content">
-        <div class="modal-header">
-          <h3>Подтвердите удаление</h3>
-          <button class="btn-close" data-bs-dismiss="modal"></button>
-        </div>
-        <div class="modal-body">
-          <p>
-            Вы уверены, что хотите удалить запись "Larry the Bird" из списка
-            услуг "Друг-спортсмен"?
-          </p>
-        </div>
-        <div class="modal-footer">
-          <button class="btn btn-danger">Удалить</button>
-          <button class="btn btn-outline-primary" data-bs-dismiss="modal">
-            Отмена
-          </button>
-        </div>
-      </div>
-    </div>
-  </div>
-</form>
-<script>
-    var modalForms = document.getElementsByClassName("form-modal");
-    for (let i = 0; i < modalForms.length; i++) {
-        const serviceModalForm = modalForms[i];
-        serviceModalForm.addEventListener("submit", (e) => {
-        if (!serviceModalForm.checkValidity()) {
-        e.preventDefault();
-        }
-        serviceModalForm.classList.add("was-validated");
-    });
-    }
-    
-    
-</script>
-{% endblock contenthome %}

+ 0 - 423
SharixAdmin/templates/SharixAdmin/servicetype.html

@@ -1,423 +0,0 @@
-{% extends 'SharixAdmin/index.html' %} {% block contenthome %}
-<div class="d-flex justify-content-between align-items-center">
-	<h1>{{ title }}</h1>
-	<button
-		type="button"
-		class="btn btn-outline-success"
-		data-bs-target="#modal-create"
-		data-bs-toggle="modal">
-		Добавить услугу
-	</button>
-</div>
-<div class="table-responsive">
-	<table class="table table-striped">
-		<thead>
-			<tr>
-				<th>ID</th>
-				<th colspan="2">Название</th>
-			</tr>
-		</thead>
-		<tbody>
-      {% comment %} Print all records {% endcomment %}
-			{% for service_type in service_types %}
-			<tr>
-				<th class="row-id" scope="row">{{service_type.id}}</th>
-				<td class="w-100">{{service_type.caption}}</td>
-				<td>
-					<div class="btn-group">
-						<button
-							class="btn btn-outline-info"
-							data-bs-target="#modal-edit"
-							data-bs-toggle="modal">
-							Изменить
-						</button>
-						<button
-							class="btn btn-outline-danger"
-							data-bs-target="#modal-confirm-delete"
-							data-bs-toggle="modal">
-							Удалить
-						</button>
-					</div>
-				</td>
-			</tr>
-      {% endfor %}
-		</tbody>
-	</table>
-</div>
-
-{% comment %} modal confirm delete {% endcomment %}
-<form
-action="/metaservicesynced/api/servicetype/"
-method="delete">
-<div class="modal fade" id="modal-confirm-delete">
-  <div class="modal-dialog modal-dialog-centered modal-fullscreen-sm-down">
-    <div class="modal-content">
-      <div class="modal-header">
-        <h3>Подтвердите удаление</h3>
-        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
-      </div>
-      <div class="modal-body">
-        <p>
-          Вы уверены, что хотите удалить запись "Larry the Bird" из списка услуг
-          "Друг-спортсмен"?
-        </p>
-      </div>
-      <div class="modal-footer">
-        <button class="btn btn-danger">Удалить</button>
-        <button
-          type="button"
-          class="btn btn-outline-primary"
-          data-bs-dismiss="modal">
-          Отмена
-        </button>
-      </div>
-    </div>
-  </div>
-</div>
-</form>
-{% comment %} modal confirm delete ends {% endcomment %} 
-
-
-{% comment %} modal edit {% endcomment %}
-<form
-	action="/metaservicesynced/api/servicetype/"
-	novalidate
-	method="patch"
-	class="form-modal">
-	<div class="modal fade" id="modal-edit">
-		<div
-			class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg modal-fullscreen-lg-down">
-			<div class="modal-content">
-				<div class="modal-header">
-					<h2>Изменить услугу</h2>
-					<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
-				</div>
-				<div class="modal-body">
-					{% comment %} Main information {% endcomment %}
-					<div class="input-group mb-3">
-						<span class="input-group-text">ID</span>
-						<span class="form-control field-id"></span>
-						<span class="input-group-text">Статус</span>
-						<span class="form-control field-status"></span>
-						<span class="input-group-text">Статус тикета</span>
-						<span class="form-control field-ticket-status"></span>
-					</div>
-					{% comment %} Caption {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm field-caption"
-							type="text"
-							name="caption"
-							id="caption"
-							placeholder="Caption of a service"
-							required
-							value="" />
-						<label class="form-label" for="caption">Наименование</label>
-						<div class="invalid-feedback">Поле обязательно</div>
-					</div>
-					{% comment %} Description {% endcomment %}
-					<div class="form-floating mb-3">
-						<textarea
-							class="form-control form-control-sm field-description"
-							type="text"
-							name="description"
-							id="description"
-							placeholder="Description of a service"
-							required></textarea>
-						<label class="form-label" for="description">Описание</label>
-						<div class="invalid-feedback">Поле обязательно</div>
-					</div>
-					{% comment %} Requirements {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm field-requirements"
-							type="text"
-							name="requirements"
-							id="requirements"
-							placeholder="Pequirements of a service"
-							required
-							value="" />
-						<label class="form-label" for="requirements">Требования</label>
-						<div class="invalid-feedback">Поле обязательно</div>
-					</div>
-					{% comment %} Price type {% endcomment %}
-					<div class="form-floating mb-3">
-						<select
-							class="form-select form-select field-type"
-							type="text"
-							name="price_type"
-							id="price_type"
-							placeholder="Тип ценнообразования"
-							required>
-							<option value="0" selected>---</option>
-						</select>
-						<label class="form-label" for="price_type">Тип ценообразования</label>
-					</div>
-					<div class="invalid-feedback">Поле обязательно</div>
-					{% comment %} Is visible {% endcomment %}
-					<div class="form-check">
-						<input
-							type="checkbox"
-							name="is_visible"
-							id="is_visible"
-							class="form-check-input field-visible"
-							{% if service_type.is_visible %}
-                checked
-              {% endif %} />
-						<label for="is_visible">Видимость</label>
-					</div>
-					{% comment %} Is global {% endcomment %}
-					<div class="form-check">
-						<input
-							type="checkbox"
-							name="is_global"
-							id="is_global"
-							class="form-check-input field-global"
-							{% if service_type.is_global %}
-                checked
-              {% endif %} />
-						<label for="is_global">Глобальность</label>
-					</div>
-				</div>
-				<div class="modal-footer">
-					<button type="submit" class="btn btn-success">Сохранить</button>
-					<button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal">
-						Отмена
-					</button>
-				</div>
-			</div>
-		</div>
-	</div>
-</form>
-{% comment %} modal edit ends {% endcomment %} 
-
-{% comment %} modal new {%endcomment %}
-<form
-	action="/metaservicesynced/api/servicetype/"
-	method="post"
-	novalidate
-	class="form-modal">
-	{% csrf_token %}
-	<div class="modal fade" id="modal-create">
-		<div
-			class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg modal-fullscreen-lg-down">
-			<div class="modal-content">
-				<div class="modal-header">
-					<h2>Добавить услугу</h2>
-					<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
-				</div>
-				<div class="modal-body">
-					{% comment %} Main information {% endcomment %}
-					<div class="input-group mb-3">
-						<span class="input-group-text">ID</span>
-						<span class="form-control">None</span>
-						<span class="input-group-text">Статус</span>
-						<span class="form-control text-secondary">None</span>
-						<input type="hidden" name="status" value="Active" />
-					</div>
-					{% comment %} Codename {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm"
-							type="text"
-							name="codename"
-							id="codename"
-							placeholder="Codename of a service"
-							required />
-						<label class="form-label" for="codename"
-							>Латинское наименование услуги в системе</label
-						>
-						<div class="invalid-feedback">Обязательное поле</div>
-					</div>
-					{% comment %} Caption {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm"
-							type="text"
-							name="caption"
-							id="caption"
-							placeholder="Caption of a service"
-							required />
-						<label class="form-label" for="caption">Наименование</label>
-						<div class="invalid-feedback">Обязательное поле</div>
-					</div>
-					{% comment %} Description {% endcomment %}
-					<div class="form-floating mb-3">
-						<textarea
-							class="form-control form-control-sm"
-							type="text"
-							name="description"
-							id="description"
-							placeholder="Description of a service"
-							required></textarea>
-						<label class="form-label" for="description">Описание</label>
-						<div class="invalid-feedback">Обязательное поле</div>
-					</div>
-					{% comment %} Requirements {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm"
-							type="text"
-							name="requirements"
-							id="requirements"
-							placeholder="Pequirements of a service"
-							required />
-						<label class="form-label" for="requirements">Требования</label>
-						<div class="invalid-feedback">Обязательное поле</div>
-					</div>
-					{% comment %} Price type {% endcomment %}
-					<div class="form-floating mb-3">
-						<select
-							class="form-select form-select"
-							type="text"
-							name="price_type"
-							id="price_type"
-							placeholder="Тип ценнообразования"
-							required>
-							<option selected>3</option>
-						</select>
-						<label class="form-label" for="price_type">Тип ценообразования</label>
-					</div>
-					<div class="invalid-feedback">Обязательное поле</div>
-					{% comment %} Id metaservice {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm"
-							type="number"
-							name="id_metaservice"
-							id="id_metaservice"
-							placeholder="Id metaservice of the service"
-							required
-							max="9223372036854775807"
-							min="-9223372036854775808" />
-						<label class="form-label" for="id_metaservice"
-							>Уникальный идентификатор мета-сервиса</label
-						>
-						<div class="invalid-feedback">Обязательное поле</div>
-					</div>
-					{% comment %} link_agreement {% endcomment %}
-					<div class="form-floating mb-3">
-						<input
-							class="form-control form-control-sm"
-							type="url"
-							name="link_agreement"
-							id="link_agreement"
-							placeholder="Link agreement of the service"
-							required />
-						<label class="form-label" for="link_agreement">Ссылка на договор</label>
-						<div class="invalid-feedback">Неверный формат ссылки</div>
-					</div>
-					{% comment %} Is visible {% endcomment %}
-					<div class="form-check">
-						<input
-							type="checkbox"
-							name="is_visible"
-							id="is_visible"
-							class="form-check-input"
-							value="1" />
-						<label for="is_visible">Видимость</label>
-					</div>
-					{% comment %} Is global {% endcomment %}
-					<div class="form-check">
-						<input
-							type="checkbox"
-							name="is_global"
-							id="is_global"
-							class="form-check-input"
-							value="1" />
-						<label for="is_global">Глобальность</label>
-					</div>
-				</div>
-				<div class="modal-footer">
-					<button class="btn btn-success">Сохранить</button>
-					<button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal">
-						Отмена
-					</button>
-				</div>
-			</div>
-		</div>
-	</div>
-</form>
-{% comment %} modal new ends {% endcomment %}
-
-<script defer>
-  {% comment %} Get data of a record {% endcomment %}
-  async function getData(id) {
-    return await fetch('/metaservicesynced/api/servicetype/' + id)
-    .then(res => {
-      if (res.ok) {
-        return res.json()
-        
-      } else {
-        console.log('Error')
-      }
-    })
-    .then(data => {
-      return data
-    })
-    .catch(e => {console.log('Error')})
-  }
-
-
-	{% comment %} Bootstrap input validity script {% endcomment %}
-	var modalForms = document.getElementsByClassName("form-modal");
-	for (var i = 0; i < modalForms.length; i++) {
-	    var serviceModalForm = modalForms[i];
-	    serviceModalForm.addEventListener("submit", e => {
-	    if (!serviceModalForm.checkValidity()) {
-	    e.preventDefault();
-	    };
-	    e.target.classList.add("was-validated");
-	})
-	}
-
-	{% comment %} add Event to all Edit buttons {% endcomment %}
-	var editButtons = document.getElementsByClassName("btn-outline-info");
-	for (let i = 0; i < editButtons.length; i++) {
-	  var editButton = editButtons[i];
-	  editButton.addEventListener("click", fillEditForm);
-	};
-
-  {% comment %} add Event to all delete buttons {% endcomment %}
-	var editButtons = document.getElementsByClassName("btn-outline-info");
-	for (let i = 0; i < editButtons.length; i++) {
-	  var editButton = editButtons[i];
-	  editButton.addEventListener("click", deleteRecord);
-	};
-
-  function deleteRecord(id) {
-    // delete query
-  }
-
-  {% comment %} Get the id of the row whose button was clicked {% endcomment %}
-	function getRowId(button) {
-	  var row = button.parentElement.parentElement.parentElement;
-	  var rowId = parseInt(row.getElementsByClassName("row-id")[0].innerText);
-    return rowId
-	};
-
-  {% comment %} Fill form fields with data {% endcomment %}
-  function fillEditForm(event) {
-    var id = getRowId(event.target)
-    getData(id).then(data => {
-      fillFormFields(data)
-    })
-  }
-
-  function fillFormFields(data) {
-    editForm = document.getElementById("modal-edit")
-
-    // Get and fill all the fields
-    editForm.getElementsByClassName("field-id")[0].innerText = data["id"]
-    editForm.getElementsByClassName("field-status")[0].innerText = data["status"]
-    editForm.getElementsByClassName("field-ticket-status")[0].innerText = data["ticket_status"]
-    editForm.getElementsByClassName("field-caption")[0].value= data["caption"]
-    editForm.getElementsByClassName("field-description")[0].innerText = data["description"]
-    editForm.getElementsByClassName("field-requirements")[0].value = data["requirements"]
-    editForm.getElementsByClassName("field-type")[0].value = 0
-    editForm.getElementsByClassName("field-visible")[0].checked = parseInt(data["is_visible"])
-    editForm.getElementsByClassName("field-global")[0].checked = parseInt(data["is_global"]) 
-  }
-
-</script>
-{% endblock contenthome %}

+ 6 - 0
SharixAdmin/urls.py

@@ -21,6 +21,12 @@ urlpatterns = [
     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('v1/auth/', include('djoser.urls')),
     path('auth/', include('djoser.urls.authtoken'), name='auth'),
     path('platform/api/', include(router.urls), name="sharix-api"),

+ 67 - 1
SharixAdmin/views.py

@@ -13,6 +13,8 @@ from .tables import *
 from django import template
 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.
 
 
@@ -115,7 +117,7 @@ menu = [
     {'title':'Сотрудничество',          'link':'test-page', 'sel':'sotrud'},
     {'title':'Техподдержка',            'link':'test-page', 'sel':'gear'},
     {'title':'Мои заявки',              'link':'tickets', 'sel':'tikets'},
-    {'title':'Услуги сервиса',          'link':'servicetype', 'sel':'tikets'},
+    {'title':'Услуги сервиса',          'link':'service_type', 'sel':'hdd-network'},
 ]
 
 def get_context(request, page_context) -> dict:
@@ -128,6 +130,70 @@ def get_context(request, page_context) -> dict:
     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)
+        context.update(get_context(self.request, {
+            'title': 'Услуги сервиса',
+            'object': self.object,
+        }))
+        return context
+    
+    def get_success_url(self):
+        return reverse('service_type')
+
+
+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')
+    
+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
+
+
 
 
 #Shema views