Commit Graph

88 Commits (7ed44fa84b129271d015ffb9e2ca72462e65f185)

Author SHA1 Message Date
blag 00eb3fdb30
Pass the queryset filters from the request into the object_rep.html template 2020-05-25 18:45:09 -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 8311881f2f Fixed overzealous selector for sortable tabular inlines. 2020-01-14 18:26:49 -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 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 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 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 e87a1444b4 Fixed import paths. 2018-06-29 08:23:22 -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
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
René Fleschenberg 78c2e91aac Unlocalize object IDs
Fixes #187
2018-03-21 13:03:08 +01:00
Brandon Taylor 1e7ea7b75a Minor formatting fixes from merge. 2018-03-19 21:22:57 -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 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 bb70d5a3ad Added jQuery UI Touch Support 2017-10-11 07:15:42 -04:00
Jaap Roes f17db22938 Remove inline admin fallback templates 2017-03-16 16:21:58 +01:00
Igor Sobolev 12fbb62302 Proper context and breadcrumbs 2016-11-02 12:47:36 -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
Brandon Taylor f5cda8ded9 Updated Font Awesome to 4.6.3 2016-08-08 21:35:43 -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
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
Venelin Stoykov 262ec1b49b Fix stacked inline icons placement
Fixes #138
2016-06-23 18:25:11 +03:00
Venelin Stoykov a479198799 Use separate URLs per model in administration to do the sorting
- Correctly check if current user has permissions to made the change

Fixes #142
2016-06-16 14:41:03 +03:00
Venelin Stoykov 7c235308b8 Fix UI when djangocms-admin-style is used 2016-06-15 17:53:35 +03:00
Brandon Taylor c1181b0e52 Support CSRF_COOKIE_NAME
Added support for custom CSRF_COOKIE_NAME by refactoring the jquery.django-csrf.js file into a separate .html file that can be used as an include, passing in the CSRF_COOKIE_NAME from settings.
2016-02-16 08:48:32 -05:00
Brandon Taylor 7e9d305c90 Added template tag to get django version to allow flat admin specific classing for Django 1.9 or above. 2015-12-23 17:16:47 -05:00
Brandon Taylor 5dee27e077 Added sorting icons.
Refactored determination of sortability of classes referenced as sortable foreign keys in admin in a more reliable way.
2015-12-23 16:39:45 -05:00
Daniel Otero 11e445d99e Variable jQuery path for Django version 1.9 and above 2015-12-08 22:04:05 +01:00
Marco Badan a5496fed0b Remove `load url from future`
`{% load url from future %}` can be removed from templates since Django 1.5 and it will be removed from Django in 1.9

https://docs.djangoproject.com/en/1.8/releases/1.5/#django-1-5-release-notes
https://docs.djangoproject.com/en/dev/releases/1.7/#loading-ssi-and-url-template-tags-from-future-library
2015-11-14 14:04:56 +01:00
Jorge Marques feeb4e7910 Updates the stacked and tabular inline templates so that the
"show_change_link" option is taken into account, mimicking the
corresponding templates in Django 1.8
2015-10-13 18:41:51 +01:00
Brandon Taylor ca6d4ee8ed Removed debugging information. 2015-03-24 09:13:33 -04:00
mark@ignacio.io da39cf7497 re-enabled href in shared/object_rep.html 2014-12-27 12:18:10 -05:00
Brandon Taylor 01403f1b8c Merged pull request 97 2014-12-22 10:25:35 -05:00
Brandon Taylor e521d5c8ad Added extra check for object when sorting self-referential models. 2014-11-03 10:44:11 -05:00
Brandon Taylor b880018f71 Added css target class to proerly display the 'move' cursor for sortable stacked inlines. 2014-09-21 14:31:46 -04:00
Jaap Roes 0e993c524c Removed a stray "TEST 2" 2014-09-19 13:30:46 +02:00
Brandon Taylor 5e307d687b Version bump to 1.7.1.
Added Brazilian Portugese locale.
Fixed minor css scoping issue that caused stacked template items that were sortable to not display the 'move' cusor type.
Fixed comment line in manage.py for PEP8.
2014-08-21 22:14:36 -04:00
Brandon Taylor 80bdaafdc3 Refactored sorting_filters into a tuple and moved logic for retrieving sorting filters into the sort_view versus changelist_view.
Updated readme.
Updated sample project to leverage new sorting_filters on Person model and admin.
Removed custom change list template for Person admin.
2014-03-05 09:10:47 -05:00
Brandon Taylor 1b4730fef9 Added Person model with sorting_filters set to only order people who are board members.
Added custom template override to specify which people are sortable in change list.
Added initial data fixture for people.
2014-02-05 11:08:02 -05:00
Moritz Pfeiffer 818a231a1a Reordering with unsaved inlines is faulty and counter intuitive.
In this commit I added a javascript alert that prompts the user to save their changes before reordering if unsaved inlines are detected.
Please review and let me know if this in compliance with your guidelines.
2013-12-03 10:45:17 +01:00
Moritz Pfeiffer ab38988698 Added missing templates 2013-12-03 10:43:00 +01:00
Brandon Taylor 469e7d5d4d Added new stacked and tabular change form templates for inlines from Django 1.6.
Added backwards compatibility changes for the setting of the edit inline template to use.
2013-11-25 22:03:20 -05:00