Commit graph

529 commits

Author SHA1 Message Date
Mark Skelton
fcc84ec00d Remove filter_expression which breaks change order 2018-08-08 21:23:55 -05: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
Brandon Taylor
842d748935
Merge pull request #191 from timur-orudzhov/change-list-filters-support
add support for django admin filters
2018-05-17 12:49:22 -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
Brandon Taylor
a90449a8a5
Merge pull request #189 from lumatijev/croatian-translation
Added Croatian translation
2018-03-22 14:13:58 -04:00
Luka Matijevic
b4a01720db Added Croatian translation 2018-03-22 19:04:02 +01:00
Brandon Taylor
4eed5b1e2d
Merge pull request #188 from rfleschenberg/issue-187
Unlocalize object IDs
2018-03-21 09:44:24 -04: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
Brandon Taylor
5d1529c161 Updated migrations to allow for a model with a non autofield as the primary key.
Updated tests.
2018-03-19 21:18:08 -04:00
Brandon Taylor
d8df8bab55 Updated documentation around extending custom templates. 2018-03-19 20:54:23 -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
Brandon Taylor
f2df915a13
Merge pull request #183 from bashu/patch-1
let there be (correct) colour
2018-02-16 16:19:30 -05:00
Basil Shubin
40affcaea3
let there be (correct) colour
+ corrected indentation level as a bonus
2018-02-16 18:25:11 +07:00
Brandon Taylor
dcee65eab5
Merge pull request #182 from peterisb/master
Added Latvian translation.
2018-02-08 15:53:00 -05:00
Peteris Bruns
f992fc72b4 Added Latvian translation. 2018-02-08 22:48:57 +02:00
Brandon Taylor
7bd6dfdbf8
Merge pull request #181 from simenheg/norwegian-translation
Add Norwegian Bokmål translation
2018-02-05 11:41:31 -05:00
Simen Heggestøyl
8d4c5b1417 Add Norwegian Bokmål translation 2018-02-05 17:25:14 +01:00
Brandon Taylor
604bfd035a Updated tox 2017-12-04 22:10:12 -05:00
Brandon Taylor
d4f577fdf9 Update csrf value to use value if present in context, then fall back to cookie.
Updated database samples.
Added migrations for sample project models.
Updated Category model to make order not editable.
2017-12-04 22:05:37 -05:00
Brandon Taylor
f4daaeb232 Restructured sample project for Django 2.
Refactored database and changed "app" to "samples" so name didn't conflict with "AppConfig".
Replaced deprecated assignment_tag with simple_tag.
Updated unit tests.
2017-12-04 21:29:55 -05:00
Brandon Taylor
10188ec8ac Merge branch 'touch-support' 2017-10-13 06:41:25 -04:00
Brandon Taylor
d594dbaf62 Merge branch 'touch-support' of github.com:iambrandontaylor/django-admin-sortable into touch-support 2017-10-13 06:40:39 -04:00
Brandon Taylor
4e0c23a1e5 Version bump to 2.1.1.
Updated readme files.
2017-10-13 06:40:35 -04:00
Brandon Taylor
0a594928ef Increase margin between sortable elements in the change list. 2017-10-11 16:13:12 -04:00
Brandon Taylor
bb70d5a3ad Added jQuery UI Touch Support 2017-10-11 07:15:42 -04:00
Brandon Taylor
115aad641d Update README.md
Updated Travis urls
2017-03-21 15:09:33 -04:00
Brandon Taylor
171257c9c5 [bt/master] Updated information on version compatibility 2017-03-21 06:44:26 -04:00
Brandon Taylor
a9855808d0 [bt/master] Version bump to 2.1 2017-03-21 06:42:24 -04:00
Brandon Taylor
2ec2722c67 Merge pull request #168 from jaap3/modernize
Remove fallbacks for Django < 1.8
2017-03-21 06:38:17 -04:00
Brandon Taylor
9fa1fb13a5 Update setup.py 2017-03-21 06:10:58 -04:00
Jaap Roes
49a7c41896 Use remote_field.model in favor of rel.to when possible 2017-03-16 16:21:59 +01:00
Jaap Roes
de6a768ceb No need to use include for admin.site.urls (it’s deprecated) 2017-03-16 16:21:59 +01:00
Jaap Roes
aa9c4a6063 User.is_authenticated is a property from Django 1.10 and onward 2017-03-16 16:21:59 +01:00
Jaap Roes
a5eca5ea4d assertEquals is deprecated in Python 3 2017-03-16 16:21:59 +01:00
Jaap Roes
e5adadaefc Use the newer MIDDLEWARE setting but fall back to MIDDLEWARE_CLASSES on Django < 1.10 2017-03-16 16:21:59 +01:00
Jaap Roes
defaf45e9a Make it clear why the httplib import is guarded by a try except and has a fallback 2017-03-16 16:21:59 +01:00
Jaap Roes
b8bfbe0c9a Explicitly set on_delete=models.CASCADE on ForeignKey as it will be required in Django 2.0 2017-03-16 16:21:59 +01:00