views.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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: {btnSuccessBg};
  37. --pills-txt-color: {btnSuccessTxt};
  38. --links-txt-color: {btnDangerBg};
  39. --btn-success: {btnDangerTxt};
  40. --btn-success-txt: {pillsBg};
  41. --btn-danger: {pillsTxt};
  42. --btn-danger-txt: {linksTxt};
  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. .nav-link{{
  57. color: var(--links-txt-color)
  58. }}
  59. .btn-success, .btn-outline-success{{
  60. color: var(--btn-txt-color);
  61. background-color: var(--btn-success);
  62. border-color: var(--btn-success);
  63. }}
  64. .btn-danger, .btn-outline-danger{{
  65. color: var(--btn-danger-txt);
  66. background-color: var(--btn-danger);
  67. border-color: var(--btn-danger);
  68. }}
  69. '''
  70. with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
  71. file.write(css)
  72. else:
  73. form = ColorsForm()
  74. return render(request,"admin/change_colors.html", {'form':form})