def test_get_featured_image_url(self): view = HomeView() article = { 'images': [ { 'url': 'first', 'featured': False }, { 'url': 'second', 'featured': True }, { 'url': 'third', 'featured': False }, ] } url = view.get_featured_image_url(article) self.assertEqual(url, 'second') article = { 'images': [ { 'url': 'first', 'featured': False }, { 'url': 'second', 'featured': False }, { 'url': 'third', 'featured': False }, ] } url = view.get_featured_image_url(article) self.assertEqual(url, None) article = {'images': []} url = view.get_featured_image_url(article) self.assertEqual(url, None)
from articles.views import FollowAllView, SessionExpiresView, FollowView, UnfollowView, HomeView, PostView, ShareView from articles.views import CommentOnView, CommentView, CommentsView, GetArticleView urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), (r'^comments/', include('django.contrib.comments.urls')), (r'^follow/all/$', FollowAllView.as_view()), (r'^accounts/expire/$', SessionExpiresView.as_view()), (r'^follow/(?P<email>.+)/$', FollowView.as_view()), (r'^unfollow/(?P<email>.+)/$', UnfollowView.as_view()), (r'^shared/(?P<email>.+)/$', feeds.UsersSharedFeed()), (r'^feed/(?P<email>.+)/(?P<auth_key>.+)/$', feeds.FollowingFeed()), (r'^post/$', PostView.as_view()), (r'^share/$', ShareView.as_view()), (r'^comment/on/(?P<article_id>.+)/$', CommentOnView.as_view()), (r'^comment/$', CommentView.as_view()), (r'^comments/$', CommentsView.as_view()), (r'^get/(?P<article_id>\d+)/$', GetArticleView.as_view()), url(r'', include('social_auth.urls')), url('^', include('follow.urls')), (r'^$', HomeView.as_view()), ) print settings.MEDIA_ROOT urlpatterns = urlpatterns + patterns('', (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT }), )
from django.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include from articles.views import HomeView urlpatterns = [ path('admin/', admin.site.urls), path('', include('aggregator.urls', namespace='aggregator')), path('', HomeView.as_view(), name='home') ] urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG or settings.TESTING_MODE: import debug_toolbar urlpatterns = [path('__debug__/', include(debug_toolbar.urls)) ] + urlpatterns
# -*- coding: utf-8 -*- from rest_framework.routers import DefaultRouter from django.conf.urls import url, include from articles.api import BlogDetailViewSet from articles.views import HomeView, BlogsView, BlogDetailView, ArticleDetailView, ArticleCreationView articles=BlogDetailViewSet.as_view({ 'get': 'list' }) router = DefaultRouter() router.register('api/1.0/blog/(?P<username>\w+)', BlogDetailViewSet, base_name='api_blogs_detail') urlpatterns = [ url(r'^$', HomeView.as_view(), name='article_home'), url(r'^new-post$', ArticleCreationView.as_view(), name='article_creation'), url(r'^blogs/$', BlogsView.as_view(), name='blogs_list'), url(r'^blogs/(?P<username>\w+)/$', BlogDetailView.as_view(), name='blog_detail'), url(r'^blogs/(?P<username>\w+)/(?P<pk>[0-9]+)$$', ArticleDetailView.as_view(), name='article_detail'), url(r'', include(router.urls)) ]
# -*- encoding: utf-8 -*- from django.conf.urls import url, include from rest_framework.routers import DefaultRouter from articles.api import ArticleViewSet, ArticleOnlyByUserView from articles.views import HomeView, ArticleView, ArticlesByUserView, ArticlesByCategoryView, ArticlesBySearchQueryView router = DefaultRouter() router.register('apiv1/article', ArticleViewSet, 'api_articles_') articles_urls = [ # Urls WEB url(r'^$', HomeView.as_view(), name='site_home'), url(r'^category\/(?P<slug>[A-Za-z0-9.\+@_-]+)\/$', ArticlesByCategoryView.as_view(), name='articles_by_category'), url(r'^search\/$', ArticlesBySearchQueryView.as_view(), name='articles_by_search_query'), url(r'^(?P<nombre_de_usuario>[A-Za-z0-9.\+@_-]+)\/$', ArticlesByUserView.as_view(), name='articles_by_user'), url(r'^(?P<nombre_de_usuario>[A-Za-z0-9.\+@_-]+)\/(?P<articulo_slug>[A-Za-z0-9.\+@_-]+)$', ArticleView.as_view(), name='article_detail'), # URLS APis url(r'', include(router.urls)), url(r'^apiv1/articleuser/$', ArticleOnlyByUserView.as_view()), ]
"""gamesreview URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path from articles.views import HomeView, ArticleView, ArticleListView from django.conf import settings from django.conf.urls.static import static urlpatterns = [ path('admin/', admin.site.urls, name='admin'), path('', HomeView.as_view()), path('page<int:page>', ArticleListView.as_view()), path('article/<slug:slug>', ArticleView.as_view(), name='article'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.conf.urls import url from django.contrib import admin from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.views import LoginView, LogoutView from django.urls import path from articles import views from articles.views import HomeView, PaidView, ArticleListView, ArticleView urlpatterns = [ path('admin/', admin.site.urls), path('', HomeView.as_view(), name='index'), path('login/', LoginView.as_view(template_name='login.html', authentication_form=AuthenticationForm), name='login'), path('logout/', LogoutView.as_view(template_name='index.html'), name='logout'), path('articles/', ArticleListView.as_view(), name='articles'), # path('articles/', views.show_articles, name='articles'), path('article/<pk>/', ArticleView.as_view(), name='article'), # url(r'^articles/(?P<id>[0-9]+)/', views.show_article, name='article'), path('subscribe-paid/', PaidView.as_view(), name='subscribe_paid') ]