From abbb666eaeb7d5dbe7352b9bb0993588adc690d9 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Thu, 1 Feb 2018 13:35:54 +0000 Subject: [PATCH] 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. --- .../templatetags/admin_interface_tags.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/admin_interface/templatetags/admin_interface_tags.py b/admin_interface/templatetags/admin_interface_tags.py index 4957d91..9a09d22 100644 --- a/admin_interface/templatetags/admin_interface_tags.py +++ b/admin_interface/templatetags/admin_interface_tags.py @@ -1,21 +1,20 @@ # -*- coding: utf-8 -*- -from django import template +from django import template, VERSION from admin_interface.models import Theme from admin_interface.version import __version__ register = template.Library() -try: - assignment_tag = register.assignment_tag -except AttributeError: - assignment_tag = register.simple_tag +if VERSION < (1, 9): + simple_tag = register.assignment_tag +else: + simple_tag = register.simple_tag -@assignment_tag(takes_context=True) +@simple_tag(takes_context=True) def get_admin_interface_theme(context): - theme = None request = context.get('request', None) @@ -31,6 +30,6 @@ def get_admin_interface_theme(context): return theme -@assignment_tag(takes_context=False) +@simple_tag(takes_context=False) def get_admin_interface_version(): return __version__