当前位置: 首页>>代码示例>>Python>>正文


Python Article.active_years方法代码示例

本文整理汇总了Python中blog.models.Article.active_years方法的典型用法代码示例。如果您正苦于以下问题:Python Article.active_years方法的具体用法?Python Article.active_years怎么用?Python Article.active_years使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blog.models.Article的用法示例。


在下文中一共展示了Article.active_years方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_active_years

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import active_years [as 别名]
 def test_active_years(self):
     """
     Tests the active_years function.
     """
     self.assertEqual(Article.active_years(), [])
     Article.objects.create(published=datetime.datetime(
         2009, 3, 12, 0, 0, 0, 0, get_current_timezone()))
     self.assertEqual(Article.active_years(), [2009])
     Article.objects.create(published=datetime.datetime(
         2011, 12, 4, 0, 0, 0, 0, get_current_timezone()))
     self.assertEqual(Article.active_years(), [2011, 2009])
     Article.objects.create(published=datetime.datetime(
         2011, 2, 11, 0, 0, 0, 0, get_current_timezone()))
     self.assertEqual(Article.active_years(), [2011, 2009])
     Article.objects.create(published=datetime.datetime(
         2015, 4, 3, 0, 0, 0, 0, get_current_timezone()))
     self.assertEqual(Article.active_years(), [2015, 2011, 2009])
开发者ID:Lantero,项目名称:personal-portfolio,代码行数:19,代码来源:test_models.py

示例2: get_context_data

# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import active_years [as 别名]
    def get_context_data(self, **kwargs):
        """
        Loads common information that is needed throughout the website.

        First it gets blog information, that is, getting articles by year and
        month, and articles by tag. Then adds email and google recaptcha keys
        to compose the context data that will be passed to all the views.

        Arguments:
            **kwargs: Django's default kwargs for this overridden function.
        """
        # Populate entries by time line info.
        entries_by_time_line = []
        for active_year in Article.active_years():
            articles_per_year = Article.articles_per_year(active_year)
            month_list = []
            for active_month in Article.active_months_per_year(active_year):
                articles = Article.articles_per_month_and_year(
                    active_year,
                    active_month
                )
                articles_list = []
                for article in articles:
                    articles_list.append((article.id, article.title))
                month_list.append((
                    active_month,
                    MONTHS_OF_THE_YEAR[active_month],
                    articles.count(),
                    articles_list
                ))
            entries_by_time_line.append((active_year,
                                         articles_per_year.count(),
                                         month_list))
        # Populate entries by tag info.
        entries_by_tag = []
        for tag in Tag.objects.all():
            articles = tag.related_articles.all()
            articles_list = []
            for article in articles:
                articles_list.append((article.id, article.title))
            entries_by_tag.append((tag.name, tag.__str__(),
                                   articles.count(), articles_list))
        # Update context dictionary with the previous information and email
        # and google recaptcha settings.
        context = super(ContextMixin, self).get_context_data(**kwargs)
        app_context = {
            'email': settings.DEFAULT_FROM_EMAIL,
            'google_recaptcha_client_key':
                settings.GOOGLE_RECAPTCHA_CLIENT_KEY,
            'entries_by_time_line': entries_by_time_line,
            'entries_by_tag': entries_by_tag
        }
        context.update(app_context)
        return context
开发者ID:Lantero,项目名称:personal-portfolio,代码行数:56,代码来源:views.py


注:本文中的blog.models.Article.active_years方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。