Commit Graph

286 Commits (fa8a5f12a8a79ff0f3cb1ae828b46aa31c8c65f8)

Author SHA1 Message Date
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
Peteris Bruns f992fc72b4 Added Latvian translation. 2018-02-08 22:48:57 +02:00
Simen Heggestøyl 8d4c5b1417 Add Norwegian Bokmål translation 2018-02-05 17:25:14 +01: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 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 a9855808d0 [bt/master] Version bump to 2.1 2017-03-21 06:42:24 -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 209a280ce8 Remove (seemingly broken) TemplateSyntaxError import fallback 2017-03-16 16:21:58 +01:00
Jaap Roes b0df1ff701 Remove south_field_triple method as South does not support Django >= 1.7 2017-03-16 16:21:58 +01:00
Jaap Roes 8b88dfa9cd Remove pointless fallback code (it just repeats the previously failed statement) 2017-03-16 16:21:58 +01:00
Jaap Roes 356d88dfde Remove ordering field lookup fallback 2017-03-16 16:21:58 +01:00
Jaap Roes ac507e4484 Remove get_queryset fallback 2017-03-16 16:21:58 +01:00
Jaap Roes f17db22938 Remove inline admin fallback templates 2017-03-16 16:21:58 +01:00
Jaap Roes 74e0c92455 Remove contenttypes.generic import fallbacks 2017-03-16 16:21:58 +01:00
Jaap Roes e0a85c554b Remove django.conf.urls import fallback 2017-03-16 16:21:58 +01:00
Brandon Taylor 1990e6653e [bt] Version 2.0.22 Release Notes
Updated readme files with new version information and credits.
Version bump to 2.0.22.
2017-03-14 22:04:23 -04:00
Camilo Nova 9b51e83537 Update to django 1.11
Fixes `TypeError, context must be a dict rather than RequestContext.`

As seen in https://docs.djangoproject.com/en/1.11/ref/templates/upgrading/#django-template-loader
2017-03-13 11:57:38 -05:00
Anton Shevchenko eb5f14fe22 Clarify comment. 2017-03-11 11:20:16 -05:00
Anton Shevchenko eb5a9e0a8a Avoid unnecessary db queries: perform the update iff the order field has changed. 2017-03-08 23:28:40 -05:00
Anton Shevchenko f2f5daf831 Use 'update_fields' to limit the object's save() method to just the order field, so that other fields are not accidentally overwritten with stale data. 2017-03-08 22:14:48 -05:00
Brandon Taylor d1911519ed Added version check for 1.7 to create context dict. 2016-11-02 21:29:31 -04:00
Igor Sobolev 12fbb62302 Proper context and breadcrumbs 2016-11-02 12:47:36 -04:00
Brandon Taylor b96896d890 Merge branch 'develop' 2016-10-30 11:39:17 -04:00
Brandon Taylor 863ff69719 Fix Sorting by ForeignKey
Removed do_inline_sorting_url and get_object_or_404 check in admin. The model_type_id should *always* be passed in.
Removed test that asserted that Categories weren't sortable as part of the Project admin. Categories *should* be sortable as part of Project admin as they are a Sortable ForeignKey.
Fixed object_rep template to pass in model_type_id again.
Updated README.
Version bump to 2.0.21
2016-10-30 11:33:20 -04:00
Steven Wood 686ddae81c Raise NotImplementedError instead of NotImplemented 2016-10-23 10:20:45 -04:00
Brandon Taylor 3f12b10926 Changed version check back to old-style for backwards compatibility. 2016-10-12 22:23:38 -04:00
Brandon Taylor 32726cdcae Version 2.0.20
Bumped version up.
Updated README.
2016-10-12 06:09:49 -04:00
Ruben Dura Tari 3c2935776e Enables support for primary keys that are not AutoFields.
Specially useful when using UUIDs as primary keys.
2016-10-11 18:53:45 +01:00
Brandon Taylor 66e63a29c2 Version bump to 2.0.19.
Updated readme.
2016-08-08 21:48:11 -04:00
Brandon Taylor f5cda8ded9 Updated Font Awesome to 4.6.3 2016-08-08 21:35:43 -04:00
Brandon Taylor b29590a185 Minor formatting tweaks 2016-08-08 21:34:53 -04:00
Brandon Taylor ec03f8d17b Updated change_list template for Django 1.10 compatibility. 2016-08-08 21:34:41 -04:00
Brandon Taylor 5566faed5b Update sortable inline templates for Django 1.10.x compatibility. 2016-08-08 20:36:35 -04:00
Brandon Taylor e9b03a3a4f Merge pull request #143 from MagicSolutions/fix/admin-urs
Use separate URLs per model in administration to do the sorting
2016-08-03 10:06:29 -04:00
Brandon Taylor fc58ee51f0 Updated readme.
Version bump to 2.0.18
2016-07-09 18:26:00 -04:00
Steven H Johnson 76a49cc082 Fix missing admin icon for django 1.9 2016-07-09 16:26:45 -04:00
Venelin Stoykov c59617e004 Fix sorted icons placement
- Move icons to the header of the row. By this way they will play nicely with custom
admin themes (like djangocms-admin-style).
- Also fix icons for Django 1.5 (now the admin looks the same as with Django >= 1.6)
2016-06-24 14:04:06 +03:00
Brandon Taylor ee857c7403 [bt] Release 2.0.17
Merged Pull Requests #146 and #147
2016-06-23 22:04:07 -04:00
Brandon Taylor 54482b3bb3 Merge branch 'master' into develop 2016-06-23 21:48:45 -04:00
Brandon Taylor 7788b8e405 Merge pull request #146 from MagicSolutions/fix/change_form_template-selection
Play nice with other apps which dynamically choose `change_form_template`
2016-06-23 18:36:02 -07:00