def test_post_archive_view(self): pages = self.get_pages() posts = self.get_posts() with smart_override('en'): request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False) view_obj = PostArchiveView() view_obj.request = request view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'year': now().year, 'month': now().month} # One post only, anonymous request qs = view_obj.get_queryset() self.assertEqual(qs.count(), 1) self.assertEqual(list(qs), [posts[0]]) view_obj.object_list = qs context = view_obj.get_context_data( object_list=view_obj.object_list) self.assertEqual( context['archive_date'].date(), now().replace(year=now().year, month=now().month, day=1).date())
def test_post_archive_view(self): page1, page2 = self.get_pages() post1, post2 = self.get_posts() request = self.get_page_request(page1, AnonymousUser(), r'/en/blog/', edit=False) activate('en') view_obj = PostArchiveView() view_obj.request = request view_obj.kwargs = {'year': now().year, 'month': now().month} # One post only, anonymous request qs = view_obj.get_queryset() self.assertEqual(qs.count(), 1) self.assertEqual(list(qs), [post1]) view_obj.object_list = qs context = view_obj.get_context_data(object_list=view_obj.object_list) self.assertEqual(context['archive_date'].date(), now().replace(year=now().year, month=now().month, day=1).date())
def test_post_archive_view(self): posts = self.get_posts() pages = self.get_pages() with smart_override('en'): request = self.get_page_request(pages[1], AnonymousUser(), lang='en', edit=False) view_obj = PostArchiveView() view_obj.request = request view_obj.namespace, view_obj.config = get_app_instance(request) view_obj.kwargs = {'year': now().year, 'month': now().month} # One post only, anonymous request qs = view_obj.get_queryset() self.assertEqual(qs.count(), 1) self.assertEqual(list(qs), [posts[0]]) view_obj.object_list = qs context = view_obj.get_context_data(object_list=view_obj.object_list) self.assertEqual(context['archive_date'].date(), now().replace(year=now().year, month=now().month, day=1).date())
def get_urls(): urls = get_setting("PERMALINK_URLS") details = [] for urlconf in urls.values(): details.append( path(urlconf, PostDetailView.as_view(), name="post-detail"), ) return details detail_urls = get_urls() urlpatterns = [ path("latests/", PostListView.as_view(), name="posts-latest"), path("feed/", LatestEntriesFeed(), name="posts-latest-feed"), path("feed/fb/", FBInstantArticles(), name="posts-latest-feed-fb"), path("<int:year>/", PostArchiveView.as_view(), name="posts-archive"), path("<int:year>/<int:month>/", PostArchiveView.as_view(), name="posts-archive"), path("author/<str:username>/", AuthorEntriesView.as_view(), name="posts-author"), path("category/<str:category>/", CategoryEntriesView.as_view(), name="posts-category"), path("tag/<slug:tag>/", TaggedListView.as_view(), name="posts-tagged"), path("tag/<slug:tag>/feed/", TagFeed(), name="posts-tagged-feed"), ] + detail_urls
def get_urls(): urls = get_setting('PERMALINK_URLS') details = [] for urlconf in urls.values(): details.append( url(urlconf, PostDetailView.as_view(), name='post-detail'), ) return details detail_urls = get_urls() urlpatterns = [ url(r'^latests/$', PostListView.as_view(), name='posts-latest'), url(r'^feed/$', LatestEntriesFeed(), name='posts-latest-feed'), url(r'^feed/fb/$', FBInstantArticles(), name='posts-latest-feed-fb'), url(r'^(?P<year>\d{4})/$', PostArchiveView.as_view(), name='posts-archive'), url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', PostArchiveView.as_view(), name='posts-archive'), url(r'^author/(?P<username>[\w\.@+-]+)/$', AuthorEntriesView.as_view(), name='posts-author'), url(r'^category/(?P<category>[\w\.@+-]+)/$', CategoryEntriesView.as_view(), name='posts-category'), url(r'^tag/(?P<tag>[-\w]+)/$', TaggedListView.as_view(), name='posts-tagged'), url(r'^tag/(?P<tag>[-\w]+)/feed/$', TagFeed(), name='posts-tagged-feed'), ] + detail_urls
def get_urls(): urls = get_setting("PERMALINK_URLS") details = [] for urlconf in urls.values(): details.append( url(urlconf, PostDetailView.as_view(), name="post-detail"), ) return details detail_urls = get_urls() urlpatterns = [ url(r"^latests/$", PostListView.as_view(), name="posts-latest"), url(r"^feed/$", LatestEntriesFeed(), name="posts-latest-feed"), url(r"^feed/fb/$", FBInstantArticles(), name="posts-latest-feed-fb"), url(r"^(?P<year>\d{4})/$", PostArchiveView.as_view(), name="posts-archive"), url(r"^(?P<year>\d{4})/(?P<month>\d{1,2})/$", PostArchiveView.as_view(), name="posts-archive"), url(r"^author/(?P<username>[\w\.@+-]+)/$", AuthorEntriesView.as_view(), name="posts-author"), url(r"^category/(?P<category>[\w\.@+-]+)/$", CategoryEntriesView.as_view(), name="posts-category"), url(r"^tag/(?P<tag>[-\w]+)/$", TaggedListView.as_view(), name="posts-tagged"), url(r"^tag/(?P<tag>[-\w]+)/feed/$", TagFeed(), name="posts-tagged-feed"), ] + detail_urls
details = [] for urlconf in urls.values(): details.append( url(urlconf, PostDetailView.as_view(), name='post-detail'), ) return details detail_urls = get_urls() urlpatterns = [ url(r'^latests/$', PostListView.as_view(), name='posts-latest'), url(r'^feed/$', LatestEntriesFeed(), name='posts-latest-feed'), url(r'^feed/fb/$', FBInstantArticles(), name='posts-latest-feed-fb'), url(r'^(?P<year>\d{4})/$', PostArchiveView.as_view(), name='posts-archive'), url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$', PostArchiveView.as_view(), name='posts-archive'), url(r'^author/(?P<username>[\w\.@+-]+)/$', AuthorEntriesView.as_view(), name='posts-author'), url(r'^category/(?P<category>[\w\.@+-]+)/$', CategoryEntriesView.as_view(), name='posts-category'), url(r'^tag/(?P<tag>[-\w]+)/$', TaggedListView.as_view(), name='posts-tagged'), url(r'^tag/(?P<tag>[-\w]+)/feed/$', TagFeed(), name='posts-tagged-feed'), ] + detail_urls