Bläddra i källkod

Merge branch 'feature/django-2.0' into dev

Denis K 7 år sedan
förälder
incheckning
7e6aaf6f43

+ 21 - 8
.travis.yml

@@ -15,6 +15,7 @@ env:
   - DJANGO="<1.10"
   - DJANGO="<1.11"
   - DJANGO="<1.12"
+  - DJANGO="<2.1"
 before_install:
   - export DJANGO_SETTINGS_MODULE=jet.tests.settings
 install:
@@ -35,22 +36,34 @@ matrix:
       env: DJANGO="<1.9"
     - python: 2.6
       env: DJANGO="<1.10"
-    - python: 3.2
-      env: DJANGO="<1.10"
-    - python: 3.3
-      env: DJANGO="<1.10"
     - python: 2.6
       env: DJANGO="<1.11"
-    - python: 3.2
-      env: DJANGO="<1.11"
-    - python: 3.3
-      env: DJANGO="<1.11"
     - python: 2.6
       env: DJANGO="<1.12"
+    - python: 2.6
+      env: DJANGO="<2.1"
+
+    - python: 2.7
+      env: DJANGO="<2.1"
+
+    - python: 3.2
+      env: DJANGO="<1.10"
+    - python: 3.2
+      env: DJANGO="<1.11"
     - python: 3.2
       env: DJANGO="<1.12"
+    - python: 3.2
+      env: DJANGO="<2.1"
+
+    - python: 3.3
+      env: DJANGO="<1.10"
+    - python: 3.3
+      env: DJANGO="<1.11"
     - python: 3.3
       env: DJANGO="<1.12"
+    - python: 3.3
+      env: DJANGO="<2.1"
+
     - python: 3.5
       env: DJANGO="<1.7"
     - python: 3.5

+ 6 - 5
jet/dashboard/forms.py

@@ -3,6 +3,7 @@ from django import forms
 from django.core.exceptions import ValidationError
 from jet.dashboard.models import UserDashboardModule
 from jet.dashboard.utils import get_current_dashboard
+from jet.utils import user_is_authenticated
 
 
 class UpdateDashboardModulesForm(forms.Form):
@@ -17,7 +18,7 @@ class UpdateDashboardModulesForm(forms.Form):
     def clean(self):
         data = super(UpdateDashboardModulesForm, self).clean()
 
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         try:
@@ -68,7 +69,7 @@ class AddUserDashboardModuleForm(forms.ModelForm):
     def clean(self):
         data = super(AddUserDashboardModuleForm, self).clean()
 
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         if 'app_label' in data:
@@ -110,7 +111,7 @@ class UpdateDashboardModuleCollapseForm(forms.ModelForm):
     def clean(self):
         data = super(UpdateDashboardModuleCollapseForm, self).clean()
 
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         if self.instance.user != self.request.user.pk:
@@ -131,7 +132,7 @@ class RemoveDashboardModuleForm(forms.ModelForm):
     def clean(self):
         cleaned_data = super(RemoveDashboardModuleForm, self).clean()
 
-        if not self.request.user.is_authenticated() or self.instance.user != self.request.user.pk:
+        if not user_is_authenticated(self.request.user) or self.instance.user != self.request.user.pk:
             raise ValidationError('error')
 
         return cleaned_data
@@ -156,7 +157,7 @@ class ResetDashboardForm(forms.Form):
         data = super(ResetDashboardForm, self).clean()
         data['app_label'] = data['app_label'] if data['app_label'] else None
 
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         return data

+ 2 - 1
jet/dashboard/templatetags/jet_dashboard_tags.py

@@ -3,9 +3,10 @@ from django import template
 from jet.dashboard.utils import get_current_dashboard
 
 register = template.Library()
+assignment_tag = register.assignment_tag if hasattr(register, 'assignment_tag') else register.simple_tag
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def get_dashboard(context, location):
     dashboard_cls = get_current_dashboard(location)
 

