__init__.py 1.54 KB
# -*- 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,
               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,
    }