Avoid deprecation warning about assignment_tag

Even though the try/except is Django 2.0 compatible, it still
accesses the deprecated template tag, and therefore it emits a
warning in the console, whereas it's actually fixed.

I tried to swap the try and the catch, but it doesn't work:
`simple_tag` existed before 1.9 but in a non-compatible form.

I've changed the decorator name we use to match the new Django version,
it should make the codebase more future proof.
pull/32/head
Bruno Alla 2018-02-01 13:35:54 +00:00
parent d48fc882f1
commit abbb666eae
1 changed files with 7 additions and 8 deletions

View File

@ -1,21 +1,20 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import template from django import template, VERSION
from admin_interface.models import Theme from admin_interface.models import Theme
from admin_interface.version import __version__ from admin_interface.version import __version__
register = template.Library() register = template.Library()
try: if VERSION < (1, 9):
assignment_tag = register.assignment_tag simple_tag = register.assignment_tag
except AttributeError: else:
assignment_tag = register.simple_tag simple_tag = register.simple_tag
@assignment_tag(takes_context=True) @simple_tag(takes_context=True)
def get_admin_interface_theme(context): def get_admin_interface_theme(context):
theme = None theme = None
request = context.get('request', None) request = context.get('request', None)
@ -31,6 +30,6 @@ def get_admin_interface_theme(context):
return theme return theme
@assignment_tag(takes_context=False) @simple_tag(takes_context=False)
def get_admin_interface_version(): def get_admin_interface_version():
return __version__ return __version__