+ 10 - 2
jet/dashboard/urls.py

@@ -1,11 +1,19 @@
 import django
 from django.conf.urls import url
-from django.views.i18n import javascript_catalog
+
+try:
+    from django.views.i18n import JavaScriptCatalog
+    javascript_catalog = JavaScriptCatalog.as_view()
+except ImportError:  # Django < 2.0
+    from django.views.i18n import javascript_catalog
+
 from jet.dashboard import dashboard
 from jet.dashboard.views import update_dashboard_modules_view, add_user_dashboard_module_view, \
     update_dashboard_module_collapse_view, remove_dashboard_module_view, UpdateDashboardModuleView, \
     load_dashboard_module_view, reset_dashboard_view
 
+app_name = 'dashboard'
+
 urlpatterns = [
     url(
         r'^module/(?P<pk>\d+)/$',
@@ -45,7 +53,7 @@ urlpatterns = [
     url(
         r'^jsi18n/$',
         javascript_catalog,
-        {'packages': ('jet',)},
+        {'packages': 'jet'},
         name='jsi18n'
     ),
 ]

+ 2 - 2
jet/dashboard/views.py

@@ -11,7 +11,7 @@ from django.views.decorators.http import require_POST, require_GET
 from jet.dashboard.forms import UpdateDashboardModulesForm, AddUserDashboardModuleForm, \
     UpdateDashboardModuleCollapseForm, RemoveDashboardModuleForm, ResetDashboardForm
 from jet.dashboard.models import UserDashboardModule
-from jet.utils import JsonResponse, get_app_list, SuccessMessageMixin
+from jet.utils import JsonResponse, get_app_list, SuccessMessageMixin, user_is_authenticated
 from django.views.generic import UpdateView
 from django.utils.translation import ugettext_lazy as _
 
@@ -216,7 +216,7 @@ def load_dashboard_module_view(request, pk):
     result = {'error': False}
 
     try:
-        if not request.user.is_authenticated() or not request.user.is_staff:
+        if not user_is_authenticated(request.user) or not request.user.is_staff:
             raise ValidationError('error')
 
         instance = UserDashboardModule.objects.get(pk=pk, user=request.user.pk)

+ 6 - 5
jet/forms.py

@@ -5,8 +5,9 @@ from django.contrib.contenttypes.models import ContentType
 from django.core.exceptions import ValidationError
 from django.db.models import Q
 import operator
+
 from jet.models import Bookmark, PinnedApplication
-from jet.utils import get_model_instance_label
+from jet.utils import get_model_instance_label, user_is_authenticated
 from functools import reduce
 
 try:
@@ -27,7 +28,7 @@ class AddBookmarkForm(forms.ModelForm):
 
     def clean(self):
         data = super(AddBookmarkForm, self).clean()
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         if not self.request.user.has_perm('jet.change_bookmark'):
             raise ValidationError('error')
@@ -49,7 +50,7 @@ class RemoveBookmarkForm(forms.ModelForm):
 
     def clean(self):
         data = super(RemoveBookmarkForm, self).clean()
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         if self.instance.user != self.request.user.pk:
             raise ValidationError('error')
@@ -71,7 +72,7 @@ class ToggleApplicationPinForm(forms.ModelForm):
 
     def clean(self):
         data = super(ToggleApplicationPinForm, self).clean()
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
         return data
 
@@ -108,7 +109,7 @@ class ModelLookupForm(forms.Form):
     def clean(self):
         data = super(ModelLookupForm, self).clean()
 
-        if not self.request.user.is_authenticated() or not self.request.user.is_staff:
+        if not user_is_authenticated(self.request.user) or not self.request.user.is_staff:
             raise ValidationError('error')
 
         try:

+ 1 - 0
jet/static/jet/css/_header.scss

@@ -9,6 +9,7 @@
   padding: 14px 32px 14px 36px;
   text-align: center;
   position: relative;
+  height: auto !important;
   min-height: 52px;
   box-sizing: border-box;
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/default/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/default/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/green/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/green/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-blue/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-blue/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-gray/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-gray/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-green/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-green/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-violet/base.css


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
jet/static/jet/css/themes/light-violet/base.css.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 1
jet/static/jet/css/vendor.css


+ 8 - 4
jet/templates/admin/base.html

@@ -17,11 +17,14 @@
 
 {% block extrastyle %}{% endblock %}
 {% if LANGUAGE_BIDI %}<link rel="stylesheet" type="text/css" href="{% block stylesheet_rtl %}{% static "admin/css/rtl.css" %}{% endblock %}" />{% endif %}
+{% jet_get_date_format as date_format %}
+{% jet_get_time_format as time_format %}
+{% jet_get_datetime_format as datetime_format %}
 
 <script type="text/javascript" charset="utf-8">
-    var DATE_FORMAT = "{% jet_get_date_format %}";
-    var TIME_FORMAT = "{% jet_get_time_format %}";
-    var DATETIME_FORMAT = "{% jet_get_datetime_format %}";
+    var DATE_FORMAT = "{{ date_format }}";
+    var TIME_FORMAT = "{{ time_format }}";
+    var DATETIME_FORMAT = "{{ datetime_format }}";
 </script>
 <script type="text/javascript" src="{% url 'jet:jsi18n' %}"></script>
 <script src="{% static "jet/js/build/bundle.min.js" as url %}{{ url|jet_append_version }}"></script>
@@ -109,7 +112,8 @@
 
     {% block footer %}<div id="footer"></div>{% endblock %}
 
-    {% jet_delete_confirmation_context %}
+    {% jet_delete_confirmation_context as delete_confirmation_context %}
+    {{ delete_confirmation_context }}
 
     {% jet_change_form_sibling_links_enabled as show_siblings %}
     {% if change and show_siblings %}

+ 16 - 15
jet/templatetags/jet_tags.py

@@ -24,29 +24,30 @@ except ImportError:
 
 
 register = template.Library()
+assignment_tag = register.assignment_tag if hasattr(register, 'assignment_tag') else register.simple_tag
 
 
-@register.simple_tag
+@assignment_tag
 def jet_get_date_format():
     return get_format('DATE_INPUT_FORMATS')[0]
 
 
-@register.simple_tag
+@assignment_tag
 def jet_get_time_format():
     return get_format('TIME_INPUT_FORMATS')[0]
 
 
-@register.simple_tag
+@assignment_tag
 def jet_get_datetime_format():
     return get_format('DATETIME_INPUT_FORMATS')[0]
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_get_menu(context):
     return get_menu_items(context)
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_get_bookmarks(user):
     if user is None:
         return None
@@ -110,7 +111,7 @@ def jet_select2_lookups(field):
     return field
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_get_current_theme(context):
     if 'request' in context and 'JET_THEME' in context['request'].COOKIES:
         theme = context['request'].COOKIES['JET_THEME']
@@ -121,12 +122,12 @@ def jet_get_current_theme(context):
     return settings.JET_DEFAULT_THEME
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_get_themes():
     return settings.JET_THEMES
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_get_current_version():
     return VERSION
 
@@ -139,12 +140,12 @@ def jet_append_version(url):
         return '%s?v=%s' % (url, VERSION)
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_get_side_menu_compact():
     return settings.JET_SIDE_MENU_COMPACT
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_change_form_sibling_links_enabled():
     return settings.JET_CHANGE_FORM_SIBLING_LINKS
 
@@ -198,17 +199,17 @@ def jet_sibling_object(context, next):
     }
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_previous_object(context):
     return jet_sibling_object(context, False)
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_next_object(context):
     return jet_sibling_object(context, True)
 
 
-@register.assignment_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_popup_response_data(context):
     if context.get('popup_response_data'):
         return context['popup_response_data']
@@ -221,14 +222,14 @@ def jet_popup_response_data(context):
     })
 
 
