Commit graph

329 commits

Author SHA1 Message Date
blag
2bb6a677fe
Check that the parent model is a SortableMixin before enabling sorting them 2020-05-19 18:37:55 -07:00
Brandon Taylor
db162bf890 Fix inline admin templates to display FontAwesome icons and be Django 2 & 3 compatible.
Version bump to 2.2.3.
Updated READMEs.
2020-01-14 20:05:25 -05:00
Brandon Taylor
bee77a28db Version bump to 2.2.2
Updated READMEs
2020-01-14 18:55:54 -05:00
Brandon Taylor
723ddda6c2 FontAwesome Icons in Inline templates
- Fixed VERSION check to enable correct templates if VERSION > 2
2020-01-14 18:53:07 -05:00
Brandon Taylor
257e22fb8a Version bump to 2.2.1
Updated READMEs
2020-01-14 18:31:00 -05:00
Brandon Taylor
8311881f2f Fixed overzealous selector for sortable tabular inlines. 2020-01-14 18:26:49 -05:00
Brandon Taylor
99bf2fb5f2 Version bump to 2.2.0
Updated README.
Updated models to be compliant with Django 3.
2019-12-07 17:36:54 -05:00
Chris Tapper
01fc6a18b6 Remove deprecated template tag libraries.
`{% load staticfiles %}` and `{% load adminstatic %}` were
[deprecated in Django 2.1](https://docs.djangoproject.com/en/2.2/releases/2.1/#features-deprecated-in-2-1),
and [removed in Django 3.0](https://docs.djangoproject.com/en/dev/releases/3.0/#features-removed-in-3-0).

Instead, `{% load static %}` should be used.
2019-10-27 18:51:55 +01:00
Brandon Taylor
5cb0f1ebf8 Fix Font Awesome Icon selection scoping
- Narrowed scoping of selector so it doesn't interfere with custom widgets after drop
- Version bump to 2.0.18
- Updated README
2019-08-28 07:53:50 -04:00
Brandon Taylor
d22d4d174c Version bump to 2.1.17.
Updated README
2019-07-20 11:36:54 -04:00
Brandon Taylor
71bd1be135
Merge pull request #214 from SerhiyRomanov/ukrainian_translation
Fixed empty django.mo file for Ukrainian translation (sorry for this)
2019-07-17 16:44:48 -04:00
Serhiy Romanov
9def367234 Fixed empty django.mo file for Ukrainian translation (sorry for this) 2019-07-17 22:45:14 +03:00
Brandon Taylor
e069cc39c0 Version bump to 2.1.6
Updated readme with credit for Ukrainian translations.
2019-06-22 20:42:35 -04:00
Serhiy Romanov
f839d4d9fa Add Ukrainian translation 2019-06-22 00:04:10 +03:00
Brandon Taylor
14436afb6f Meged changes
Updated readme
Proper version bump to 2.1.15
2019-06-03 14:29:17 -04:00
Brandon Taylor
8fc4956adc Removed old .rst for README.
Updated README.md
Version bump to 2.1.11
Updated setup.py to support markdown for long description
2019-06-03 14:26:01 -04:00
Brandon Taylor
bfb1969e50 Removed unused imports 2019-06-03 14:13:21 -04:00
Brandon Taylor
97003cd5cc Added matching for PAGE_VAR 2019-04-17 11:24:43 -04:00
Brandon Taylor
debe9db327 Added matching for PAGE_VAR 2019-04-17 11:22:21 -04:00
Brandon Taylor
eff9872799 Version bump to 2.1.14
Updated readme
2019-02-23 07:59:00 -05:00
Stephan Jaekel
cdce5e453b Improve querystring filtering.
This changed excludes more querystring parameters and relies on Django's
knowledge of what keys should be excluded. It basically does the same
what the ChangeList class would do [1].

[1] https://github.com/django/django/blob/master/django/contrib/admin/views/main.py#L91-L102
2019-02-22 11:14:07 +01:00
Brandon Taylor
e2bee04990 Fix sorting for raw_id objects
- Added common function to get querystring filters
- Excluded querystring parameters used for raw_id fields
- Version bump to 2.1.13
- Updated readme
2019-02-21 09:56:08 -05:00
Brandon Taylor
26b11e8b41 Version bump to 2.1.12
Updates to readme
2019-02-14 16:07:35 -05:00
Brandon Taylor
478600fd5a - Appplied filters to queryset check for length of items in change list
- Added conditional in template to show/hide sort link
2019-02-14 16:04:17 -05:00
Brandon Taylor
1e395ab3f0 Properly handle querystring filters 2019-02-12 11:15:17 -05:00
Brandon Taylor
de393db7c4 Version bump to 2.1.11
Updated README.
2019-01-17 13:34:33 -05:00
Brandon Taylor
ff4dc3184f Fix Missing CSRF Token
- Set default CSRF_HEADER_NAME to previous value instead of Django default
- Added csrfmiddlewaretoken value to Ajax POST data from sorting views.
- Moved csrf token template tag inside object representation form
2019-01-17 13:32:02 -05:00
Brandon Taylor
c15f307e5a CSRF_HEADER_NAME
- Get CSRF_HEADER_NAME from settings to pass to jquery.django-csrf.html template
- Version bump to 2.1.10
- Update readme
2019-01-14 09:40:54 -05:00
Brandon Taylor
b1258afcea Version bump to 2.1.9
Updated readme.
Added filter_kwargs as a replacement to extra_filters.
2018-10-10 14:02:11 -04:00
Brandon Taylor
fabd78e5be Add Positional Arguments to Get Next/Previous
Added filter_args array argument to be passed to get_next/previous methods.
Added extra boolean fields to project model for testing.
2018-10-06 09:46:34 -04:00
Brandon Taylor
2688003ac9 Update Readme
Version bump to 2.1.8
2018-10-05 10:56:48 -04:00
Brandon Taylor
1ed27acbaa Fix Sort Link
Updated conditional to not add filter expression if a search has been performed on the queryset.
2018-10-05 10:53:56 -04:00
Brandon Taylor
6d5f9e97b4 Added after_sorting method to SortableAdminBase class that can be defined on a model admin to be executed after sorting has occurred. 2018-07-09 07:49:55 -04:00
Brandon Taylor
3f49a72a6d Version bump to 2.1.7.
Updated readme.
2018-06-29 08:27:11 -04:00
Brandon Taylor
e87a1444b4 Fixed import paths. 2018-06-29 08:23:22 -04:00
Brandon Taylor
612de9ea9d Updates to README.
Version bump to 2.1.6
2018-06-18 11:58:52 -04:00
Brandon Taylor
5ad2c0e4ec Merged after-sort-callback branch and fixed conflicts. 2018-06-18 11:41:20 -04:00
Brandon Taylor
e35f36b25a Refactored sorting JS files to be includes so that server-side variables may be passed to them.
Added 'after_sorting_js_callback_name' attribute to SortableAdminBase.
Added callback to be executed after sorting for each of the possible sorting scenarios.
Added custom template examples to add a callback to be executed when sorting is finished.
2018-06-18 11:40:24 -04:00
Brandon Taylor
4e0a3cc0ec Version bump to 2.1.5
Updated README(s).
Updated email address in AUTHORS.
2018-05-17 12:54:44 -04:00
timur-orudzhov
4add46c6de fix typo 2018-05-16 22:57:13 +03:00
timur-orudzhov
f135ad906d add support for django admin filters 2018-05-16 16:05:40 +03:00
Luka Matijevic
b4a01720db Added Croatian translation 2018-03-22 19:04:02 +01:00
René Fleschenberg
78c2e91aac Unlocalize object IDs
Fixes #187
2018-03-21 13:03:08 +01:00
Brandon Taylor
fa8a5f12a8 Merge branch 'master' into develop 2018-03-19 21:40:06 -04:00
Brandon Taylor
ae609e10da Version bump to 2.1.4.
Updated README
2018-03-19 21:32:39 -04:00
Brandon Taylor
041558823e Fixed return outside of function 2018-03-19 21:23:59 -04:00
Brandon Taylor
1e7ea7b75a Minor formatting fixes from merge. 2018-03-19 21:22:57 -04:00
Brandon Taylor
f6522d0a49
Merge pull request #185 from ixc/ixc/improve-performance-master
Fixed #162 -- Improve performance of sort view.
2018-03-19 21:19:20 -04:00
Tai Lee
108ef6dd18 Improve performance of sort view for moods and elements.
* Use `{% include  "..." with ... %}` instead of template tags that do
  nothing but pass through or rename context variables and render a
  template. This appears to yield a 2x increase in performance.

  As a side effect, this change also appears to fix some glitches with
  the rendering of `fa-sort`, `fa-sort-asc` and `fa-sort-desc` icons.

* Move queryset filtering from `sort_view()` to new `get_sort_view_queryset()`
  method, so subclasses can override to apply different or additional
  filtering (based on `request` and `sortable_by_expression`) to reduce
  the number of objects being reordered.

  `django-admin-sortable` already provides a mechanism to reorder a
  subset of objects via `sorting_filters`, but this is restricted to a
  small number of hard coded filters, and we found it not very useful.

  We have tens of thousands of nested objects grouped under hundreds or
  thousands of parent objects, and we needed a way to reorder child
  objects just within their own group.

  We also needed a way to reorder a subset of flat (not grouped by
  parent) sortable objects with much more flexibility.

Here's an example of additional filtering that allows us to reorder a
contiguous sequence of objects (nested or flat) that bounded by the min
and max (by ordering) selected objects:

```python
class MyBaseSortableAdmin(SortableAdmin):

    def get_sort_view_queryset(self, request, sortable_by_expression):
        """
        Filter the sort view queryset to include only a contiguous sequence of
        objects between the first and last of given parent objects, according
        to the current ordering.

        This should avoid inconsistent or ambiguous behaviour that might occur
        when re-ordering a non-contiguous sequence.
        """
        sortable_by_expression = sortable_by_expression or 'pk'
        queryset = super(MyBaseSortableAdmin, self) \
            .get_sort_view_queryset(request, sortable_by_expression)
        pks = [
            int(pk) for pk in request.GET.get('pks', '').split(',') if pk
        ]
        if pks:
            queryset = queryset.filter(**{
                '%s__in' % sortable_by_expression: pks,
            })
        return queryset

    def reorder_children(self, qs, child):
        # Get the min and max order field value for the selected objects, then
        # get contiguous PKs for objects between the min and max and pass to
        # the sort view, to avoid inconsistent or ambiguous behaviour.
        field = self.opts.ordering[0].replace('-', '')
        qs = qs.model.objects.filter(**qs.aggregate(**{
            '%s__gte' % field: Min(field),
            '%s__lte' % field: Max(field),
        }))
        ct = ContentType.objects.get_for_model(child)
        url = '%ssort/?pks=%s' % (
            reverse('admin:%s_%s_changelist' % (ct.app_label, ct.model)),
            ','.join([str(pk) for pk in qs.values_list('pk', flat=True)]),
        )
        return http.HttpResponseRedirect(url)

class MyModelAdmin(MyBaseSortableAdmin):
    actions = (
        "reorder_mymodel",
        "reorder_childmodel",
    )

    def reorder_mymodel(self, request, qs):
        return self.reorder_children(qs, MyModel)
    reorder_chapters.short_description = 'Reorder selected MyModels'

    def reorder_childmodel(self, request, qs):
        return self.reorder_children(qs, ChildModel)
    reorder_elements.short_description = 'Reorder ChildModels for the selected MyModels'
```

This could be made generic enough for inclusion by default with a few
tweaks, so that `Reorder selected {{ parent.verbose_name_plural }}` and
`Reorder {{ child.verbose_name_plural }} for selected {{ parent.verbose_name_plural }}`
admin actions could be included in sortable change lists.
2018-03-13 23:06:05 +11:00
Brandon Taylor
f515f93d22 Version bump to 2.1.3
Updated readme with credits for translations.
2018-02-25 11:49:38 -05:00