Compare commits

...

3 Commits

Author SHA1 Message Date
Fabio Caccamo 486bfa9aba Updated version 2017-06-09 11:58:26 +02:00
Fabio Caccamo e19cd51803 Added per-request cache to get_admin_interface_theme template tag #19 2017-06-09 11:58:10 +02:00
Fabio Caccamo 2d8eeee425 Updated README [ci skip] 2017-05-24 12:46:42 +02:00
4 changed files with 52 additions and 8 deletions
+24 -1
View File
@@ -27,7 +27,7 @@ INSTALLED_APPS = (
#... #...
'admin_interface', 'admin_interface',
'flat_responsive', 'flat_responsive',
'flat', #if django version < 1.9 'flat', # only if django version < 1.9
'colorfield', 'colorfield',
#... #...
'django.contrib.admin', 'django.contrib.admin',
@@ -44,6 +44,29 @@ INSTALLED_APPS = (
- Run ``python manage.py collectstatic --clear`` - Run ``python manage.py collectstatic --clear``
- Restart your application server - Restart your application server
## Optional themes
This package ships with optional themes as fixtures, they can be installed using the [loaddata admin command](https://docs.djangoproject.com/en/1.11/ref/django-admin/#django-admin-loaddata). Optional themes are activated on installation.
##### Django theme (default):
Run ``python manage.py loaddata admin_interface_theme_django.json``
##### Bootstrap theme:
Run ``python manage.py loaddata admin_interface_theme_bootstrap.json``
##### Foundation theme:
Run ``python manage.py loaddata admin_interface_theme_foundation.json``
### Add more themes
You can add a theme you've created through the admin to this repository by [sending us a PR](http://makeapullrequest.com/). Here are the steps to follow to add :
1. Export your exact theme as fixture using the `dumpdata` admin command:
``python manage.py dumpdata admin_interface.Theme --indent 4 -o admin_interface_theme_{{name}}.json --pks=N``
2. Copy the generated json file into the fixtures folder *(making sure its name starts with `admin_interface_theme_` to avoid clashes with fixtures that might be provided by other third party apps)*.
3. Remove the `"pk"` from the fixture and make sure the `active` field is set to `true` *(in this way a theme is automatically activated when installed)*.
4. Edit the section above to document your theme.
## Screenshots ## Screenshots
###### Admin login ###### Admin login
@@ -11,5 +11,17 @@ register = template.Library()
@register.assignment_tag(takes_context = True) @register.assignment_tag(takes_context = True)
def get_admin_interface_theme(context): def get_admin_interface_theme(context):
return Theme.get_active_theme() theme = None
request = context.get('request', None)
if request:
theme = getattr(request, 'admin_interface_theme', None)
if not theme:
theme = Theme.get_active_theme()
if request:
request.admin_interface_theme = theme
return theme
+1 -1
View File
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__version__ = '0.4.5' __version__ = '0.4.6'
+14 -5
View File
@@ -2,6 +2,7 @@
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory
from django.template import Context, Template from django.template import Context, Template
import random import random
@@ -13,16 +14,14 @@ from admin_interface.models import Theme
class AdminInterfaceTestCase(TestCase): class AdminInterfaceTestCase(TestCase):
def setUp(self): def setUp(self):
self.request_factory = RequestFactory()
pass pass
def tearDown(self): def tearDown(self):
shutil.rmtree(settings.MEDIA_ROOT, ignore_errors=True) shutil.rmtree(settings.MEDIA_ROOT, ignore_errors=True)
pass pass
def __render_template(self, string, context=None): def __render_template(self, string, context):
context = context or {}
context = Context(context)
return Template(string).render(context) return Template(string).render(context)
def __test_active_theme(self): def __test_active_theme(self):
@@ -104,7 +103,17 @@ class AdminInterfaceTestCase(TestCase):
def test_templatetags(self): def test_templatetags(self):
Theme.objects.all().delete() Theme.objects.all().delete()
rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_theme as theme %}{{ theme.name }}') context = Context({})
rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_theme as theme %}{{ theme.name }}', context)
self.assertEqual(rendered, 'Django')
def test_templatetags_with_request(self):
Theme.objects.all().delete()
context = Context({
'request': self.request_factory.get('/')
})
rendered = self.__render_template('{% load admin_interface_tags %}{% get_admin_interface_theme as theme %}{{ theme.name }}', context)
self.assertEqual(rendered, 'Django') self.assertEqual(rendered, 'Django')
def test_repr(self): def test_repr(self):