예제 #1
0
def create_blog_view(request):
    context = {}

    form = CreateBlogPostForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        obj = form.save(commit=False)
        obj.author = request.user
        obj.save()
        context['success_message'] = "Post Created Successfully"

        form = CreateBlogPostForm()

    context['form'] = form

    return render(request, 'blog/create_blog.html', context)
예제 #2
0
def create_blog_view(request):
    context = {}
    user = request.user
    if not user.is_authenticated:
        return redirect('must authenticate')

    form = CreateBlogPostForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        obj = form.save(commit=False)
        author = Account.objects.filter(email=user.email).first()
        obj.author = author
        obj.save()
        form = CreateBlogPostForm()
    context['form'] = form
    return render(request, 'blog/create_blog.html')
예제 #3
0
def create_blog_view(request):
    context = {}
    user = request.user
    if not user.is_authenticated:
        return redirect('must_authenticate')
    form = CreateBlogPostForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        # it wiwll create the form after all the fields have been validated
        # because i need set the author object to the blogpost coz it is not going to get set by default
        obj = form.save(commit=False)
        # to get the first item in ther query set
        author = Account.objects.filter(email=request.user.email).first()
        obj.author = author
        obj.save()
        form = CreateBlogPostForm()
    context['form'] = form
    return render(request, 'blog/create_blog.html', context)
예제 #4
0
def create_blog_view(request):

    context = {}

    user = request.user
    if not user.is_authenticated:
        return redirect('must_authenticate')

    form = CreateBlogPostForm(request.POST or None)
    if form.is_valid():
        obj = form.save(commit=False)
        author = User.objects.get(pk=user.id)
        obj.author = author
        obj.save()
        form = CreateBlogPostForm()

        context['form'] = form
    # TODO notifying about text size >
    # TODO handling not unique post titles
    return render(request, "create_blog.html", context)
예제 #5
0
파일: views.py 프로젝트: barnit88/Vlog
def create_blog_view(request):
    context = {}

    if request.GET:
        return search(request)

    user = request.user
    if not user.is_authenticated:
        return redirect('blog:must_authenticate')

    form = CreateBlogPostForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        obj = form.save(commit=False)
        author = Account.objects.filter(email=user.email).first()
        obj.author = author
        obj.save()
        context['message'] = "Blog Upload .Successful!!"
        form = CreateBlogPostForm()

    context['form'] = form
    return render(request, "blog/create_blog.html", context)
예제 #6
0
def create_blog_view(request):

    context = {}
    user = request.user
    if not user.is_authenticated:
        return redirect('must_authenticate')

    #IF user is Authenticated, will be abe to create Post
    form = CreateBlogPostForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        obj = form.save(commit=False)
        author = Account.objects.filter(email=user.email).first()
        obj.author = author
        obj.save()
        context['prompt_success'] = 'Blog Created'
        form = CreateBlogPostForm()

    context['form'] = form

    #Show Blog that belongs to the author in profile page,
    blog_posts = BlogPost.objects.filter(author=request.user)
    context['blog_posts'] = blog_posts
    return render(request, "blog/create_blog.html", context)
예제 #7
0
파일: views.py 프로젝트: vybhavpai/Blog
def create_blog_view(request):

    context = {}

    user = request.user
    user_id = Account.objects.filter(username=request.user).first()
    if not user.is_authenticated:
        return redirect('must_authenticate')

    form = CreateBlogPostForm(request.POST or None, request.FILES or None)
    #print(request.POST.get('title'))

    if form.is_valid():
        obj = form.save(commit=False)
        author = Account.objects.filter(email=user.email).first()
        obj.author = author
        obj.save()
        category_list_unsplit = form.cleaned_data['category']
        if category_list_unsplit:
            category_list = category_list_unsplit.split(':')
            for category in category_list:
                cat_obj = Categories()
                cat_obj.blog_id = BlogPost.objects.get(
                    title=form.cleaned_data['title'])
                cat_obj.category = category
                cat_obj.save()

        form = CreateBlogPostForm()
        for f in request.FILES.getlist('other_image'):
            img = Extra_Image()
            img.blog_id = obj
            img.image = f
            img.save()

    context['form'] = form

    return render(request, 'blog/create_blog.html', context)