views.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. background-color: var(--btn-hover-color);
  61. border-color: var(--btn-hover-color);
  62. }}
  63. .nav-pills .nav-link.active, .nav-pills .show>.nav-link{{
  64. background-color: var(--pills-bg-color);
  65. color: var(--pills-txt-color);
  66. }}
  67. a{{
  68. color: var(--links-txt-color);
  69. }}
  70. a:hover{{
  71. color:var(--links-hover-color)
  72. }}
  73. .nav-link{{
  74. color: var(--links-txt-color)
  75. }}
  76. .nav-link:hover{{
  77. color:var(--links-hover-color)
  78. }}
  79. .btn-success, .btn-outline-success{{
  80. color: var(--btn-txt-color);
  81. background-color: var(--btn-success);
  82. border-color: var(--btn-success);
  83. }}
  84. .btn-success, .btn-outline-success:hover{{
  85. background-color: var(--btn-success-hover);
  86. border-color: var(--btn-success-hover);
  87. }}
  88. .btn-danger, .btn-outline-danger{{
  89. color: var(--btn-danger-txt);
  90. background-color: var(--btn-danger);
  91. border-color: var(--btn-danger);
  92. }}
  93. .btn-danger, .btn-outline-danger:hover{{
  94. background-color: var(--btn-danger-hover);
  95. border-color: var(--btn-danger-hover);
  96. }}
  97. '''
  98. with open("design_template/static/design_template/colors.css", 'r+', encoding='utf-8') as file:
  99. file.write(css)
  100. subprocess.run(["/root/sharix-open-webapp-base/bin/collectstatic.sh"])
  101. messages.success(request, "The colors changed successfully.")
  102. else:
  103. form = ColorsForm()
  104. return render(request,"admin/change_colors.html", {'form':form})