-@register.simple_tag(takes_context=True)
+@assignment_tag(takes_context=True)
 def jet_delete_confirmation_context(context):
     if context.get('deletable_objects') is None and context.get('deleted_objects') is None:
         return ''
     return mark_safe('<div class="delete-confirmation-marker"></div>')
 
 
-@register.assignment_tag
+@assignment_tag
 def jet_static_translation_urls():
     language_codes = get_possible_language_codes()
 

+ 1 - 1
jet/tests/models.py

@@ -13,7 +13,7 @@ class TestModel(models.Model):
 
 @python_2_unicode_compatible
 class RelatedToTestModel(models.Model):
-    field = models.ForeignKey(TestModel)
+    field = models.ForeignKey(TestModel, on_delete=models.CASCADE)
 
     def __str__(self):
         return self.field

+ 1 - 1
jet/tests/settings.py

@@ -24,7 +24,7 @@ INSTALLED_APPS = (
     'jet.tests',
 )
 
-MIDDLEWARE_CLASSES = (
+MIDDLEWARE = MIDDLEWARE_CLASSES = (
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',

+ 17 - 6
jet/tests/urls.py

@@ -4,12 +4,23 @@ from django.contrib import admin
 
 admin.autodiscover()
 
-urlpatterns = [
-    url(r'^jet/', include('jet.urls', 'jet')),
-    url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
-    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-    url(r'^admin/', include(admin.site.urls)),
-]
+
+try:
+    from django.urls import path
+
+    urlpatterns = [
+        url(r'^jet/', include('jet.urls', 'jet')),
+        url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
+        url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+        path('admin/', admin.site.urls),
+    ]
+except ImportError:  # Django < 2.0
+    urlpatterns = [
+        url(r'^jet/', include('jet.urls', 'jet')),
+        url(r'^jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
+        url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+        url(r'^admin/', include(admin.site.urls)),
+    ]
 
 if django.VERSION[:2] < (1, 8):
     from django.conf.urls import patterns

+ 11 - 2
jet/urls.py

@@ -1,8 +1,17 @@
 import django
 from django.conf.urls import url
-from django.views.i18n import javascript_catalog
+
+try:
+    from django.views.i18n import JavaScriptCatalog
+    javascript_catalog = JavaScriptCatalog.as_view()
+except ImportError:  # Django < 2.0
+    from django.views.i18n import javascript_catalog
+
 from jet.views import add_bookmark_view, remove_bookmark_view, toggle_application_pin_view, model_lookup_view
 
+
+app_name = 'jet'
+
 urlpatterns = [
     url(
         r'^add_bookmark/$',
@@ -27,7 +36,7 @@ urlpatterns = [
     url(
         r'^jsi18n/$',
         javascript_catalog,
-        {'packages': ('django.conf', 'django.contrib.admin', 'jet',)},
+        {'packages': 'django.contrib.admin+jet'},
         name='jsi18n'
     ),
 ]

+ 8 - 1
jet/utils.py

@@ -250,7 +250,7 @@ def get_possible_language_codes():
 
 
 def get_original_menu_items(context):
-    if context.get('user') and context['user'].is_authenticated():
+    if context.get('user') and user_is_authenticated(context['user']):
         pinned_apps = PinnedApplication.objects.filter(user=context['user'].pk).values_list('app_label', flat=True)
     else:
         pinned_apps = []
@@ -447,3 +447,10 @@ def context_to_dict(context):
         context = flat
 
     return context
+
+
+def user_is_authenticated(user):
+    if not hasattr(user.is_authenticated, '__call__'):
+        return user.is_authenticated
+    else:
+        return user.is_authenticated()

Vissa filer visades inte eftersom för många filer har ändrats