-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Django 2.0 compatibility problems #651
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import django | ||
from django import template | ||
from django.contrib import admin | ||
from django.contrib.admin import AdminSite | ||
from django.http import HttpRequest | ||
from django.core.urlresolvers import reverse, resolve | ||
|
||
try: | ||
from django.urls import reverse, resolve | ||
except: | ||
from django.core.urlresolvers import reverse, resolve | ||
|
||
try: | ||
from django.utils.six import string_types | ||
|
@@ -16,9 +21,12 @@ | |
from suit.config import get_config | ||
|
||
register = template.Library() | ||
if django.VERSION >= (2, 0, 0, 'final', 0): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also, you can compare against a "coarse" version, not a very specific one. Makes it a little more readable. if django.VERSION < (1, 9):
simple_tag = register.assignment_tag
else:
simple_tag = register.simple_tag |
||
simple_tag = register.simple_tag | ||
else: | ||
simple_tag = register.assignment_tag | ||
|
||
|
||
@register.assignment_tag(takes_context=True) | ||
@simple_tag(takes_context=True) | ||
def get_menu(context, request): | ||
""" | ||
:type request: HttpRequest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Django settings for testproject project. | ||
import django | ||
|
||
DEBUG = True | ||
TEMPLATE_DEBUG = DEBUG | ||
|
@@ -27,13 +28,24 @@ | |
'django.template.loaders.app_directories.Loader', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.middleware.common.CommonMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
) | ||
if django.VERSION >= (2, 0, 0, 'final', 0): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new-style middleware can be used since 1.10. |
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
else: | ||
MIDDLEWARE_CLASSES = ( | ||
'django.middleware.common.CommonMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'suit.tests.urls' | ||
TEMPLATE_DIRS = () | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,9 +136,15 @@ def __init__(self, attrs=None): | |
widgets = [SuitDateWidget, SuitTimeWidget] | ||
forms.MultiWidget.__init__(self, widgets, attrs) | ||
|
||
def format_output(self, rendered_widgets): | ||
out_tpl = '<div class="datetime">%s %s</div>' | ||
return mark_safe(out_tpl % (rendered_widgets[0], rendered_widgets[1])) | ||
def render(self, name, value, attrs=None): | ||
html = super(SuitSplitDateTimeWidget, self).render(name, value, attrs) | ||
|
||
out_tpl = '<div class="datetime">%s</div>' | ||
return mark_safe(out_tpl % html) | ||
|
||
# def format_output(self, rendered_widgets): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is needed? |
||
# out_tpl = '<div class="datetime">%s %s</div>' | ||
# return mark_safe(out_tpl % (rendered_widgets[0], rendered_widgets[1])) | ||
|
||
|
||
def _make_attrs(attrs, defaults=None, classes=None): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is far too broad, I suggest to narrow it to
ImportError
exception: