page_it()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
1
# coding: utf-8
2
import arrow
3
4
from django.conf import settings
5
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
6
7
# ************************
8
# FBV : simple actions   *
9
# ************************
10
11
12
def page_it(data, record_per_page, page=''):
13
    """
14
        return the data of the current page
15
    """
16
    paginator = Paginator(data, record_per_page)
17
    try:
18
        data = paginator.page(page)
19
    except PageNotAnInteger:
20
        # If page is not an integer, deliver first page.
21
        data = paginator.page(1)
22
    except EmptyPage:
23
        # If page is out of range (e.g. 9999),
24
        # deliver last page of results.
25
        data = paginator.page(paginator.num_pages)
26
27
    return data
28
29
30
def right_now(model):
31
    """
32
        return a dict of 2 property set with current date and time
33
    """
34
    now_date = arrow.utcnow().to(settings.TIME_ZONE).format('YYYY-MM-DD')
35
    now_hour = arrow.utcnow().to(settings.TIME_ZONE).format('HH:mm:ss')
36
    my_date = 'date_' + model
37
    my_hour = 'hour_' + model
38
    return {my_date: now_date, my_hour: now_hour}
39