views.py 3.6 KB

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