def test_subscribe(self):
        request = self.factory.post(
            self.path,
            {
                'action': 'Subscribe',
                'author': self.admin.username,
                'subscriber': self.user.username,
            },
            kwargs={'username': self.admin.username},
        )

        request.user = self.user
        response = UserView().post(request=request,
                                   username=self.admin.username)

        assert response.status_code == 302
        assert response.url == reverse(
            'blog:user_view', kwargs={'username': self.admin.username})
        assert Subscription.objects.filter(author=self.admin).count() == 1
        assert (Subscription.objects.filter(author=self.admin,
                                            subscriber=self.user).exists())

        # if sub already exists
        response = UserView().post(request=request,
                                   username=self.admin.username)
        assert response.status_code == 302
        assert response.url == reverse(
            'blog:user_view', kwargs={'username': self.admin.username})
        assert Subscription.objects.filter(author=self.admin).count() == 1
        assert (Subscription.objects.filter(author=self.admin,
                                            subscriber=self.user).exists())
    def test_unsubscribe(self):
        request = self.factory.post(
            self.path,
            {
                'action': 'Unsubscribe',
            },
            kwargs={'username': self.admin.username},
        )

        request.user = self.user
        response = UserView().post(request=request,
                                   username=self.admin.username)

        assert response.status_code == 302
        assert response.url == reverse(
            'blog:user_view', kwargs={'username': self.admin.username})

        mixer.blend(Subscription, author=self.admin, subscriber=self.user)
        post = mixer.blend(Post, author=self.admin)
        post.read_by.add(self.user)

        response = UserView().post(request=request,
                                   username=self.admin.username)

        assert response.status_code == 302
        assert response.url == reverse(
            'blog:user_view', kwargs={'username': self.admin.username})
        assert Subscription.objects.filter(author=self.admin,
                                           subscriber=self.user).count() == 0
        assert not self.user.user_read.filter(author=self.admin).exists()
        assert not (Subscription.objects.filter(author=self.admin,
                                                subscriber=self.user).exists())
    def test_create_post(self):
        request = self.factory.post(
            self.path,
            {
                'title': 'title1',
                'content': 'content1',
            },
            kwargs={'username': self.admin.username},
        )

        request.user = self.user
        response = UserView().post(request=request,
                                   username=self.admin.username)

        assert response.status_code == 302
        assert response.url == reverse(
            'blog:user_view', kwargs={'username': self.admin.username})

        # TODO: google tasks delayed check
        """
Example #4
0
from django.conf.urls import url
from blog.views import IndexView, ArticleView, AboutView, AllView, DownView, SearchView, ColumnView, UserView, TagView, CategoryView
from django.views.generic import TemplateView, DetailView

urlpatterns = [
    url(r'^$', IndexView.as_view()),
    url(r'^article/(?P<slug>\w+).html$', ArticleView.as_view()),
    url(r'^all/$', AllView.as_view()),
    url(r'^search/$', SearchView.as_view()),
    url(r'^login/$', TemplateView.as_view(template_name="blog/login.html")),
    url(r'^register/$',
        TemplateView.as_view(template_name="blog/register.html")),
    url(r'^forgetpassword/$',
        TemplateView.as_view(template_name="blog/forgetpassword.html")),
    url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        TemplateView.as_view(template_name="blog/resetpassword.html")),
    url(r'^column/(?P<column>\w+)$', ColumnView.as_view()),
    url(r'^user/(?P<slug>\w+)$', UserView.as_view()),
    url(r'^tag/(?P<tag>\w+)/$', TagView.as_view()),
    url(r'^category/(?P<category>\w+)/$', CategoryView.as_view()),
    url(r'^about/$', AboutView.as_view()),
    url(r'^down/$', DownView.as_view()),
]
Example #5
0
from blog.views import (
    IndexView,
    ArticleView,
    AllView,
    SearchView,
    ColumnView,
    UserView,
    NewsView,
    TagView,
    CategoryView,
)
from django.views.generic import TemplateView, DetailView
from blog.models import News

urlpatterns = [
    url(r"^$", IndexView.as_view()),
    url(r"^article/(?P<slug>\w+).html$", ArticleView.as_view()),
    url(r"^all/$", AllView.as_view()),
    url(r"^search/$", SearchView.as_view()),
    #        url(r'^login/$',TemplateView.as_view(template_name="blog/login.html")),
    #        url(r'^register/$',TemplateView.as_view(template_name="blog/register.html")),
    #        url(r'^forgetpassword/$',TemplateView.as_view(template_name="blog/forgetpassword.html")),
    #        url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',TemplateView.as_view(template_name="blog/resetpassword.html")),
    url(r"^column/(?P<column>\w+)$", ColumnView.as_view()),
    url(r"^user/(?P<slug>\w+)$", UserView.as_view()),
    url(r"^about/$", NewsView.as_view()),
    url(r"^news/(?P<pk>\w+)$", DetailView.as_view(model=News)),
    url(r"^tag/(?P<tag>\w+)/$", TagView.as_view()),
    url(r"^category/(?P<category>\w+)/$", CategoryView.as_view()),
]
Example #6
0
File: urls.py Project: levylll/NGB
from django.conf.urls import url
from blog.views import IndexView,ArticleView,AllView,SearchView,ColumnView,UserView,NewsView,TagView,CategoryView
from django.views.generic import TemplateView,DetailView
from blog.models import News

urlpatterns = [
        url(r'^$',IndexView.as_view()),
        url(r'^article/(?P<slug>\w+).html$',ArticleView.as_view()),
        url(r'^all/$',AllView.as_view()),
        url(r'^search/$',SearchView.as_view()),
        url(r'^login/$',TemplateView.as_view(template_name="blog/login.html")),
        url(r'^register/$',TemplateView.as_view(template_name="blog/register.html")),
        url(r'^forgetpassword/$',TemplateView.as_view(template_name="blog/forgetpassword.html")),
        url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',TemplateView.as_view(template_name="blog/resetpassword.html")),
        url(r'^column/(?P<column>\w+)$',ColumnView.as_view()),
        url(r'^user/(?P<slug>\w+)$',UserView.as_view()),
        url(r'^news/$',NewsView.as_view()),
        url(r'^news/(?P<pk>\w+)$',DetailView.as_view(model=News)),
        url(r'^tag/(?P<tag>\w+)/$',TagView.as_view()),
        url(r'^category/(?P<category>\w+)/$',CategoryView.as_view()),
]
Example #7
0
    url(r'^forgetpassword/$',
        TemplateView.as_view(template_name="sys/forgetpassword.html"),
        name='forgetpassword-view'),
    url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        TemplateView.as_view(template_name="sys/resetpassword.html"),
        name='resetpassword-view'),
    url(r'^aboutme/$', AboutMeView.as_view(), name='aboutme-view'),
    url(r'^media/article/(?P<path>.*)', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT + '/article'}),
    url(r'^article/(?P<pk>\d+)/$', ArticleView.as_view(), name='article-view'),
    url(r'^tag/(?P<tag_name>.+)/$', TagsView.as_view(), name='tag-view'),
    url(r'^all/$', AllView.as_view(), name='all-view'),
    url(r'^comment/(?P<slug>\w+)/$',
        PostCommentView.as_view(),
        name='postcomment-view'),
    url(r'^search/$', SearchView.as_view(), name='search-view'),
    url(r'^category/(?P<pk>\w+)/$',
        CaregoryView.as_view(),
        name='category-view'),
    url(r'^datearticle/(?P<year>\d+)/(?P<month>\d+)/$',
        DateArticleView.as_view(),
        name='datearticle-view'),
    url(r'^msgbook/$', MsgBookView.as_view(), name='msgbook-view'),
    url(r'^photo/$', PhotoView.as_view(), name='photo-view'),
    url(r'^photolist/(?P<pk>\d+)/$',
        PhothListView.as_view(),
        name='photolist-view'),
    url(r'^addarticle/$', AddArticleView.as_view(), name='addarticle-view'),
    url(r'^user/(?P<slug>\w+)$', UserView.as_view(), name='user-view'),
]
Example #8
0
The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
import xadmin
from blog.views import UserView, LearnView, LifeView, AboutMeView, MessageView, EmailView
from django.views.static import serve
from MyBlog.settings import MEDIA_ROOT

urlpatterns = [
    # url(r'^admin/', admin.site.urls),
    url(r'^xadmin/', xadmin.site.urls),
    url(r'^myblog/$', UserView.as_view(), name="index"),
    url(r'^learn/$', LearnView.as_view(), name='learn'),
    url(r'^life/$', LifeView.as_view(), name='life'),
    url(r'^about_me/$', AboutMeView, name='about_me'),
    url(r'^message/$', MessageView, name='message'),
    url(r'^email/', EmailView, name='email'),
    url(r'^media/(?P<path>.*)/$', serve, {"document_root": MEDIA_ROOT}),
]
Example #9
0
    url(r'^article/(?P<slug>[\s\S]*).html$',
        ArticleView.as_view(),
        name='article-detail-view'),
    url(r'^all/$', AllView.as_view(), name='all-view'),
    url(r'^search/$', SearchView.as_view()),
    url(r'^login/$',
        TemplateView.as_view(template_name="blog/login.html"),
        name='login-view'),
    url(r'^register/$',
        TemplateView.as_view(template_name="blog/register.html"),
        name='register-view'),
    url(r'^forgetpassword/$',
        TemplateView.as_view(template_name="blog/forgetpassword.html"),
        name='forgetpassword-view'),
    url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
        TemplateView.as_view(template_name="blog/resetpassword.html"),
        name='resetpassword-view'),
    url(r'^column/(?P<column>[\s\S]*)/$',
        ColumnView.as_view(),
        name='column-detail-view'),
    url(r'^user/(?P<slug>[\s\S]*)$', UserView.as_view(), name='user-view'),
    url(r'^news/$', NewsView.as_view(), name='news-view'),
    url(r'^news/(?P<pk>[\s\S]*)$',
        DetailView.as_view(model=News),
        name='news-detail-view'),
    url(r'^tag/(?P<tag>[\s\S]*)/$', TagView.as_view(), name='tag-detail-view'),
    url(r'^category/(?P<category>[\s\S]*)/$',
        CategoryView.as_view(),
        name='category-detail-view'),
]
Example #10
0
    PostTemplateView, LogoutView, FeedView, IndexView, PostListView,\
    PostListAllView
from django.contrib.auth import views as auth_views

urlpatterns = [
    path('login/', auth_views.LoginView.as_view(), name='login'),
    path('api/logout/', LogoutView.as_view()),
    path('list/', PostListView.as_view(), name='list'),
    path('list_all/', PostListAllView.as_view(), name='list_all'),
    path('list/<int:user_id>/', UserListView.as_view(), name='user_list'),
    path('feed/', FeedView.as_view(), name='feed'),
    path('post/<int:post_id>/', PostTemplateView.as_view(), name='post_view'),
    path('api/post/<int:post_id>/', PostView.as_view()),
    path('admin/', admin.site.urls),
    path('api/subscribe/<int:author_id>/', AddSubscriptionView.as_view()),
    path('api/unsubscribe/<int:author_id>/', DeleteSubscriptionView.as_view()),
    path('api/create-post/', CreatePostView.as_view()),
    path('api/list/', GetMyList.as_view()),
    path('api/list-all/', GetAllMyList.as_view()),
    path('api/feed/', AllPosts.as_view()),
    path('api/list/<int:user_id>/', GetUserList.as_view()),
    path('api/mark-read/<int:post_id>/', MarkPost.as_view()),
    path('api/users/', UserView.as_view()),
    path('api/subscriptions/', SubscriptionView.as_view()),
    path('api/nosubscriptions/', NoSubscriptionView.as_view()),
    re_path(r'^$', IndexView.as_view(), name='index'),
]

urlpatterns += [
    re_path(r'^accounts/', include('django.contrib.auth.urls')),
]
Example #11
0
File: urls.py Project: jqlts1/blog
        url(r'^all/$', AllView.as_view(), name='all-view'),
        url(r'^search/$', SearchView.as_view()),
        url(r'^login/$',
            TemplateView.as_view(template_name="blog/login.html"),
            name='login-view'),
        url(r'^register/$',
            TemplateView.as_view(template_name="blog/register.html"),
            name='register-view'),
        url(r'^forgetpassword/$',
            TemplateView.as_view(template_name="blog/forgetpassword.html"),
            name='forgetpassword-view'),
        url(r'^resetpassword/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
            TemplateView.as_view(template_name="blog/resetpassword.html"),
            name='resetpassword-view'),
        url(r'^column/(?P<column>\w+)/$',
            ColumnView.as_view(), name='column-detail-view'),
        url(r'^user/(?P<slug>\w+)$', UserView.as_view(), name='user-view'),
        url(r'^news/$', NewsView.as_view(), name='news-view'),
        url(r'^news/(?P<pk>\w+)$',
            DetailView.as_view(model=News), name='news-detail-view'),
        url(r'^tag/(?P<tag>\w+)/$', TagView.as_view(), name='tag-detail-view'),
        url(r'^(?P<category>\w+)/$',
            CategoryView.as_view(), name='category-detail-view'),
]


if settings.DEBUG:
    from django.conf.urls.static import static
    urlpatterns += static(
        settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Example #12
0
    def test_get_user_view_another_authenticated(self):
        request = self.factory.get(self.path)
        request.user = self.user

        response = UserView().get(request=request, username='******')
        assert response.status_code == 200
Example #13
0
from blog.views import ProfileView, PostCreateView, PostListView, PostDetailView, UserPostListView, \
    CommentListView, MessagesListView, MessagesUserView, UserView, PostUpdateView

post_urls = [
    url(r'^create/$', PostCreateView.as_view(), name='post-create'),
    url(r'^update/(?P<pk>[-\w]+)/$',
        PostUpdateView.as_view(),
        name='post-update'),
    url(r'^my/$', UserPostListView.as_view(), name='post-list-user'),
    url(r'^comments/$', CommentListView.as_view(), name='comment-list-user'),
    url(r'^(?P<pk>[-\w]+)/$', PostDetailView.as_view(), name='post-detail'),
]

messages_urls = [
    url(r'^$', MessagesListView.as_view(), name='message_list'),
    url(r'^(?P<user>[-\w]+)/$', MessagesUserView.as_view(), name='message'),
]

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^accounts/', include('allauth.urls')),
    url(r'^$', PostListView.as_view(), name='post-list'),
    url(r'^accounts/profile/$', ProfileView.as_view(), name='profile'),
    url(r'^user/(?P<pk>[-\w]+)/$', UserView.as_view(), name='profile-public'),
    url(r'^posts/', include(post_urls)),
    url(r'^messages/', include(messages_urls)),
    url(r'^summernote/', include('django_summernote.urls')),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Example #14
0
from .views import ping

router = routers.SimpleRouter()
router.register(r"blog", BlogPostViewSet)

schema_view = get_schema_view(
    openapi.Info(title="Simple blog API", default_version="v1"),
    public=True,
    permission_classes=(permissions.AllowAny, ),
)

urlpatterns = [
    path("admin/", admin.site.urls),
    path("ping/", ping, name="ping"),
    path(
        "api/docs/",
        schema_view.with_ui("swagger", cache_timeout=0),
        name="schema-swagger-ui",
    ),
    path("api/register/", RegisterView.as_view(), name="register"),
    path("api/login/", LoginView.as_view(), name="login"),
    path("api/logout/", LogoutView.as_view(), name="logout"),
    path("api/user/", UserView.as_view(), name="current-user"),
    path("api/tags/", TagsView.as_view(), name="tags"),
    path("api/", include(router.urls)),
    path("api/blog/<slug:slug>/comments/",
         CommentsView.as_view(),
         name="comments"),
    path("api/image/", ImageView.as_view(), name="image"),
]
Example #15
0
from django.urls import path, re_path
from .custom_site import custom_site
from blog.views import IndexView, CategoryView, TagView, PostDetailView, \
    demo, SearchView, LoginViewSet, IndexViewSimple, UserView, AuthorView, \
    DemoView
from config.views import LinkListView
from comment.views import CommentView

urlpatterns = [
    re_path('^$', IndexView.as_view(), name='index'),
    re_path('^category/(?P<category_id>\d+)/$',
            CategoryView.as_view(),
            name='category-list'),
    re_path('^tag/(?P<tag_id>\d+)/$', TagView.as_view(), name='tag-list'),
    re_path('^post/(?P<post_id>\d+).html$',
            PostDetailView.as_view(),
            name='post-detail'),
    re_path('^author/(?P<owner_id>\d+)/$', AuthorView.as_view(),
            name='author'),
    re_path('^links/$', LinkListView.as_view(), name='links'),
    re_path('^super_admin/', admin.site.urls, name='super-admin'),
    re_path('^admin/', custom_site.urls, name='admin'),
    re_path('^comment/$', CommentView.as_view(), name='comment'),
    path('demo/', demo),
    re_path('^search/$', SearchView.as_view(), name='search'),
    path('api/v1/logintoken/', LoginViewSet.as_view(), name='logintoken'),
    path('api/v1/user/', UserView.as_view(), name='userauth'),
    path('api/v1/demo/', DemoView.as_view(), name='demov'),
    path('index/', IndexViewSimple.as_view(), name='indexsimple'),
]