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: btnBg = request.POST.get('btnBg') btnTxt = request.POST.get('btnTxt') btnHover = request.POST.get('btnHover') pillsBg = request.POST.get('pillsBg') pillsTxt = request.POST.get('pillsTxt') linksTxt = request.POST.get('linksTxt') linksHover = request.POST.get('linksHover') btnSuccessBg = request.POST.get('btnSuccessBg') btnSuccessTxt = request.POST.get('btnSuccessTxt') btnSuccessHover = request.POST.get('btnSuccessHover') btnDangerBg = request.POST.get('btnDangerBg') btnDangerTxt = request.POST.get('btnDangerTxt') btnDangerHover = request.POST.get('btnDangerHover') css = f''' :root{{ --btn-bg-color: {btnBg}; --btn-txt-color: {btnTxt}; --btn-hover-color: {btnHover}; --pills-bg-color: {pillsBg}; --pills-txt-color: {pillsTxt}; --links-txt-color: {linksTxt}; --links-hover-color: {linksHover}; --btn-success: {btnSuccessBg}; --btn-success-txt: {btnSuccessTxt}; --btn-success-hover: {btnSuccessHover}; --btn-danger: {btnDangerBg}; --btn-danger-txt: {btnDangerTxt}; --btn-danger-hover: {btnDangerHover}; }} .btn-primary, .btn-outline-primary{{ background-color: var(--btn-bg-color); color: var(--btn-txt-color); border-color: var(--btn-bg-color); }} .btn-primary:hover, .btn-outline-primary:hover{{ background-color: var(--btn-hover-color); border-color: var(--btn-hover-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); }} a:hover{{ color:var(--links-hover-color) }} .nav-link{{ color: var(--links-txt-color) }} .nav-link:hover{{ color:var(--links-hover-color) }} .btn-success, .btn-outline-success{{ color: var(--btn-txt-color); background-color: var(--btn-success); border-color: var(--btn-success); }} .btn-success:hover, .btn-outline-success:hover{{ background-color: var(--btn-success-hover); border-color: var(--btn-success-hover); }} .btn-danger, .btn-outline-danger{{ color: var(--btn-danger-txt); background-color: var(--btn-danger); border-color: var(--btn-danger); }} .btn-danger:hover, .btn-outline-danger:hover{{ background-color: var(--btn-danger-hover); border-color: var(--btn-danger-hover); }} ''' with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file: file.write(css) subprocess.run( ["bin/collectstatic.sh"]) messages.success(request, "The colors changed successfully.") else: form = ColorsForm() return render(request, "admin/change_colors.html", {'form': form})