views.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import subprocess
  8. def upload(request):
  9. if request.method == 'POST':
  10. form = LogoForm(request.POST, request.FILES)
  11. if form.is_valid():
  12. settings.NAME_SYSTEM = request.POST.get('namesystem')
  13. handle_uploaded_file(request.FILES.get('logo'))
  14. form.save()
  15. subprocess.run(["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
  16. messages.success(request, "The logo has been uploaded successfully.")
  17. return HttpResponseRedirect("/admin")
  18. else:
  19. form = LogoForm()
  20. return render(request,"admin/upload_logo.html",{'form':form})
  21. def change_colors(request):
  22. if request.method == 'POST':
  23. form = ColorsForm(request.POST)
  24. if form.is_valid():
  25. btnBg = request.POST.get('btnBg')
  26. btnTxt = request.POST.get('btnTxt')
  27. btnSuccessBg = request.POST.get('btnSuccessBg')
  28. btnSuccessTxt = request.POST.get('btnSuccessTxt')
  29. btnDangerBg = request.POST.get('btnDangerBg')
  30. btnDangerTxt = request.POST.get('btnDangerTxt')
  31. pillsBg = request.POST.get('pillsBg')
  32. pillsTxt = request.POST.get('pillsTxt')
  33. linksTxt = request.POST.get('linksTxt')
  34. css = f'''
  35. :root{{
  36. --btn-bg-color: {btnBg};
  37. --btn-txt-color: {btnTxt};
  38. --pills-bg-color: {pillsBg};
  39. --pills-txt-color: {pillsTxt};
  40. --links-txt-color: {linksTxt};
  41. --btn-success: {btnSuccessBg};
  42. --btn-success-txt: {btnSuccessTxt};
  43. --btn-danger: {btnDangerBg};
  44. --btn-danger-txt: {btnDangerTxt};
  45. }}
  46. .btn-primary, .btn-outline-primary{{
  47. background-color: var(--btn-bg-color);
  48. color: var(--btn-txt-color);
  49. border-color: var(--btn-bg-color);
  50. }}
  51. .nav-pills .nav-link.active, .nav-pills .show>.nav-link{{
  52. background-color: var(--pills-bg-color);
  53. color: var(--pills-txt-color);
  54. }}
  55. a{{
  56. color: var(--links-txt-color);
  57. }}
  58. .nav-link{{
  59. color: var(--links-txt-color)
  60. }}
  61. .btn-success, .btn-outline-success{{
  62. color: var(--btn-txt-color);
  63. background-color: var(--btn-success);
  64. border-color: var(--btn-success);
  65. }}
  66. .btn-danger, .btn-outline-danger{{
  67. color: var(--btn-danger-txt);
  68. background-color: var(--btn-danger);
  69. border-color: var(--btn-danger);
  70. }}
  71. '''
  72. with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
  73. file.write(css)
  74. subprocess.run(["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
  75. messages.success(request, "The colors changed successfully.")
  76. else:
  77. form = ColorsForm()
  78. return render(request,"admin/change_colors.html", {'form':form})