2015-12-27 11:23:33 +01:00
|
|
|
# hobo - portal to configure and deploy applications
|
|
|
|
# Copyright (C) 2015 Entr'ouvert
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-11-16 10:31:29 +01:00
|
|
|
import colorsys
|
|
|
|
import random
|
|
|
|
|
2016-05-28 18:10:09 +02:00
|
|
|
from django.contrib import messages
|
2020-05-07 20:01:20 +02:00
|
|
|
from django.urls import reverse
|
2023-03-29 12:10:39 +02:00
|
|
|
from django.utils.translation import gettext as _
|
2015-12-27 11:23:33 +01:00
|
|
|
from django.views.generic import RedirectView, TemplateView
|
|
|
|
|
2017-09-06 15:00:23 +02:00
|
|
|
from hobo.environment.forms import VariablesFormMixin
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2017-09-06 15:00:23 +02:00
|
|
|
from .forms import ThemeOptionsForm
|
2015-12-27 11:23:33 +01:00
|
|
|
from .utils import get_selected_theme, get_themes, set_theme
|
|
|
|
|
|
|
|
|
|
|
|
class HomeView(TemplateView):
|
|
|
|
template_name = 'hobo/theme_home.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super().get_context_data(**kwargs)
|
|
|
|
|
2016-11-16 10:31:29 +01:00
|
|
|
def hsv(theme):
|
|
|
|
theme_colour = theme.get('variables').get('theme_color') or '#FFFFFF'
|
|
|
|
if theme_colour == '#FFFFFF':
|
|
|
|
return (1, 1, 1)
|
|
|
|
theme_rgb = [int(x, 16) for x in (theme_colour[1:3], theme_colour[3:5], theme_colour[5:])]
|
|
|
|
theme_hsv = colorsys.rgb_to_hsv(*(1.0 * x / 255 for x in theme_rgb))
|
|
|
|
return theme_hsv
|
|
|
|
|
2015-12-27 11:23:33 +01:00
|
|
|
context['themes'] = get_themes()
|
2016-11-16 10:31:29 +01:00
|
|
|
if random.random() < 0.1:
|
|
|
|
# easter egg, sometimes it gets sorted by colour
|
|
|
|
context['themes'].sort(key=hsv)
|
2015-12-27 11:23:33 +01:00
|
|
|
context['selected_theme'] = get_selected_theme()
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2015-12-27 11:23:33 +01:00
|
|
|
home = HomeView.as_view()
|
|
|
|
|
|
|
|
|
|
|
|
class SelectView(RedirectView):
|
|
|
|
permanent = False
|
|
|
|
|
|
|
|
def get_redirect_url(self):
|
2021-12-16 20:23:16 +01:00
|
|
|
if self.request.method == 'POST' and 'theme' in self.request.POST:
|
2020-03-27 11:30:41 +01:00
|
|
|
set_theme(self.request.POST['theme'])
|
|
|
|
messages.info(
|
|
|
|
self.request, _('The theme has been changed, it will soon be visible on the sites.')
|
2021-05-14 18:39:27 +02:00
|
|
|
)
|
2015-12-27 11:23:33 +01:00
|
|
|
return reverse('theme-home')
|
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2015-12-27 11:23:33 +01:00
|
|
|
select = SelectView.as_view()
|
2017-09-06 15:00:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class OptionsView(VariablesFormMixin, TemplateView):
|
|
|
|
template_name = 'hobo/theme_options.html'
|
|
|
|
variables = ['global_title']
|
|
|
|
form_class = ThemeOptionsForm
|
|
|
|
|
2021-05-14 18:39:27 +02:00
|
|
|
|
2017-09-06 15:00:23 +02:00
|
|
|
options = OptionsView.as_view()
|