Example #1
0
def picture_create(request):
  form = PictureForm(request.POST)
  if form.is_valid():
    form.save()
    return redirect('pictures')
  else:
    context = {'form': form}
    return render(request, 'products/new.html', context)
Example #2
0
def picture_create(request):
    form = PictureForm(request.POST)
    if form.is_valid():
        new_pic = form.save(commit=False)
        new_pic.user = request.user

        new_pic.save()
    return HttpResponseRedirect('/pictures')
Example #3
0
def new_picture(request):
    form = PictureForm(request.POST)
    if form.is_valid():
        new_picture = form.save(commit=False)
        new_picture.user = request.user
        new_picture.save()
        return redirect('pictures')
    else:
        return render(request, 'new_picture_form.html', {
        'form': form
    })
Example #4
0
def new_picture_form(request):
    form = PictureForm(request.POST)

    if form.is_valid():
        new_picture = form.save(commit=False)
        new_picture.user = request.user
        new_picture.save()

        return redirect(reverse('show_all'))
    else:  # Else sends user back to picture_form page.
        return render(request, 'picture_form.html', {'form': form})
Example #5
0
def add_picture(request):
    if request.method == "POST":
        form = PictureForm(request.POST)
        if form.is_valid():
            new_picture = form.instance
            new_picture.user = request.user
            new_picture.save()
            return HttpResponseRedirect('/')
    else:
        form = PictureForm()
    html_response = render(request, 'new_picture.html', {'form': form})
    return HttpResponse(html_response)
Example #6
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)
    if request.method == 'POST':
        form = PictureForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data.get('title')
            artist = form.cleaned_data.get('artist')
            url = form.cleaned_data.get('url')
            picture.title = title
            picture.artist = artist
            picture.url = url
            picture.save()
            return HttpResponseRedirect('/pictures')
    form = PictureForm(request.POST)
    context = {'picture': picture, 'form': form}
    return HttpResponse(render(request, 'edit.html', context))
Example #7
0
def picture_new(request):
  form = PictureForm()
  context = {
    'form': form,
    'title': 'Add a New Picture',
  }
  response = render(request, 'pictures/new.html', context)
  return HttpResponse(response)
Example #8
0
def add_picture(request):
    if request.method == 'POST':
        form = PictureForm(request.POST)
        if form.is_valid():
            add_pic = form.save(commit=False)
            add_pic.user = request.user
            form.save()
            return redirect('picture_details', id=add_pic.id)
    else:
        form = PictureForm()
    html_response = render(request, 'new_pic.html', {'form': form})
    return HttpResponse(html_response)
Example #9
0
def picture_edit(request, picture_id):
    picture = get_object_or_404(Picture, pk=picture_id, user=request.user.pk)

    form = PictureForm(request.POST)

    if form.is_valid():
        edit_picture = form.save(commit=False)
        edit_picture.user = request.user
        edit_picture.id = picture_id
        edit_picture.save()
        return redirect(
            reverse('image_details', kwargs={'picture_id': picture_id}))
    else:
        return render(
            request, 'picture_edit.html', {
                'picture': picture,
                'picture_id': picture_id,
                'form': PictureForm(instance=picture)
            })
Example #10
0
def add_picture(request):
    if request.method == 'POST':
        picture_form = PictureForm(request.POST)
        if picture_form.is_valid():
            new_pic = picture_form.save(commit=False)
            new_pic.user = request.user
            picture_form.save()
            return redirect('/pictures', id=new_pic.id)
    else:
        picture_form = PictureForm()
        return render(request, 'add_picture.html',
                      {'picture_form': picture_form})
Example #11
0
def new_picture(request):
    if request.method == 'POST':
        form = PictureForm(request.POST)
        if form.is_valid():
            form.user = request.user
            form.save()
            return HttpResponseRedirect('/pictures')
    else:
        form = PictureForm()

    context = {'form': form}
    response = render(request, 'new_picture.html', context)
    return HttpResponse(response)
Example #12
0
def new_picture_view(request):
    if request.method == "POST":
        form = PictureForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = request.user
            form.save()
            return redirect("picture_details", id=instance.id)
    else:
        form = PictureForm()

    html_response = render(request, "new_picture.html", {"form": form})
    return HttpResponse(html_response)
Example #13
0
def picture_edit(request, picture_id):
  # picture = Picture.objects.get(id=picture_id)
  picture = get_object_or_404(Picture, id=picture_id, user=request.user.id)
  form = PictureForm(instance=picture)
  context = {
    'form': form,
    'title': f'Edit {picture.title} Information',
    'picture': picture
  }
  response = render(request, 'pictures/edit.html', context)
  return HttpResponse(response)
