From c9120785acc67d00fb28289a106f0f5a02b9a15b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 27 Dec 2015 11:23:33 +0100 Subject: [PATCH] misc: start a new 'theme' panel (#8777) --- MANIFEST.in | 1 + hobo/environment/forms.py | 2 +- hobo/environment/migrations/0010_variable_auto.py | 20 ++++++++ hobo/environment/models.py | 1 + hobo/environment/views.py | 18 ++++++- hobo/settings.py | 3 ++ hobo/static/css/style.css | 16 ++++++ hobo/templates/hobo/home.html | 1 + hobo/theme/__init__.py | 0 hobo/theme/templates/hobo/theme_home.html | 29 +++++++++++ hobo/theme/urls.py | 24 +++++++++ hobo/theme/utils.py | 61 +++++++++++++++++++++++ hobo/theme/views.py | 45 +++++++++++++++++ hobo/urls.py | 3 ++ 14 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 hobo/environment/migrations/0010_variable_auto.py create mode 100644 hobo/theme/__init__.py create mode 100644 hobo/theme/templates/hobo/theme_home.html create mode 100644 hobo/theme/urls.py create mode 100644 hobo/theme/utils.py create mode 100644 hobo/theme/views.py diff --git a/MANIFEST.in b/MANIFEST.in index 9831d7d..df91ded 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ recursive-include hobo/static *.css *.png *.js recursive-include hobo/templates *.html *.txt recursive-include hobo/profile/templates *.html *.txt +recursive-include hobo/theme/templates *.html *.txt recursive-include hobo/environment/templates *.html *.txt recursive-include hobo/locale *.po *.mo recursive-include hobo/environment/locale *.po *.mo diff --git a/hobo/environment/forms.py b/hobo/environment/forms.py index 7b1af00..e5513fc 100644 --- a/hobo/environment/forms.py +++ b/hobo/environment/forms.py @@ -119,7 +119,7 @@ class MandayeJSForm(BaseForm): class VariableForm(forms.ModelForm): class Meta: model = Variable - exclude = ('service_type', 'service_pk') + exclude = ('service_type', 'service_pk', 'auto') def __init__(self, service=None, **kwargs): self.service = service diff --git a/hobo/environment/migrations/0010_variable_auto.py b/hobo/environment/migrations/0010_variable_auto.py new file mode 100644 index 0000000..f63574e --- /dev/null +++ b/hobo/environment/migrations/0010_variable_auto.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('environment', '0009_mandayejs'), + ] + + operations = [ + migrations.AddField( + model_name='variable', + name='auto', + field=models.BooleanField(default=False), + preserve_default=True, + ), + ] diff --git a/hobo/environment/models.py b/hobo/environment/models.py index 16746f2..621e675 100644 --- a/hobo/environment/models.py +++ b/hobo/environment/models.py @@ -21,6 +21,7 @@ class Variable(models.Model): value = models.TextField(verbose_name=_('value'), blank=True, help_text=_('start with [ or { for a JSON document')) + auto = models.BooleanField(default=False) service_type = models.ForeignKey(ContentType, null=True) service_pk = models.PositiveIntegerField(null=True) service = generic.GenericForeignKey('service_type', 'service_pk') diff --git a/hobo/environment/views.py b/hobo/environment/views.py index 538cd75..eb01558 100644 --- a/hobo/environment/views.py +++ b/hobo/environment/views.py @@ -3,7 +3,7 @@ import string from django.conf import settings from django.core.urlresolvers import reverse_lazy -from django.http import HttpResponse, Http404 +from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import get_object_or_404 from django.views.generic.base import TemplateView from django.views.generic.edit import CreateView, UpdateView, DeleteView @@ -35,7 +35,8 @@ class VariablesView(TemplateView): def get_context_data(self, **kwargs): context = super(VariablesView, self).get_context_data(**kwargs) - context['variables'] = Variable.objects.filter(service_pk__isnull=True) + context['variables'] = Variable.objects.filter(auto=False, + service_pk__isnull=True) return context @@ -54,6 +55,19 @@ class VariableCreateView(CreateView): break return kwargs + def form_valid(self, form): + try: + self.object = Variable.objects.get( + name=form.instance.name, + service_pk__isnull=True) + except Variable.DoesNotExist: + self.object = form.save() + else: + self.object.auto = False + self.object.value = form.instance.value + self.object.save() + return HttpResponseRedirect(self.get_success_url()) + def get_success_url(self): if self.object.service is None: return reverse_lazy('environment-variables') diff --git a/hobo/settings.py b/hobo/settings.py index 8ebc8e0..ed7123f 100644 --- a/hobo/settings.py +++ b/hobo/settings.py @@ -41,6 +41,7 @@ INSTALLED_APPS = ( 'gadjo', 'hobo.environment', 'hobo.profile', + 'hobo.theme', 'hobo.deploy', ) @@ -166,6 +167,8 @@ MELLON_SUPERUSER_MAPPING = { 'is_superuser': 'true', } +THEMES_DIRECTORY = '/usr/share/publik/themes/' + MELLON_USERNAME_TEMPLATE = '{attributes[name_id_content]}' local_settings_file = os.environ.get('HOBO_SETTINGS_FILE', diff --git a/hobo/static/css/style.css b/hobo/static/css/style.css index ea5fc7f..592f9cd 100644 --- a/hobo/static/css/style.css +++ b/hobo/static/css/style.css @@ -102,3 +102,19 @@ h4.custom-variables.toggled:after { h4.untoggled + div { display: none; } + +div.objects-list > div > label { + display: block; + width: 100%; + border-left: 20px solid white; + min-height: 20px; + padding-left: 1ex; +} + +div.objects-list > div > label > input[type=radio] { + margin-right: 1.5ex; +} + +div.buttons { + margin: 1em 0; +} diff --git a/hobo/templates/hobo/home.html b/hobo/templates/hobo/home.html index b3a5f7d..6fdb384 100644 --- a/hobo/templates/hobo/home.html +++ b/hobo/templates/hobo/home.html @@ -10,6 +10,7 @@