def _post_response(self, user, data): url = reverse('reviews:add_review') request = self.factory.post(url, data) store = _create_session() request.session = store request.user = user messages = FallbackStorage(request) request._messages = messages view = ReviewCreateView.as_view() return view(request)
from django.urls import include, path from django.conf.urls import url from reviews.views import about_view, ReviewsListView, ReviewsDetailView, ReviewCreateView, ReviewListCreate, UserListCreate, LocationListCreate, TagListCreate, ReviewUpVoteToggle, ReviewDownVoteToggle app_name = 'reviews' urlpatterns = [ url(r'^$', ReviewsListView.as_view(), name="list"), url(r'^create/$', ReviewCreateView.as_view(), name="create"), url(r'^(?P<slug>[\w-]+)/$', ReviewsDetailView.as_view(), name="detail"), url(r'^(?P<slug>[\w-]+)/upvote/$', ReviewUpVoteToggle.as_view(), name="upvote-toggle"), url(r'^(?P<slug>[\w-]+)/downvote/$', ReviewDownVoteToggle.as_view(), name="downvote-toggle"), path('create/api/review/', ReviewListCreate.as_view()), path('api/review/', ReviewListCreate.as_view()), path('api/user/', UserListCreate.as_view()), path('create/api/location/', LocationListCreate.as_view()), path('create/api/tag/', TagListCreate.as_view()), path('create/api/user/', UserListCreate.as_view()), path('api/location/', LocationListCreate.as_view()), path('api/tag/', TagListCreate.as_view()), #Names makes it easier to refer to the paths; so if path changes you don't need to change all references ]
def _get_response(self, user): url = reverse('reviews:add_review') request = self.factory.get(url) request.user = user view = ReviewCreateView.as_view() return view(request)
from django.urls import path from reviews.views import ReviewListView, ReviewCreateView, \ ReviewUpdateView, StaffReviewListView app_name = 'reviews' urlpatterns = [ path('', ReviewListView.as_view(), name='reviews'), ##### VIEWS FOR LOGGED IN USER ONLY ##### # add a review path('add/', ReviewCreateView.as_view(), name='add_review'), # edit review (allow users to edit their own reviews) path('<slug:slug>/edit/', ReviewUpdateView.as_view(), name='edit_review'), ##### VIEWS FOR STAFF USER ONLY ##### # listview for all reviews, button to publish/reject path('staff-review/', StaffReviewListView.as_view(), name='staff_reviews') ]