Beispiel #1
0
 def test_get(self):
     """
     Test GET requests
     """
     snippet = SnippetFactory()
     url = reverse('snippet_detail', args=[snippet.pub_date.year,snippet.pub_date.month,snippet.slug])
     request = self.factory.get(url)
     request.user = self.user
     response = SnippetDetailView.as_view()(request, slug=snippet.slug)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context_data['user'], self.user)
     self.assertEqual(response.context_data['request'], request)
Beispiel #2
0
sitemaps = {
    'snippets': SnippetSiteMap
}

urlpatterns = patterns('',
    # Social integration
    url('', include('social.apps.django_app.urls', namespace='social')),

    # Auth
    url('', include('django.contrib.auth.urls', namespace='auth')),

    # Comments
    (r'^comments/', include('django_comments.urls')),

    # Index - create new snippet
    url(r'^$', login_required(SnippetCreateView.as_view(
        )), name='snippet_create'),

    # Individual posts
    url(r'^(?P<pub_date__year>\d{4})/(?P<pub_date__month>\d{1,2})/(?P<slug>[a-zA-Z0-9-]+)/?$', cache_page(900)(SnippetDetailView.as_view(
        )), name='snippet_detail'),

    # Login
    url(r'^accounts/login/?$', anonymous_required(LoginView.as_view(
        )), name='login'),

    # Sitemap
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
            name='django.contrib.sitemaps.views.sitemap'),
)
Beispiel #3
0
from django.conf.urls import patterns, url

from snippets.views import SnippetListView, SnippetCreateView, SnippetUpdateView, SnippetDetailView


# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('snippets.views',
    url('^$', SnippetCreateView.as_view(), name="snippet_create"),
    # This one is redundant!
    url('^create$', SnippetCreateView.as_view(), name="snippet_create_new"),
    url('^(?P<id>\d+)/$', SnippetDetailView.as_view(), name="snippet_detail"),
    url('^(?P<id>\d+)/edit$', SnippetUpdateView.as_view(), name="snippet_update"),
    url('^my-snippets/$', SnippetListView.as_view(), name="user_snippet_list")
)
Beispiel #4
0
from django.urls import path
from snippets.views import SnippetListView, SnippetDetailView


app_name = 'snippets'
urlpatterns = [
	path('', SnippetListView.as_view(), name='list'),
	path('<int:pk>/', SnippetDetailView.as_view(), name='detail')
]