Example #1
0
 def post(self, request, *args, **kwargs):
     form = PostCreateForm(request.POST)
     if form.is_valid():
         post = form.save()
         post.save()
         return HttpResponseRedirect(reverse_lazy('posts:post-list-page'))
     return render(request, 'blog/new.html', {'form': form})
Example #2
0
    def post(self, req):
        """
        Muestra un form para crear un post y lo crea si la peticion es POST
        :param req: HttpRequest
        :return: HttpResponse
        """
        error_messages = []
        success_message = ''

        # Creamos owner y se lo pasamos al form con un objeto pre-establecido
        post_with_owner = Post()
        post_with_owner.owner = req.user
        post_with_owner.blog = Blog.objects.filter(owner=req.user)[0]

        form = PostCreateForm(req.POST, instance=post_with_owner)
        if form.is_valid():

            new_post = form.save()
            form = PostCreateForm()
            success_message = u'Post guardado con éxito! '
            success_message += u'<a href="{0}">'.format(reverse('post_detail', args=[req.user.username, new_post.pk]))
            success_message += u'(ver post)</a>'
        else:
            error_messages.append(u'Formulario incompleto.')

        context = {
            'form': form,
            'success_message': success_message
        }
        return render(req, 'posts/new_post.html', context)
Example #3
0
def post_create(request):
    title = "Create"
    form = PostCreateForm(request.POST or None, request.FILES or None)
    author = get_author(request.user)
    if request.method == 'POST':
        if form.is_valid():
            form.instance.author = author
            form.save()
            return redirect(
                reverse("post_detail", kwargs={'id': form.instance.id}))
    context = {'title': title, 'form': form}
    return render(request, "post_create.html", context)
Example #4
0
def post_create(request):
    """
    url:        /posts/create name='post-create'
    Template:   /posts/posts-create.html

    forms.PostCreateForm을 생성한다.

    :param request:
    :return:
    """

    if request.method == 'POST':
        images = request.FILES.getlist('image')
        content = request.POST['content']

        post = Post.objects.create(author=request.user, content=content)

        for image in images:
            PostImage.objects.create(post=post, image=image)

        return redirect('posts:post_list')

    else:
        form = PostCreateForm()
        context = {'form': form}
        return render(request, 'posts/post-create.html', context)
Example #5
0
def post_created(request):
    if request.method == 'POST':
        content = request.POST['content']
        images = request.FILES.getlist('images')
        post = Post.objects.create(author=request.user, content=content)
        for image in images:
            post.postimage_set.create(image=image)
        return redirect('posts:post_list')
    else:
        form = PostCreateForm()

    context = {'form': form}
    return render(request, 'posts/postcreate.html', context)
Example #6
0
def post_create(request):
    if not request.user.is_authenticated:
        return redirect('posts:post-list')

    if request.method == 'POST':
        post = Post(photo=request.FILES['photo'], )
        post.save()
        return redirect('posts:post-list')
    else:
        form = PostCreateForm()
        context = {
            'form': form,
        }

        return render(request, 'posts/post_create.html', context)
Example #7
0
def post_create(request):
    if request.method == 'POST':
        user = request.user
        image = request.FILES.getlist('image')
        text = request.POST['text']
        post = Post.objects.create(author=user, content=text)
        # post.postimage_set.create(image=image)
        # PostImage.objects.create(post=post, image=image)
        for f in image:
            PostImage.objects.create(post=post, image=f)
        return redirect('posts:post-list')
    else:
        form = PostCreateForm()
        context = {
            'forms': form
        }
        return render(request, 'posts/post-create.html', context)
Example #8
0
def post_create(request):
    if request.method == 'POST':
        form = PostCreateForm(request.POST, request.FILES)

        if form.is_valid():
            post = form.save(author=request.user)
            return redirect('posts:post_list')
    else:
        form = PostCreateForm()

    context = {'form': form}

    return render(request, 'posts/post_create.html', context)
Example #9
0
def post_create_view(request):
    if request.method == 'POST':
        text = request.POST['text']
        # image = request.FILES['image']
        # image 여러개 받을 때는
        images = request.FILES.getlist('image')
        post = Post.objects.create(author=request.user, content=text)
        # post.images_set.create(image=image)
        for image in images:
            post.images_set.create(image=image)
        return redirect('posts:post-list')
    else:
        form = PostCreateForm()
        print(form)

    context = {
        'form': form,
    }
    return render(request, 'posts/post-create.html', context)
def post_create(request):
    form = PostCreateForm()
    if request.method == 'POST':
        form = PostCreateForm(request.POST, request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()
            return redirect('posts:post-list')

    context = {
        'form': form,
    }

    return render(request, 'posts/post_create.html', context)
Example #11
0
def new_post(request):
    if request.method == 'POST':
        # TODO: create form, create template
        form = PostCreateForm(request.POST, request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.profile = request.user.profile
            post.save()

            return redirect('posts_list')

    else:
        form = PostCreateForm()

    return render(request, 'posts/create.html', {'form': form})
Example #12
0
def post_create(request):
    if request.method == 'POST':
        author = request.user
        content = request.POST['content']
        # 여러 개의 이미지를 받음
        images = request.FILES.getlist('image')

        # 새 포스트 생성
        post = Post.objects.create(author=author, content=content)

        for image in images:
            post.postimage_set.create(image=image)

        print('post.postimage_set >>> ', post.postimage_set)
        # post일 경우, 포스트 생성하고 post-list 페이지로 이동
        return redirect('posts:post-list')
    else:
        # get일 경우, 포스트 생성 페이지로 이동
        form = PostCreateForm()

        context = {'form': form}
        return render(request, 'posts/post_create.html', context)
Example #13
0
def post_create(request):
    """
    URL: /posts/create/
    Template: /posts/post-create.html

    forms.PostCreateForm을 사용

    """
    if request.method == 'POST':
        """
        새 Post 생성
        user는 request.user
        전달받는 데이터 : image, text
            image는 request.FILES에 있음
            text는 request.POST에 있음
        Post를 생성
            request.user와 text를 사용
        PostImage를 생성
            post와 전달받은 image를 사용
        모든 생성이 완료되면 posts:post-list로 redirect
        """
        text = request.POST['text']
        images = request.FILES.getlist('image')

        post = Post.objects.create(
            author=request.user,
            content=text,
        )

        for image in images:
            post.postimage_set.create(image=image)

        return redirect('posts:post-list')
    else:
        form = PostCreateForm()
        context = {
            'form': form,
        }
        return render(request, 'posts/post-create.html', context)
Example #14
0
def create(request, section):
    section = get_object_or_404(Section, name=section)

    form = PostCreateForm()
    if request.method == 'POST':
        form = PostCreateForm(request.POST, request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.section = section
            post.save()
            return redirect(post)

    return render(request, 'posts/create.html', dict(
        section = section,
        form = form,
    ))
Example #15
0
def post_create(request):
    if request.method == 'POST':
        # form is sent
        form = PostCreateForm(data=request.POST)
        if form.is_valid():
            # form data is valid
            cd = form.cleaned_data
            new_item = form.save(commit=False)

            # assign current user to the item
            new_item.author = request.user
            new_item.save()

            # redirect to new created item detail view
            return redirect(new_item.get_absolute_url())
    else:
        # build form with data provided by the bookmarklet via GET
        form = PostCreateForm(data=request.GET)

    return render(request, 'users/user-detail2.html', {'form': form})
Example #16
0
 def get(self, request, *args, **kwargs):
     post = {'form': PostCreateForm()}
     return render(request, 'blog/new.html', post)