Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 48 lines (37 sloc) 1.269 kb
e2623dc Bryan Helmig lots of template and view tie in work. need to go back and do tests. get...
bryanhelmig authored
1 def paginate(iterable, per_page, page_num):
2 """
3 recipes = Recipe.objects.all()
9a47cdc Bryan Helmig pep8 cleanup
bryanhelmig authored
4 paginator, recipes = paginate(recipes, 12,
e2623dc Bryan Helmig lots of template and view tie in work. need to go back and do tests. get...
bryanhelmig authored
5 request.GET.get('page', '1'))
6 """
7 from django.core.paginator import Paginator, InvalidPage, EmptyPage
8
9 paginator = Paginator(iterable, per_page)
10
11 try:
12 page = int(page_num)
13 except ValueError:
14 page = 1
15
16 try:
17 iterable = paginator.page(page)
18 except (EmptyPage, InvalidPage):
19 iterable = paginator.page(paginator.num_pages)
20
9a47cdc Bryan Helmig pep8 cleanup
bryanhelmig authored
21 return paginator, iterable
1e47cc5 Bryan Helmig alert emails closes #1
bryanhelmig authored
22
23
24 def get_module(path):
25 """
26 A modified duplicate from Django's built in backend
27 retriever.
28
29 slugify = get_module('django.template.defaultfilters.slugify')
30 """
31 from django.utils.importlib import import_module
32
33 try:
34 mod_name, func_name = path.rsplit('.', 1)
35 mod = import_module(mod_name)
36 except ImportError, e:
37 raise ImportError(
38 'Error importing alert function {0}: "{1}"'.format(mod_name, e))
39
40 try:
41 func = getattr(mod, func_name)
42 except AttributeError:
43 raise ImportError(
44 ('Module "{0}" does not define a "{1}" function'
45 ).format(mod_name, func_name))
46
820fe81 Greg Aker PEP8 cleanup.
gaker authored
47 return func
Something went wrong with that request. Please try again.