Source code for shoop.xtheme.admin_module.views
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals
from django import forms
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http.response import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.views.generic.edit import FormView
from shoop.admin.utils.views import CreateOrUpdateView
from shoop.apps.provides import get_provide_objects
from shoop.xtheme._theme import (
get_current_theme, get_theme_by_identifier, set_current_theme
)
from shoop.xtheme.models import ThemeSettings
[docs]class ThemeConfigView(FormView):
"""
A view for listing and activating themes.
"""
template_name = "shoop/xtheme/admin/config.jinja"
form_class = ActivationForm
[docs] def get_context_data(self, **kwargs):
context = super(ThemeConfigView, self).get_context_data(**kwargs)
context["theme_classes"] = sorted(
[t for t in get_provide_objects("xtheme") if t.identifier],
key=lambda t: (t.name or t.identifier)
)
context["current_theme"] = get_current_theme()
return context
[docs]class ThemeConfigDetailView(CreateOrUpdateView):
"""
A view for configuring a single theme.
"""
model = ThemeSettings
template_name = "shoop/xtheme/admin/config_detail.jinja"
form_class = forms.Form
context_object_name = "theme_settings"
add_form_errors_as_messages = True
[docs] def get_object(self, queryset=None):
ts, _ = ThemeSettings.objects.get_or_create(theme_identifier=self.kwargs["theme_identifier"])
return ts
[docs] def get_theme(self):
"""
Get the theme object to configure.
:return: Theme object
:rtype: shoop.xtheme.Theme
"""
return get_theme_by_identifier(
identifier=self.kwargs["theme_identifier"],
settings_obj=self.object
)
[docs] def get_context_data(self, **kwargs):
context = super(ThemeConfigDetailView, self).get_context_data(**kwargs)
context["theme"] = self.get_theme()
return context
[docs] def get_success_url(self):
return reverse("shoop_admin:xtheme.config_detail", kwargs={
"theme_identifier": self.object.theme_identifier
})