Browse Source

Django 2.0 compatibility.

master 0.1.8
Erik Stein 4 years ago
parent
commit
4ae13cdb33
  1. 3
      CHANGES
  2. 46
      shared/media_archive/mixins.py

3
CHANGES

@ -1,3 +1,6 @@
0.1.8 2021-04-26
- Django 2.0 compatibility
0.1.7 2021-04-26 0.1.7 2021-04-26
- Use window.jQuery instead of django.jQuery - Use window.jQuery instead of django.jQuery
- Fix in field choices setup - Fix in field choices setup

46
shared/media_archive/mixins.py

@ -1,3 +1,4 @@
import django
from django.http import JsonResponse from django.http import JsonResponse
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@ -23,29 +24,34 @@ class DropUploadAdminMixin:
def upload(self, request): def upload(self, request):
# We must initialize a fake-ChangeList to be able to get the currently # We must initialize a fake-ChangeList to be able to get the currently
# selected categories. # selected categories.
# Code copied from django.contrib.admin.options.ModelAdmin.changelist_view
if not self.has_change_permission(request, None):
raise PermissionDenied
list_display = self.get_list_display(request) if django.VERSION >= (2, 0, 0):
list_display_links = self.get_list_display_links(request, list_display) changelist = self.get_changelist_instance(request)
list_filter = self.get_list_filter(request)
search_fields = self.get_search_fields(request)
list_select_related = self.get_list_select_related(request)
# Check actions to see if any are available on this changelist else:
actions = self.get_actions(request) # Code copied from django.contrib.admin.options.ModelAdmin.changelist_view
if actions: if not self.has_change_permission(request, None):
# Add the action checkboxes if there are any actions available. raise PermissionDenied
list_display = ['action_checkbox'] + list(list_display)
ChangeList = self.get_changelist(request) list_display = self.get_list_display(request)
changelist = ChangeList( list_display_links = self.get_list_display_links(request, list_display)
request, self.model, list_display, list_filter = self.get_list_filter(request)
list_display_links, list_filter, self.date_hierarchy, search_fields = self.get_search_fields(request)
search_fields, list_select_related, self.list_per_page, list_select_related = self.get_list_select_related(request)
self.list_max_show_all, self.list_editable, self,
) # Check actions to see if any are available on this changelist
actions = self.get_actions(request)
if actions:
# Add the action checkboxes if there are any actions available.
list_display = ['action_checkbox'] + list(list_display)
ChangeList = self.get_changelist(request)
changelist = ChangeList(
request, self.model, list_display,
list_display_links, list_filter, self.date_hierarchy,
search_fields, list_select_related, self.list_per_page,
self.list_max_show_all, self.list_editable, self,
)
# Put uploaded file in selected categories # Put uploaded file in selected categories
if changelist.result_list: if changelist.result_list:

Loading…
Cancel
Save