__init__.py 1.55 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,
               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ć
    }