Example #14
0
def picture_update(request, picture_id):
  picture = get_object_or_404(Picture, id=picture_id, user=request.user.id)
  # picture = Picture.objects.get(id=picture_id)
  form = PictureForm(request.POST, instance=picture)
  if form.is_valid():
    picture_edit = form.instance
    picture_edit.user = request.user
    picture_edit.id = picture_id
    # picture_edit.picture = picture
    picture_edit.save()
    # form.save()
    return redirect('picture_show', picture.id)
  else:
    context = {
      'form': form,
      'title': f'Edit {picture.title} Information',
      'product': product,
    }
    response = render(request, 'pictures/edit.html', context)
    return HttpResponse(response)
Example #15
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)
    if request.method == 'POST':
        form = PictureForm(request.POST, instance=picture)
        if form.is_valid():
            form.save()
            return redirect('picture_details', id=picture.id)
    else:
        form = PictureForm(instance=picture)
    context = {'form': form, 'picture': picture}
    return render(request, 'editpic.html', context)
Example #16
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)

    if request.method == 'POST':
        form = PictureForm(request.POST, instance=picture)
        if form.is_valid():
            form.user = request.user
            form.save()
            return HttpResponseRedirect('/pictures/' + str(picture.id))
    else:
        form = PictureForm(instance=picture)

    context = {'picture': picture, 'form': form}
    response = render(request, 'edit_picture.html', context)
    return HttpResponse(response)
Example #17
0
def edit_picture_view(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)

    if request.method == "POST":
        form = PictureForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = request.user
            form.save()
            return redirect("picture_details", id=instance.id)
    else:
        form = PictureForm(instance=picture)

    context = {"form": form, "picture": picture}
    html_response = render(request, "edit_picture.html", context)
    return HttpResponse(html_response)
Example #18
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, id=id, user=request.user.pk)
    print(picture.user)
    if request.method == 'POST':
        picture_form = PictureForm(request.POST, instance=picture)
        if picture_form.is_valid():
            picture_form.save()
            return redirect('/pictures', id=picture.id)
    else:
        picture_form = PictureForm(instance=picture)
        return render(request, 'edit_picture.html', {
            'picture_form': picture_form,
            'picture': picture
        })
Example #19
0
def edit_picture(request, id):
    obj = get_object_or_404(Picture, id=id, user=request.user.id)
    if request.method == "POST":
        form = PictureForm(request.POST, instance=obj)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.save()
            return redirect('picture_details', id=obj.id)
    else:
        form = PictureForm(instance=obj)
    return render(request, 'edit_picture.html', {'form': form})
Example #20
0
def new_picture(request):
    if request.method == 'POST':
        form = PictureForm(request.POST)
        if form.is_valid():
            picture = form.save(commit=False)
            picture.user = request.user
            picture.save()
            return redirect('picture_details', id=picture.id)
    else:
        form = PictureForm()
    context = {'form': form}
    return render(request, 'createpic.html', context)
Example #21
0
def submit_picture(request):
    if request.method == 'POST':
        form = PictureForm(request.POST)
        if form.is_valid():
            picture = form.save(commit=False)
            picture.user = request.user
            picture.save()
            return redirect("picture_details", id=picture.id)
            # return HttpResponseRedirect('/addpic')

    else:
        form = PictureForm()
        context = {'form': form}
        response = render(request, 'addpicture.html', context)
        return HttpResponse(response)
Example #22
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)
    if request.method == 'GET':
        form = PictureForm(instance=picture)
        return render(request, 'edit_picture_form.html', {
            "picture": picture,
            "form": form
        })
    elif request.method == 'POST': 
        form = PictureForm(request.POST, instance=picture) 
        if form.is_valid(): 
            update_picture = form.save() 
            return redirect(reverse('picture_details', args=[picture.id]))
        else: 
            context = { 'form': form, 'picture': picture }
            return render(request, 'edit_picture_form.html', context) 
Example #23
0
def edit_picture(request, id):
    picture = get_object_or_404(Picture, pk=id, user=request.user.pk)
    if request.method == "POST":
        form = PictureForm(request.POST, instance=picture)
        if form.is_valid():
            updated_picture = form.save()
            return HttpResponseRedirect(
                reverse('picture_details', args=[picture.id]))
    else:
        form = PictureForm(instance=picture)
    context = {'form': form, 'picture': picture}
    html_response = render(request, 'edit_picture.html', context)
    return HttpResponse(html_response)

    context = {'picture': picture}
    html_response = render(request, "edit_picture.html", context)
    return HttpResponse(html_response)
Example #24
0
def picture_new(request):
    return render(request, 'picture-form.html',{
        'form': PictureForm(),
        'message': 'Post a picture!!',
        'action': '/pictures/create'
    })