pagination_types.py
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#-*- coding:utf-8 -*-
from datetime import datetime
from dictionary.models import History, Lexeme, visible_vocabularies
import dictionary.forms as dictionary_forms
types = {}
def lexeme_history_list(params, user):
objects = History.objects.exclude(lexeme=None).distinct().values(
'lexeme', 'user', 'transaction_began')
lexemes = Lexeme.objects.filter(
owner_vocabulary__in=visible_vocabularies(user)).exclude(entry='')
for field, value in params['filters'].iteritems():
if field == 'user':
objects = objects.filter(user__pk=value)
if field == 'time_from':
try:
date = datetime.strptime(value, '%d.%m.%Y')
objects = objects.filter(transaction_began__gte=date)
except ValueError:
pass
if field == 'time_to':
try:
date = datetime.strptime(value, '%d.%m.%Y')
objects = objects.filter(transaction_began__lte=date)
except ValueError:
pass
if field == 'user_other':
objects = objects.exclude(user__username=value)
objects = objects.filter(lexeme__in=lexemes)
objects = objects.order_by(params['order_by'])
return objects
LEXEME_HISTORY_FILTERS = {
# 'label': (Form(), ????), # czy wymaga logowania - niepotrzebne tutaj
'user': (dictionary_forms.UserFilterForm(), True),
'time_from': (dictionary_forms.TimeFromForm(), True),
'time_to': (dictionary_forms.TimeToForm(), True),
}
def dummy_perm(_user, _object, _action):
return True
types['lexeme_history'] = (
lexeme_history_list, 'lexeme_history_item.html', dummy_perm, {},
LEXEME_HISTORY_FILTERS)