__init__.py
1.65 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
56
57
58
59
# -*- coding: utf-8 -*-
from django.conf import settings
from importlib import import_module
class PaginerObject(object):
def __init__(self, func, template, perm=None, group_action_names=None,
filters=None, field_form_class=None):
self.queryset = func
self.template = template
self.perm = perm
self.group_action_names = group_action_names
self.filters = filters
self.filter_field_form = field_form_class
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,
filters=None, field_form_class=None):
self.dict[name] = PaginerObject(
func, template, perm, group_action_names, filters, field_form_class)
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):
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,
'filters': types[list_type].filters,
}