Esempio n. 1
0
def add(request):
    if not users.is_current_user_admin():
        return redirect(users.create_login_url("/"))

    success = False

    if request.method == "POST":
        form = PortfolioForm(request.POST)
        if form.is_valid():
            form.save()
            success = True
    else:
        form = PortfolioForm()

    data = {"form": form, "success": success}

    return render_to_response("portfolios/add.html", data, context_instance=RequestContext(request))
Esempio n. 2
0
def edit(request, pk=None):

    # portfolio pk is portfolio.user.id
    if pk is None:
        pk = request.user.id
    user = get_object_or_404(User, id=pk)
    p = get_object_or_404(Portfolio, user=user)

    # if user submitted the Portfolio form to make changes:
    form = PortfolioForm(request.POST or None, instance=p)
    if form.is_valid():
        form.save()
        messages.success(request, "Portfolio updated.")

    # only allow admins or the users to edit their own portfolios
    if request.user.is_staff or request.user == p.user:
        context = {"p": p, "form": form}
        return render(request, "portfolios/edit.html", context)
    else:
        raise Http404("Sorry, this portfolio isn't yours!")
Esempio n. 3
0
def edit(request, pk=None):
    # portfolio pk is portfolio.user.id
    if pk is None:
        pk = request.user.id
    user = get_object_or_404(User, id=pk)
    p = get_object_or_404(Portfolio, user=user)

    # if user submitted the Portfolio form to make changes:
    form = PortfolioForm(request.POST or None, instance=p)
    if form.is_valid():
        form.save()
        messages.success(request, "Portfolio updated.")

    # only allow admins or the users to edit their own portfolios
    if request.user.is_staff or request.user == p.user:
        context = {
            "p": p,
            "form": form,
        }
        return render(request, 'portfolios/edit.html', context)
    else:
        raise Http404("Sorry, this portfolio isn't yours!")
Esempio n. 4
0
def update(request, slug):
    if not users.is_current_user_admin():
        return redirect(users.create_login_url("/"))

    portfolio = Portfolio.all().filter("slug =", slug)
    if portfolio.count():
        portfolio = portfolio[0]
    else:
        raise Http404

    success = False

    if request.method == "POST":
        form = PortfolioForm(request.POST, instance=portfolio)
        if form.is_valid():
            entity = form.save(commit=False)
            entity.put()
            success = True
    else:
        form = PortfolioForm(instance=portfolio)

    data = {"form": form, "portfolio": portfolio, "success": success}

    return render_to_response("portfolios/update.html", data, context_instance=RequestContext(request))