示例#1
0
    return items.filter(filters)


class DjangoPage(TemplateView):
    template_name = "landings/pages/django.html"

    def get_context_data(self, **kwargs):
        context = super(DjangoPage, self).get_context_data(**kwargs)
        context["active_menu_item"] = "feed"
        context["items"] = items_preset(get_items_by_name(get_active_items(), "django"), 10)
        return context


# The following function will be used as a block contents producer.
def get_quote(**kwargs):
    quotes = [  # From Terry Pratchett's Discworld novels.
        "Ripples of paradox spread out across the sea of causality.",
        "Early to rise, early to bed, makes a man healthy, wealthy and dead.",
        "Granny had nothing against fortune-telling provided it was done badly by people with no talent for it.",
        "Take it from me, there's nothing more terrible than someone out to do the world a favour.",
        "The duke had a mind that ticked like a clock and, like a clock, it regularly went cuckoo.",
        "Most gods find it hard to walk and think at the same time.",
        "They didn't have to be funny - they were father jokes",
        "Speak softly and employ a huge man with a crowbar.",
    ]
    return choice(quotes)


# And we register our siteblock.
register_dynamic_block("my_quotes2", get_quote)
示例#2
0
 def test_dynamic(self):
     register_dynamic_block('quotes', get_quote)
     contents = self.siteblocks.get('quotes', get_mock_context(path='/somewhere/'))
     self.assertIn(contents, QUOTES)
示例#3
0
ZEN = (
    ('Beautiful is better than ugly.', 'Красивое лучше безобразного.'),
    ('Explicit is better than implicit.', 'Явное лучше подразумеваемого.'),
    ('Simple is better than complex.', 'Простое лучше сложного.'),
    ('Complex is better than complicated.', 'Сложное лучше мудрёного.'),
    ('Flat is better than nested.', 'Плоское лучше вложенного.'),
    ('Sparse is better than dense.', 'Разреженное лучше плотного.'),
    ('Readability counts.', 'Читабельность важна.'),
    ('Special cases aren\'t special enough to break the rules.\nAlthough practicality beats purity.',
     'Исключения недостаточно исключительны, чтобы нарушать правила.\nХотя, практичность превыше чистоты.'),
    ('Errors should never pass silently.\nUnless explicitly silenced.',
     'Ошибки не должны проходить незамеченно.\nЕсли не были заглушены намеренно.'),
    ('In the face of ambiguity, refuse the temptation to guess.',
     'Пред лицом многозначительности презри желание догадаться.'),
    ('There should be one — and preferably only one — obvious way to do it.\n'
     'Although that way may not be obvious at first unless you\'re Dutch.',
     'Должен быть один — и лучше единственный — очевидный способ достичь цели.\n'
     'Впрочем, если вы не голландец, способ этот поначалу может казаться неочевидным.'),
    ('Now is better than never.\nAlthough never is often better than <em>right</em> now.',
     'Лучше сейчас, чем никогда.\nХотя, часто никогда лучше, чем <em>прямо</em> сейчас.'),
    ('If the implementation is hard to explain, it\'s a bad idea.',
     'Если реализацию трудно описать, значит идея была некудышной.'),
    ('If the implementation is easy to explain, it may be a good idea.',
     'Если реализацию легко описать — возможно, идея была хорошей.'),
    ('Namespaces are one honking great idea — let\'s do more of those!',
     'Пространства имён были блестящей идеей — генерируем ещё!'),
)

register_dynamic_block('zen', lambda **kwargs: choice(ZEN))
示例#4
0
文件: zen.py 项目: incidunt/pythonz
from random import choice

from siteblocks.siteblocksapp import register_dynamic_block


ZEN = (
    ('Beautiful is better than ugly.', 'Красивое лучше безобразного.'),
    ('Explicit is better than implicit.', 'Явное лучше подразумеваемого.'),
    ('Simple is better than complex.', 'Простое лучше сложного.'),
    ('Complex is better than complicated.', 'Сложное лучше мудрёного.'),
    ('Flat is better than nested.', 'Плоское лучше вложенного.'),
    ('Sparse is better than dense.', 'Лучше редко, чем кучно.'),
    ('Readability counts.', 'Читабельность всчёт.'),
    ('Special cases aren\'t special enough to break the rules.\nAlthough practicality beats purity.', 'Исключения недостаточно исключительны, чтобы нарушать правила.\nХотя, практичность превыше чистоты.'),
    ('Errors should never pass silently.\nUnless explicitly silenced.', 'Ошибки не должны проходить незамеченно.\nЕсли не были заглушены намеренно.'),
    ('In the face of ambiguity, refuse the temptation to guess.', 'Пред лицом многозначительности презри желание догадаться.'),
    ('There should be one — and preferably only one — obvious way to do it.\nAlthough that way may not be obvious at first unless you\'re Dutch.', 'Должен быть один —  и лучше единственный — очевидный способ достичь цели.\nХотя, этот способ поначалу может казаться неочевидным, если вы не голландец.'),
    ('Now is better than never.\nAlthough never is often better than <em>right</em> now.', 'Лучше теперь, чем никогда.\nХотя, часто никогда, лучше чем <em>сию минуту</em>.'),
    ('If the implementation is hard to explain, it\'s a bad idea.', 'Если реализацию трудно описать, значит идея была некудышной.'),
    ('If the implementation is easy to explain, it may be a good idea.', 'Если реализацию легко описать — возможно, идея была хорошей.'),
    ('Namespaces are one honking great idea — let\'s do more of those!', 'Пространства имён были запредельно замечательной идеей — так понаделаем их ещё!'),
)

register_dynamic_block('zen', lambda **kwargs: choice(ZEN))
示例#5
0
文件: views.py 项目: wd5/pythondigest

class DjangoPage(TemplateView):
    template_name = 'landings/pages/django.html'

    def get_context_data(self, **kwargs):
        context = super(DjangoPage, self).get_context_data(**kwargs)
        context['active_menu_item'] = 'feed'
        context['items'] = items_preset(
            get_items_by_name(get_active_items(), 'django'), 10)
        return context


# The following function will be used as a block contents producer.
def get_quote(**kwargs):
    quotes = [  # From Terry Pratchett's Discworld novels.
        'Ripples of paradox spread out across the sea of causality.',
        'Early to rise, early to bed, makes a man healthy, wealthy and dead.',
        'Granny had nothing against fortune-telling provided it was done badly by people with no talent for it.',
        'Take it from me, there\'s nothing more terrible than someone out to do the world a favour.',
        'The duke had a mind that ticked like a clock and, like a clock, it regularly went cuckoo.',
        'Most gods find it hard to walk and think at the same time.',
        'They didn\'t have to be funny - they were father jokes',
        'Speak softly and employ a huge man with a crowbar.',
    ]
    return choice(quotes)


# And we register our siteblock.
register_dynamic_block('my_quotes2', get_quote)
示例#6
0
 def test_dynamic(self, template_context):
     register_dynamic_block('quotes', get_quote)
     contents = self.siteblocks.get('quotes', template_context({}, '/somewhere/'))
     assert contents in QUOTES
示例#7
0
def register_zen_siteblock():
    """Регистрирует динамический блок сайта, наполняемый цитатами из дзена."""
    register_dynamic_block('zen', lambda **kwargs: choice(ZEN))