Changeset 511ba61 in tailbone


Ignore:
Timestamp:
04/02/19 14:44:59 (11 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
c26af47
Parents:
bf189bb7
Message:

Add move_before() convenience method for GridFilterSet

to more easily rearrange sort order of grid filters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tailbone/grids/filters.py

    rbf189bb7 r511ba61  
    771771    """
    772772
     773    def move_before(self, key, refkey):
     774        """
     775        Rearrange underlying key sorting, such that the given ``key`` comes
     776        just *before* the given ``refkey``.
     777        """
     778        # first must work out the new order for all keys
     779        newkeys = []
     780        for k in self.keys():
     781            if k == key:
     782                continue
     783            if k == refkey:
     784                newkeys.append(key)
     785                newkeys.append(refkey)
     786            else:
     787                newkeys.append(k)
     788
     789        # then effectively replace dict contents, using new order
     790        items = dict(self)
     791        self.clear()
     792        for k in newkeys:
     793            self[k] = items[k]
     794
    773795
    774796class GridFiltersForm(forms.Form):
Note: See TracChangeset for help on using the changeset viewer.