1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- from django.shortcuts import render
- 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 core import settings
- import subprocess
- def upload(request):
- if request.method == 'POST':
- form = LogoForm(request.POST, request.FILES)
- if form.is_valid():
- settings.NAME_SYSTEM = request.POST.get('namesystem')
- handle_uploaded_file(request.FILES.get('logo'))
- form.save()
- subprocess.run(["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
- messages.success(request, "The logo has been uploaded successfully.")
- return HttpResponseRedirect("/admin")
- else:
- form = LogoForm()
- return render(request,"admin/upload_logo.html",{'form':form})
- def change_colors(request):
- if request.method == 'POST':
- form = ColorsForm(request.POST)
- if form.is_valid():
- btnBg = request.POST.get('btnBg')
- btnTxt = request.POST.get('btnTxt')
- btnSuccessBg = request.POST.get('btnSuccessBg')
- btnSuccessTxt = request.POST.get('btnSuccessTxt')
- btnDangerBg = request.POST.get('btnDangerBg')
- btnDangerTxt = request.POST.get('btnDangerTxt')
- pillsBg = request.POST.get('pillsBg')
- pillsTxt = request.POST.get('pillsTxt')
- linksTxt = request.POST.get('linksTxt')
- css = f'''
- :root{{
- --btn-bg-color: {btnBg};
- --btn-txt-color: {btnTxt};
- --pills-bg-color: {pillsBg};
- --pills-txt-color: {pillsTxt};
- --links-txt-color: {linksTxt};
- --btn-success: {btnSuccessBg};
- --btn-success-txt: {btnSuccessTxt};
- --btn-danger: {btnDangerBg};
- --btn-danger-txt: {btnDangerTxt};
- }}
- .btn-primary, .btn-outline-primary{{
- background-color: var(--btn-bg-color);
- color: var(--btn-txt-color);
- border-color: var(--btn-bg-color);
- }}
- .nav-pills .nav-link.active, .nav-pills .show>.nav-link{{
- background-color: var(--pills-bg-color);
- color: var(--pills-txt-color);
- }}
- a{{
- color: var(--links-txt-color);
- }}
- .nav-link{{
- color: var(--links-txt-color)
- }}
- .btn-success, .btn-outline-success{{
- color: var(--btn-txt-color);
- background-color: var(--btn-success);
- border-color: var(--btn-success);
- }}
- .btn-danger, .btn-outline-danger{{
- color: var(--btn-danger-txt);
- background-color: var(--btn-danger);
- border-color: var(--btn-danger);
- }}
- '''
- with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
- file.write(css)
- subprocess.run(["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
- messages.success(request, "The colors changed successfully.")
- else:
- form = ColorsForm()
- return render(request,"admin/change_colors.html", {'form':form})
|