Пример #1
0
def portfolio_add(request):
    if request.POST:
        profile = Profile.objects.get(user=request.user)
        portfolio_form = PortfolioForm(request.POST, request.FILES, instance=profile)

        if portfolio_form.is_valid() and request.POST["imagehash"]:

            image = img_move(request.POST["imagehash"], profile)
            materials = portfolio_form.cleaned_data["materials"]
            title = portfolio_form.cleaned_data["title"]
            dimensions = portfolio_form.cleaned_data["dimensions"]
            creation_date = portfolio_form.cleaned_data["creation_date"]
            portfolio = Portfolio(
                user=request.user,
                image=image,
                title=title,
                creation_date=creation_date,
                dimensions=dimensions,
                materials=materials,
                hash=request.POST["imagehash"],
            )
            portfolio.save()
            return HttpResponseRedirect(reverse("portfolio_view"))
    else:
        portfolio_form = PortfolioForm()

    context = {}
    context["portfolio_form"] = portfolio_form
    context["image_tank"] = Image_Upload_Form()

    return render_to_response("portfolio/portfolio_edit.html", context, context_instance=RequestContext(request))
Пример #2
0
def profile_edit(request, template_name='profiles/profile_edit.html'):
    """Edit profile."""

    if request.POST:
        profile = Profile.objects.get(user=request.user)
        profile_form = ProfileForm(request.POST, request.FILES, instance=profile)
        user_form = UserForm(request.POST, instance=request.user)
        
        if profile_form.is_valid() and user_form.is_valid():
            profile_form.save()
            user_form.save()
            
            if request.POST['imagehash']:
                profile.mugshot.delete() #Remove the old image object
                profile.mugshot = img_move(request.POST['imagehash'],profile) # And sets the new image object
                profile.save()
            
            return HttpResponseRedirect(reverse('profile_view'))
        else:
            context = {
                'profile_form': profile_form,
                'user_form': user_form,
            }
    else:
        profile = Profile.objects.get(user=request.user)

        context = {
            'profile_form': ProfileForm(instance=profile),
            'image_tank': Image_Upload_Form(),            
            'user_form': UserForm(instance=request.user),
        }
    return render_to_response(template_name, context, context_instance=RequestContext(request))
Пример #3
0
def portfolio_edit(request, portfolio_id):
    if request.POST:
        instance = get_object_or_404(Portfolio, id=portfolio_id)
        portfolio_form = PortfolioForm(request.POST, request.FILES, instance=instance)
        profile = Profile.objects.get(user=request.user)

        if portfolio_form.is_valid():
            if request.POST["imagehash"]:
                image = img_move(request.POST["imagehash"], profile)
            else:
                image = portfolio_form.cleaned_data["image"]

            materials = portfolio_form.cleaned_data["materials"]
            title = portfolio_form.cleaned_data["title"]
            dimensions = portfolio_form.cleaned_data["dimensions"]
            creation_date = portfolio_form.cleaned_data["creation_date"]

            portfolio_form.save()
            return HttpResponseRedirect(reverse("portfolio_view"))

    instance = get_object_or_404(Portfolio, id=portfolio_id)
    context = {}

    try:
        context["portfolio_image"] = Portfolio.objects.get(id=portfolio_id).image.url.__str__()
    except:
        handler500

    context["portfolio_form"] = PortfolioForm(instance=instance)
    context["image_tank"] = Image_Upload_Form()

    return render_to_response("portfolio/portfolio_edit.html", context, context_instance=RequestContext(request))