From a006a9987ce540d44de097a9937791fb4d79a62e Mon Sep 17 00:00:00 2001 From: KarolG Date: Tue, 4 Jul 2023 03:52:31 +0200 Subject: [PATCH] Initial commit of skins changing implementation --- artel/artel/settings/base.py | 1 + artel/artel/static/css/dynamic_colors.css | 10 ++++++ artel/artel/templates/base.html | 1 + artel/artel/urls.py | 2 ++ artel/requirements.txt | 3 +- artel/setup/forms.py | 13 +++++++ artel/setup/templates/skin_changer.html | 29 ++++++++++++++++ artel/setup/views.py | 41 ++++++++++++++++++++++- 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 artel/artel/static/css/dynamic_colors.css create mode 100644 artel/setup/templates/skin_changer.html diff --git a/artel/artel/settings/base.py b/artel/artel/settings/base.py index a5727b6..57e2ea7 100644 --- a/artel/artel/settings/base.py +++ b/artel/artel/settings/base.py @@ -53,6 +53,7 @@ INSTALLED_APPS = [ "django.contrib.staticfiles", "rest_framework", "phonenumber_field", + "colorfield" ] # Optionalization diff --git a/artel/artel/static/css/dynamic_colors.css b/artel/artel/static/css/dynamic_colors.css new file mode 100644 index 0000000..fc1b228 --- /dev/null +++ b/artel/artel/static/css/dynamic_colors.css @@ -0,0 +1,10 @@ +body { + background-color: #000000; + color: #ffee00; +} +.button { + background-color: #ffd6d6; +} +a { + color: #804242; +} diff --git a/artel/artel/templates/base.html b/artel/artel/templates/base.html index 73922ea..b96880b 100644 --- a/artel/artel/templates/base.html +++ b/artel/artel/templates/base.html @@ -27,6 +27,7 @@ {# Global stylesheets #} + {% block extra_css %} {# Override this in templates to add extra stylesheets #} diff --git a/artel/artel/urls.py b/artel/artel/urls.py index 36836d5..39f7970 100644 --- a/artel/artel/urls.py +++ b/artel/artel/urls.py @@ -13,6 +13,7 @@ from wagtail.documents import urls as wagtaildocs_urls from search import views as search_views from setup.views import SetupPageView as setup_view +from setup.views import SkinChangerView as skin_view urlpatterns = [ path("django-admin/", admin.site.urls), @@ -20,6 +21,7 @@ urlpatterns = [ path("documents/", include(wagtaildocs_urls)), path("search/", search_views.search, name="search"), path('setup/', setup_view.as_view(), name='setup'), + path('skins/', skin_view.as_view(), name='skin' ) ] store_app_enabled = getattr(settings, 'SHOP_ENABLED', False) diff --git a/artel/requirements.txt b/artel/requirements.txt index 89d53de..0cf5800 100644 --- a/artel/requirements.txt +++ b/artel/requirements.txt @@ -7,4 +7,5 @@ djangorestframework==3.14.0 phonenumbers==8.13.13 django-phonenumber-field==7.1.0 factory-boy==3.2.1 -pdfkit==1.0.0 \ No newline at end of file +pdfkit==1.0.0 +django-colorfield==0.9.0 diff --git a/artel/setup/forms.py b/artel/setup/forms.py index 1d2d339..c4640d1 100644 --- a/artel/setup/forms.py +++ b/artel/setup/forms.py @@ -1,5 +1,6 @@ from django import forms from django.conf import settings +from colorfield.fields import ColorField import os @@ -25,3 +26,15 @@ class SiteConfigurationForm(forms.Form): f.write(chunk) return os.path.join('images/icons', logo.name) return None + + +class SkinChangerForm(forms.Form): + COLOR_PALETTE = [ + ("#FFFFFF", "white", ), + ("#000000", "black", ), + ] + + background_color = ColorField(samples=COLOR_PALETTE) + font_color = ColorField(samples=COLOR_PALETTE) + button_color = ColorField(samples=COLOR_PALETTE) + link_color = ColorField(samples=COLOR_PALETTE) diff --git a/artel/setup/templates/skin_changer.html b/artel/setup/templates/skin_changer.html new file mode 100644 index 0000000..6205868 --- /dev/null +++ b/artel/setup/templates/skin_changer.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block content %} +
+ {% csrf_token %} +
+ + +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+{% endblock content %} diff --git a/artel/setup/views.py b/artel/setup/views.py index 978ae91..4e2aadc 100644 --- a/artel/setup/views.py +++ b/artel/setup/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render, redirect from django.views import View -from .forms import SiteConfigurationForm +from django.conf import settings +import os +from .forms import SiteConfigurationForm, SkinChangerForm import json @@ -26,6 +28,43 @@ class SetupPageView(View): with open('config.json', 'w') as file: file.write(json_data) + return redirect('/skins') + else: + return render(request, self.template_name, {'form': form}) + + +class SkinChangerView(View): + template_name = 'skin_changer.html' + + def get(self, request): + form = SkinChangerForm() + return render(request, self.template_name, {'form': form}) + + def post(self, request): + form = SkinChangerForm(request.POST) + if form.is_valid(): + form_data = form.data + css_content = generate_css_content(form_data) + file_name = 'dynamic_colors.css' + css_file_path = os.path.join(settings.MEDIA_ROOT, 'css', file_name) + with open(css_file_path, 'w') as css_file: + css_file.write(css_content) return redirect('/') else: return render(request, self.template_name, {'form': form}) + + +def generate_css_content(form_data): + css_content = f""" + body {{ + background-color: {form_data['background_color']}; + color: {form_data['font_color']}; + }} + .button {{ + background-color: {form_data['button_color']}; + }} + a {{ + color: {form_data['link_color']}; + }} + """ + return css_content