mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-30 22:30:14 +02:00
Big checkin that adds a number of features and makes some changes:
* Updated jQuery to 1.2.6 * Add jQuery UI 1.6b for interface effects as needed * 'Smoothness' theme from ThemeRoller.com added. * Clean up 'Filter' dialog on Ticket List, long way to go still. * Uses tabs to save a query or load a saved query * Lots of misuse of space here, can be cleaned up somewhat still. * Add ability for users to save filters/queries * Saved queries can be shared, so other users can use them * Users can run saved queries instead of re-filtering * Filter mechanism in Ticket List had to be reworked significantly * Merged 3rd party licenses into LICENSE.3RDPARTY * Updated messages files for EN locale To update, ensure you run './manage.py syncdb' to add the SavedSearch table.
This commit is contained in:
28
lib.py
28
lib.py
@ -251,3 +251,31 @@ def query_to_dict(results, descriptions):
|
||||
|
||||
output.append(row)
|
||||
return output
|
||||
|
||||
|
||||
def apply_query(queryset, params):
|
||||
"""
|
||||
Apply a dict-based set of filters & paramaters to a queryset.
|
||||
|
||||
queryset is a Django queryset, eg MyModel.objects.all() or
|
||||
MyModel.objects.filter(user=request.user)
|
||||
|
||||
params is a dictionary that contains the following:
|
||||
filtering: A dict of Django ORM filters, eg:
|
||||
{'user__id__in': [1, 3, 103], 'title__contains': 'foo'}
|
||||
other_filter: Another filter of some type, most likely a
|
||||
set of Q() objects.
|
||||
sorting: The name of the column to sort by
|
||||
"""
|
||||
for key in params['filtering'].keys():
|
||||
filter = {key: params['filtering'][key]}
|
||||
queryset = queryset.filter(**filter)
|
||||
|
||||
if params.get('other_filter', None):
|
||||
# eg a Q() set
|
||||
queryset = queryset.filter(params['other_filter'])
|
||||
|
||||
if params.get('sorting', None):
|
||||
queryset = queryset.order_by(params['sorting'])
|
||||
|
||||
return queryset
|
||||
|
Reference in New Issue
Block a user