Initial commit of skins changing implementation
rodzic
140e7618f2
commit
a006a9987c
|
@ -53,6 +53,7 @@ INSTALLED_APPS = [
|
|||
"django.contrib.staticfiles",
|
||||
"rest_framework",
|
||||
"phonenumber_field",
|
||||
"colorfield"
|
||||
]
|
||||
|
||||
# Optionalization
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
body {
|
||||
background-color: #000000;
|
||||
color: #ffee00;
|
||||
}
|
||||
.button {
|
||||
background-color: #ffd6d6;
|
||||
}
|
||||
a {
|
||||
color: #804242;
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
{# Global stylesheets #}
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'css/artel.css' %}">
|
||||
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/dynamic_colors.css' %}">
|
||||
|
||||
{% block extra_css %}
|
||||
{# Override this in templates to add extra stylesheets #}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
pdfkit==1.0.0
|
||||
django-colorfield==0.9.0
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<form method='POST'>
|
||||
{% csrf_token %}
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.background_color.id_for_label }}">Background Color</label>
|
||||
<input type="color" name="background_color" value="{{ form.background_color.value }}">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.font_color.id_for_label }}">Font Color</label>
|
||||
<input type="color" name="font_color" value="{{ form.font_color.value }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.button_color.id_for_label }}">Button Color</label>
|
||||
<input type="color" name="button_color" value="{{ form.button_color.value }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-4">
|
||||
<label for="{{ form.link_color.id_for_label }}">Link Color</label>
|
||||
<input type="color" name="link_color" value="{{ form.link_color.value }}">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</form>
|
||||
{% endblock content %}
|
|
@ -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
|
||||
|
|
Ładowanie…
Reference in New Issue