views.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from django.shortcuts import render
  2. from django.contrib import messages
  3. from django.http import HttpResponseRedirect
  4. from design_template.utils import handle_uploaded_file
  5. from design_template.forms import ColorsForm, LogoForm
  6. from core import settings
  7. def upload(request):
  8. if request.method == 'POST':
  9. form = LogoForm(request.POST, request.FILES)
  10. if form.is_valid():
  11. name_system = request.POST['namesystem']
  12. settings.NAME_SYSTEM = name_system
  13. handle_uploaded_file(request.FILES['logo'])
  14. messages.success(request, "The logo has been uploaded successfully.")
  15. return HttpResponseRedirect("/admin")
  16. else:
  17. form = LogoForm()
  18. return render(request,"admin/upload_logo.html",{'form':form})
  19. def change_colors(request):
  20. if request.method == 'POST':
  21. form = ColorsForm(request.POST)
  22. if form.is_valid():
  23. btnBg = request.POST.get('btnBg')
  24. btnTxt = request.POST.get('btnTxt')
  25. btnSuccessBg = request.POST.get('btnSuccessBg')
  26. btnSuccessTxt = request.POST.get('btnSuccessTxt')
  27. btnDangerBg = request.POST.get('btnDangerBg')
  28. btnDangerTxt = request.POST.get('btnDangerTxt')
  29. pillsBg = request.POST.get('pillsBg')
  30. pillsTxt = request.POST.get('pillsTxt')
  31. linksTxt = request.POST.get('linksTxt')
  32. css = f'''
  33. :root{{
  34. --btn-bg-color: {btnBg};
  35. --btn-txt-color: {btnTxt};
  36. --pills-bg-color: {pillsBg};
  37. --pills-txt-color: {pillsTxt};
  38. --links-txt-color: {linksTxt};
  39. --btn-success: {btnSuccessBg};
  40. --btn-success-txt: {btnSuccessTxt};
  41. --btn-danger: {btnDangerBg};
  42. --btn-danger-txt: {btnDangerTxt};
  43. }}
  44. .btn-primary, .btn-outline-primary{{
  45. background-color: var(--btn-bg-color);
  46. color: var(--btn-txt-color);
  47. border-color: var(--btn-bg-color);
  48. }}
  49. .nav-pills .nav-link.active, .nav-pills .show>.nav-link{{
  50. background-color: var(--pills-bg-color);
  51. color: var(--pills-txt-color);
  52. }}
  53. a{{
  54. color: var(--links-txt-color);
  55. }}
  56. .btn-success, .btn-outline-success{{
  57. color: var(--btn-txt-color);
  58. background-color: var(--btn-success);
  59. border-color: var(--btn-success);
  60. }}
  61. .btn-danger, .btn-outline-danger{{
  62. color: var(--btn-danger-txt);
  63. background-color: var(--btn-danger);
  64. border-color: var(--btn-danger);
  65. }}
  66. '''
  67. with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
  68. file.write(css)
  69. else:
  70. form = ColorsForm()
  71. return render(request,"admin/change_colors.html", {'form':form})