コード例 #1
0
def blog_page(request):
    '''
    handles the dashobard landing page
    if user not logged in and not stuff we show them the login page
    @request  request object
    '''
    if not request.user.is_active or not request.user.is_staff:
        return render_view(request, 'login.html', {})
    if request.POST:
        print request.POST
        form = AddPostForm(request.POST, request.FILES)
        if not form.is_valid():
            error_message(request, "addpost")
        else:
            post = form.save()
            success_message(request, "addpost", {'post': post, 'is_published': request.POST['is_published']})
    return render_view(request, 'dashboard-index.html', {})
コード例 #2
0
def editblog_page(request, slug, action):
    '''
    handles the blog page 
    @request  request object
    '''
    post = get_object_or_404(Post.objects.filter(slug=slug, owner=request.user.pk), slug=slug, owner=request.user.pk)
    if request.POST:
        post = Post.objects.get(slug=slug, owner=request.user.pk)
        post_action = request.POST['post_action']
        if post_action == 'edit':
            post.title = request.POST['title']
            post.body = request.POST['body']
            if 'is_featured' in request.POST:
                post.is_featured = True
            else:
                post.is_featured = False
            if 'is_published' in request.POST:
                post.is_published = True
            else:
                post.is_published = False
            if 'attachment' in request.FILES:
                post.attachment = request.FILES['attachment']
            post.save()
            slug = post.slug
            success_message(request, "editpost", {'post': post})
            return HttpResponseRedirect(reverse('editblogpost', args=(slug, action)))
        if post_action == 'delete':
            post.delete()
            success_message(request, "deletepost",)
            return HttpResponseRedirect(reverse('dashboardposts',))
        if post_action == 'unpublish':
            post.is_published = False
            post.is_featured = False
            post.save()
            success_message(request, "unpublish",)
            action = 'publish'
            return HttpResponseRedirect(reverse('editblogpost', args=(slug, action)))
        if post_action == 'publish':
            post.is_published = True
            if 'is_featured' in request.POST:
                post.is_featured = True
            else:
                post.is_featured = False
            post.save()
            success_message(request, "editpost", {'post': post})
            action = 'edit'
            return HttpResponseRedirect(reverse('editblogpost', args=(slug, action)))
    return render_view(request, 'dashboard-editpost.html', {'post': post, 'action': action})
コード例 #3
0
def login_page(request):
    '''
    handles the dashobard landing page
    if user not logged in and not stuff we show them the login page
    @request  request object
    '''
    if request.POST:
        form = loginForm(request.POST)
        if form.is_valid():
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active and user.is_staff:
                    login(request, user)
                    success_message(request, "login")
                    return HttpResponseRedirect(settings.DASHBOARD_URL)
                else:
                    error_message(request, "login")
            else:
                error_message(request, "login")
        else:
            error_message(request, "login")
    return render_view(request, 'login.html')