本文整理汇总了Python中blog.models.Article.active_months_per_year方法的典型用法代码示例。如果您正苦于以下问题:Python Article.active_months_per_year方法的具体用法?Python Article.active_months_per_year怎么用?Python Article.active_months_per_year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.active_months_per_year方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_active_months_per_year
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import active_months_per_year [as 别名]
def test_active_months_per_year(self):
"""
Tests the active_months_per_year function.
"""
self.assertEqual(Article.active_months_per_year(2011), [])
Article.objects.create(published=datetime.datetime(
2011, 3, 12, 0, 0, 0, 0, get_current_timezone()))
self.assertEqual(Article.active_months_per_year(2011), [3])
Article.objects.create(published=datetime.datetime(
2011, 3, 4, 0, 0, 0, 0, get_current_timezone()))
self.assertEqual(Article.active_months_per_year(2011), [3])
Article.objects.create(published=datetime.datetime(
2011, 12, 11, 0, 0, 0, 0, get_current_timezone()))
self.assertEqual(Article.active_months_per_year(2011), [12, 3])
示例2: get_context_data
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import active_months_per_year [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