blezz-tech 1 mese fa
parent
commit
1811054243
8 ha cambiato i file con 149 aggiunte e 46 eliminazioni
  1. 3 3
      README.md
  2. 0 2
      admin.py
  3. 3 5
      apps.py
  4. 4 1
      context_processors.py
  5. 111 17
      forms.py
  6. 4 4
      urls.py
  7. 5 5
      utils.py
  8. 19 9
      views.py

+ 3 - 3
README.md

@@ -4,7 +4,6 @@ A module for the admin panel implemented as a Django application.
 
 ## Installation
 
-
 1) Download or clone repository
 
 ```bash
@@ -34,7 +33,7 @@ NAME_SYSTEM = 'Sharix'
   ] ...)
 ```
 
-4) Delete the migration files in the **migrations** folder (everything except __init__.py)
+4) Delete the migration files in the **migrations** folder (everything except \_\_init\_\_.py)
 
 Start test the server:
 
@@ -42,7 +41,8 @@ Start test the server:
 python manage.py runserver 8000
 ```
 
-If the port has not been selected, it is 8000 by default. If selected port is busy, use another one (for example, try increasing port number by 1 until the server starts). A link to the website should appear in the terminal.
+If the port has not been selected, it is 8000 by default. If selected port is busy, use another one (for example, try
+increasing port number by 1 until the server starts). A link to the website should appear in the terminal.
 
 ## Settings
 

+ 0 - 2
admin.py

@@ -1,3 +1 @@
-from django.contrib import admin
-
 # Register your models here.

+ 3 - 5
apps.py

@@ -1,10 +1,8 @@
 from django.apps import AppConfig
 
+
 class DesignTemplateConfig(AppConfig):
     default_auto_field = 'django.db.models.BigAutoField'
-    name = 'design_template'  
-        
-    
-#colors = ['#479FF8', '#ffffff', '#0a58ca', '#0d6efd', '#ffffff', '#0d6efd', '#0a58ca','#198754', '#198754', '#10683f', '#ffffff', '#dc3545', '#821e27', '#ffffff']
+    name = 'design_template'
 
-  
+# colors = ['#479FF8', '#ffffff', '#0a58ca', '#0d6efd', '#ffffff', '#0d6efd', '#0a58ca','#198754', '#198754', '#10683f', '#ffffff', '#dc3545', '#821e27', '#ffffff']

+ 4 - 1
context_processors.py

@@ -1,4 +1,7 @@
 from core import settings
 
+
 def get_name_system(request):
-    return {'NameSystem':settings.NAME_SYSTEM} 
+    return {
+        'NameSystem': settings.NAME_SYSTEM
+    }

+ 111 - 17
forms.py

@@ -1,9 +1,16 @@
-from django import forms
 import re
+
+from django import forms
+
+
 class LogoForm(forms.Form):
-    namesystem = forms.CharField(max_length=30, label="Название системы", required=False)
-    logo = forms.FileField(label="Логотип", required=False)
-    logo.widget.attrs.update({'accept':'.png, .svg, .ico'})
+    namesystem = forms.CharField(
+        max_length=30,
+        label="Название системы", required=False)
+    logo = forms.FileField(
+        label="Логотип", required=False)
+    logo.widget.attrs.update({'accept': '.png, .svg, .ico'})
+
 
 class ColorsForm(forms.Form):
     def __init__(self, *args, **kwargs):
@@ -14,16 +21,103 @@ class ColorsForm(forms.Form):
         super(ColorsForm, self).__init__(*args, **kwargs)
 
         # Create form fields with initial color values
-        self.fields['btnBg'] = forms.CharField(label='Цвет кнопок', initial=colors[0], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnTxt'] = forms.CharField(label='Цвет текста кнопок', initial=colors[1], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnHover'] = forms.CharField(label='Цвет наведения у кнопок', initial=colors[2], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['pillsBg'] = forms.CharField(label='Цвет плашек в меню', initial=colors[3], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['pillsTxt'] = forms.CharField(label='Цвет текста плашек в меню', initial=colors[4], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['linksTxt'] = forms.CharField(label='Цвет текста ссылок', initial=colors[5], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['linksHover'] = forms.CharField(label='Цвет наведения у ссылок', initial=colors[6], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnSuccessBg'] = forms.CharField(label='Цвет кнопок успеха', initial=colors[7], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnSuccessTxt'] = forms.CharField(label='Цвет текста кнопок успеха', initial=colors[8], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnSuccessHover'] = forms.CharField(label='Цвет наведения у кнопок успеха', initial=colors[9], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnDangerBg'] = forms.CharField(label='Цвет текста кнопок предупреждения', initial=colors[10], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnDangerTxt'] = forms.CharField(label='Цвет текста кнопок предупреждения', initial=colors[11], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
-        self.fields['btnDangerHover'] = forms.CharField(label='Цвет наведения у кнопок предупреждения', initial=colors[12], max_length=7, widget=forms.TextInput(attrs={'type': 'color'}))
+        self.fields['btnBg'] = forms.CharField(
+            label='Цвет кнопок',
+            initial=colors[0],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnTxt'] = forms.CharField(
+            label='Цвет текста кнопок',
+            initial=colors[1],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnHover'] = forms.CharField(
+            label='Цвет наведения у кнопок',
+            initial=colors[2],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['pillsBg'] = forms.CharField(
+            label='Цвет плашек в меню',
+            initial=colors[3],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['pillsTxt'] = forms.CharField(
+            label='Цвет текста плашек в меню',
+            initial=colors[4],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['linksTxt'] = forms.CharField(
+            label='Цвет текста ссылок',
+            initial=colors[5],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['linksHover'] = forms.CharField(
+            label='Цвет наведения у ссылок',
+            initial=colors[6],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnSuccessBg'] = forms.CharField(
+            label='Цвет кнопок успеха',
+            initial=colors[7],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnSuccessTxt'] = forms.CharField(
+            label='Цвет текста кнопок успеха',
+            initial=colors[8],
+            max_length=7, widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnSuccessHover'] = forms.CharField(
+            label='Цвет наведения у кнопок успеха',
+            initial=colors[9],
+            max_length=7, widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnDangerBg'] = forms.CharField(
+            label='Цвет текста кнопок предупреждения',
+            initial=colors[10],
+            max_length=7, widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnDangerTxt'] = forms.CharField(
+            label='Цвет текста кнопок предупреждения',
+            initial=colors[11],
+            max_length=7, widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )
+        self.fields['btnDangerHover'] = forms.CharField(
+            label='Цвет наведения у кнопок предупреждения',
+            initial=colors[12],
+            max_length=7,
+            widget=forms.TextInput(attrs={
+                'type': 'color'
+            })
+        )

+ 4 - 4
urls.py

@@ -1,12 +1,12 @@
-from django.urls import path
-from design_template import views
 from django.shortcuts import redirect
+from django.urls import path
 
+from design_template import views
 
 app_name = "design"
 
 urlpatterns = [
     path("", views.upload, name="settings"),
-    path("logo.png", lambda _ : redirect('sharix_admin/img/logo.png', permanent=True)),
+    path("logo.png", lambda _: redirect('sharix_admin/img/logo.png', permanent=True)),
     path("colors", views.change_colors, name="colors"),
-]
+]

+ 5 - 5
utils.py

@@ -1,5 +1,5 @@
-def handle_uploaded_file(file): 
-    file.name = "logo."+file.name.split('.')[1]
-    with open('sharix_admin/static/sharix_admin/img/'+file.name, 'wb+') as destination: 
-        for chunk in file.chunks(): 
-            destination.write(chunk) 
+def handle_uploaded_file(file):
+    file.name = "logo." + file.name.split('.')[1]
+    with open('sharix_admin/static/sharix_admin/img/' + file.name, 'wb+') as destination:
+        for chunk in file.chunks():
+            destination.write(chunk)

+ 19 - 9
views.py

@@ -1,11 +1,13 @@
-from django.shortcuts import render
+import subprocess
+
 from django.contrib import messages
 from django.http import HttpResponseRedirect
-from design_template.utils import handle_uploaded_file
-from design_template.forms import ColorsForm, LogoForm
+from django.shortcuts import render
+
 from core import settings
+from design_template.forms import ColorsForm, LogoForm
+from design_template.utils import handle_uploaded_file
 
-import subprocess
 
 def upload(request):
     if request.method == 'POST':
@@ -15,13 +17,20 @@ def upload(request):
             handle_uploaded_file(request.FILES.get('logo'))
             form.save()
             subprocess.run(
-                ["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
+                ["/root/sharix-open-webapp-base/bin/collectstatic.sh"]
+            )
             messages.success(
-                request, "The logo has been uploaded successfully.")
+                request,
+                "The logo has been uploaded successfully."
+            )
             return HttpResponseRedirect("/admin")
     else:
         form = LogoForm()
-    return render(request, "admin/upload_logo.html", {'form': form})
+    return render(
+        request,
+        "admin/upload_logo.html",
+        {'form': form}
+    )
 
 
 def change_colors(request):
@@ -117,9 +126,10 @@ a:hover{{
             with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
                 file.write(css)
             subprocess.run(
-                ["bin/collectstatic.sh"])
+                ["bin/collectstatic.sh"]
+            )
             messages.success(request, "The colors changed successfully.")
     else:
         form = ColorsForm()
-    
+
     return render(request, "admin/change_colors.html", {'form': form})