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 def upload(request): if request.method == 'POST': form = LogoForm(request.POST, request.FILES) if form.is_valid(): name_system = request.POST['namesystem'] settings.NAME_SYSTEM = name_system handle_uploaded_file(request.FILES['logo']) 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); }} .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) else: form = ColorsForm() return render(request,"admin/change_colors.html", {'form':form})