__init__.py
1.55 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
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from django.conf import settings
from django.utils.importlib import import_module
class PaginerObject(object):
def __init__(self, func, template, perm=None, group_action_names=None,
filter_forms=None):
self.queryset = func
self.template = template
self.perm = perm
self.group_action_names = group_action_names
self.filter_forms = filter_forms
class PaginationTypes(object):
def __init__(self):
self.dict = {}
def __getitem__(self, name):
return self.dict[name]
def add(self, name, func, template, perm=None, group_action_names=None,
filter_forms=None):
self.dict[name] = PaginerObject(func, template, perm, group_action_names,
filter_forms)
types = PaginationTypes()
for a in settings.INSTALLED_APPS:
try:
mod = import_module('.pagination_types', a)
for (name, t) in mod.types.iteritems():
types.add(name, *t)
except ImportError:
pass
class PaginationList(object):
def __init__(self):
self.dict = {}
def __getitem__(self, id):
return self.dict[id]
def add(self, id, list_type, params, action=None, group_actions=None):
a = list_type
self.dict[id] = {
'id': id,
'type': list_type,
'params': params,
'template': types[list_type].template,
'group_action_names': types[list_type].group_action_names,
'action': action,
'group_actions': group_actions,
'filter_forms': types[list_type].filter_forms, # brzydkie, że tyle razy trzeba dopisywać
}