GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5a5c79...69baa6 )
by
unknown
01:26
created

items_preset()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
from random import choice
2
# Import the register function.
3
from django.db.models import Q
4
from django.views.generic import TemplateView
5
from siteblocks.siteblocksapp import register_dynamic_block
6
import datetime
7
8
from digest.models import Item
9
10
11
def get_active_items():
12
    return Item.objects.filter(status='active',
13
                               activated_at__lte=datetime.datetime.now())
14
15
16
def items_preset(items, max_cnt=20):
17
    return items.prefetch_related('issue', 'section').order_by(
18
        '-created_at', '-related_to_date')[:max_cnt]
19
20
21
def get_items_by_name(items, name):
22
    filters = Q(title__icontains=name) | \
23
              Q(description__icontains=name) | \
24
              Q(tags__name__in=[name])
25
    return items.filter(filters)
26
27
28
class DjangoPage(TemplateView):
29
    template_name = 'landings/pages/django.html'
30
31
    def get_context_data(self, **kwargs):
32
        context = super(DjangoPage, self).get_context_data(**kwargs)
33
        context['active_menu_item'] = 'feed'
34
        context['items'] = items_preset(
35
            get_items_by_name(get_active_items(), 'django'), 10)
36
        return context
37
38
39
# The following function will be used as a block contents producer.
40
def get_quote(**kwargs):
41
    quotes = [  # From Terry Pratchett's Discworld novels.
42
        'Ripples of paradox spread out across the sea of causality.',
43
        'Early to rise, early to bed, makes a man healthy, wealthy and dead.',
44
        'Granny had nothing against fortune-telling provided it was done badly by people with no talent for it.',
45
        'Take it from me, there\'s nothing more terrible than someone out to do the world a favour.',
46
        'The duke had a mind that ticked like a clock and, like a clock, it regularly went cuckoo.',
47
        'Most gods find it hard to walk and think at the same time.',
48
        'They didn\'t have to be funny - they were father jokes',
49
        'Speak softly and employ a huge man with a crowbar.',
50
    ]
51
    return choice(quotes)
52
53
54
# And we register our siteblock.
55
register_dynamic_block('my_quotes2', get_quote)
56