views.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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(
  16. ["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
  17. messages.success(
  18. request, "The logo has been uploaded successfully.")
  19. return HttpResponseRedirect("/admin")
  20. else:
  21. form = LogoForm()
  22. return render(request, "admin/upload_logo.html", {'form': form})
  23. def change_colors(request):
  24. if request.method == 'POST':
  25. form = ColorsForm(request.POST)
  26. if form:
  27. btnBg = request.POST.get('btnBg')
  28. btnTxt = request.POST.get('btnTxt')
  29. btnHover = request.POST.get('btnHover')
  30. pillsBg = request.POST.get('pillsBg')
  31. pillsTxt = request.POST.get('pillsTxt')
  32. linksTxt = request.POST.get('linksTxt')
  33. linksHover = request.POST.get('linksHover')
  34. btnSuccessBg = request.POST.get('btnSuccessBg')
  35. btnSuccessTxt = request.POST.get('btnSuccessTxt')
  36. btnSuccessHover = request.POST.get('btnSuccessHover')
  37. btnDangerBg = request.POST.get('btnDangerBg')
  38. btnDangerTxt = request.POST.get('btnDangerTxt')
  39. btnDangerHover = request.POST.get('btnDangerHover')
  40. css = f'''
  41. :root{{
  42. --btn-bg-color: {btnBg};
  43. --btn-txt-color: {btnTxt};
  44. --btn-hover-color: {btnHover};
  45. --pills-bg-color: {pillsBg};
  46. --pills-txt-color: {pillsTxt};
  47. --links-txt-color: {linksTxt};
  48. --links-hover-color: {linksHover};
  49. --btn-success: {btnSuccessBg};
  50. --btn-success-txt: {btnSuccessTxt};
  51. --btn-success-hover: {btnSuccessHover};
  52. --btn-danger: {btnDangerBg};
  53. --btn-danger-txt: {btnDangerTxt};
  54. --btn-danger-hover: {btnDangerHover};
  55. }}
  56. .btn-primary, .btn-outline-primary{{
  57. background-color: var(--btn-bg-color);
  58. color: var(--btn-txt-color);
  59. border-color: var(--btn-bg-color);
  60. }}
  61. .btn-primary:hover, .btn-outline-primary:hover{{
  62. background-color: var(--btn-hover-color);
  63. border-color: var(--btn-hover-color);
  64. }}
  65. .nav-pills .nav-link.active, .nav-pills .show>.nav-link{{
  66. background-color: var(--pills-bg-color);
  67. color: var(--pills-txt-color);
  68. }}
  69. a{{
  70. color: var(--links-txt-color);
  71. }}
  72. a:hover{{
  73. color:var(--links-hover-color)
  74. }}
  75. .nav-link{{
  76. color: var(--links-txt-color)
  77. }}
  78. .nav-link:hover{{
  79. color:var(--links-hover-color)
  80. }}
  81. .btn-success, .btn-outline-success{{
  82. color: var(--btn-txt-color);
  83. background-color: var(--btn-success);
  84. border-color: var(--btn-success);
  85. }}
  86. .btn-success:hover, .btn-outline-success:hover{{
  87. background-color: var(--btn-success-hover);
  88. border-color: var(--btn-success-hover);
  89. }}
  90. .btn-danger, .btn-outline-danger{{
  91. color: var(--btn-danger-txt);
  92. background-color: var(--btn-danger);
  93. border-color: var(--btn-danger);
  94. }}
  95. .btn-danger:hover, .btn-outline-danger:hover{{
  96. background-color: var(--btn-danger-hover);
  97. border-color: var(--btn-danger-hover);
  98. }}
  99. '''
  100. with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
  101. file.write(css)
  102. subprocess.run(
  103. ["bin/collectstatic.sh"])
  104. messages.success(request, "The colors changed successfully.")
  105. else:
  106. form = ColorsForm()
  107. return render(request, "admin/change_colors.html", {'form': form})