示例#1
0
文件: views.py 项目: monusingh/assign
def favorite_delete(request, object_id):
    """Renders a formular to get confirmation to unfavorite the object
    the favorite that has ``object_id`` as id. It raise a 404 if there
    is not such a favorite, a 403 error is returned if the favorite is not
    owned by current user. If the action is successful the user
    is redirect using :func:`favorites.views._get_next`.

    :template favorites/favorite_delete.html: - ``form`` :class:`favorites.forms.Validation` instance.
                                              - ``favorite`` :class:`favorites.models.Favorite` to be deleted.
                                              - ``next`` value returned by :func:`favorites.views._get_next`."""
    favorite = get_object_or_404(Favorite, pk=object_id)
    # check credentials
    if not request.user == favorite.user:
        return HttpResponseForbidden()
    else:
        if request.method == 'POST':
            form = ValidationForm(request.POST)
            if form.is_valid():
                favorite.delete()
                return redirect(_get_next(request))
        else:
            form = ValidationForm()
        # if form is not valid or if it's a GET request
        ctx = {'form': form, 'favorite': favorite, 'next': _get_next(request)}
        return render(request, 'favorites/favorite_delete.html', ctx)
示例#2
0
def favorite_delete(request, object_id):
    """Renders a formular to get confirmation to unfavorite the object
    the favorite that has ``object_id`` as id. It raise a 404 if there
    is not such a favorite, a 403 error is returned if the favorite is not
    owned by current user. If the action is successful the user
    is redirect using :func:`favorites.views._get_next`.

    :template favorites/favorite_delete.html: - ``form`` :class:`favorites.forms.Validation` instance.
                                              - ``favorite`` :class:`favorites.models.Favorite` to be deleted.
                                              - ``next`` value returned by :func:`favorites.views._get_next`."""
    favorite = get_object_or_404(Favorite, pk=object_id)
    # check credentials
    if not request.user == favorite.user:
        return HttpResponseForbidden()
    else:
        if request.method == 'POST':
            form = ValidationForm(request.POST)
            if form.is_valid():
                favorite.delete()
                return redirect(_get_next(request))
        else:
            form = ValidationForm()
        # if form is not valid or if it's a GET request
        ctx = {'form': form, 'favorite': favorite, 'next': _get_next(request)}
        return render(request, 'favorites/favorite_delete.html', ctx)
示例#3
0
文件: views.py 项目: monusingh/assign
def favorite_toggle_share(request, favorite_id):
    """Confirm before submiting the toggle share action. If the action is successful
    the user is redirect using :func:`favorites.views._get_next`.

    :template favorites/favorite_toggle_share.html: - ``favorite`` :class:`favorites.models.Favorite` instance."""
    favorite = get_object_or_404(Favorite, pk=favorite_id)
    # check crendentials
    if request.user != favorite.user:
        return HttpResponseForbidden()
    else:
        if request.method == 'POST':
            form = ValidationForm(data=request.POST)
            if form.is_valid():
                favorite.shared = False if favorite.shared else True  # toggle
                favorite.save()
                return redirect(_get_next(request))
        else:
            form = ValidationForm()
        # form is not valid or it's a GET request
        ctx = {'favorite': favorite}
        return render(request, 'favorites/favorite_toggle_share.html', ctx)
示例#4
0
def favorite_toggle_share(request, favorite_id):
    """Confirm before submiting the toggle share action. If the action is successful
    the user is redirect using :func:`favorites.views._get_next`.

    :template favorites/favorite_toggle_share.html: - ``favorite`` :class:`favorites.models.Favorite` instance."""
    favorite = get_object_or_404(Favorite, pk=favorite_id)
    # check crendentials
    if request.user != favorite.user:
        return HttpResponseForbidden()
    else:
        if request.method == 'POST':
            form = ValidationForm(data=request.POST)
            if form.is_valid():
                favorite.shared = False if favorite.shared else True  # toggle
                favorite.save()
                return redirect(_get_next(request))
        else:
            form = ValidationForm()
        # form is not valid or it's a GET request
        ctx = {'favorite': favorite}
        return render(request, 'favorites/favorite_toggle_share.html', ctx)