Beispiel #1
0
def delete(request, diary_id):
    """Deletes a diary, only if logged in user is the creator."""
    entry = get_object_or_404(DiaryEntry, pk=diary_id)
    if entry.creator != request.user:
        raise PermissionDenied

    for pic in entry.pictures.all():
        pic.image.delete()
        pic.thumbnail.delete()
    entry.delete()
    request.user.profile.update(
        coins=request.user.profile.coins - ucs.ACTIONS_COINS['diary']['daily'])
    update_rewards(request.user, 'diary')
    process_mojo_action_down(request.user, 'diary_entry')
    url = reverse('diary.list_all', args=[request.user.username])
    if request.is_ajax():
        return JSONResponse({'is_valid': True, 'success': ENTRY_DELETED,
                             'url': url})
    return HttpResponseRedirect(url)
Beispiel #2
0
def delete_comment(request, comment_id):
    """Deletes a comment from a diary.

    Only deletes the comment if the logged in user is the creator of the
    comment or of the diary.

    """
    comment = get_object_or_404(Comment, pk=comment_id)
    entry = comment.diary
    comment_creator = comment.creator
    if comment.creator != request.user and entry.creator != request.user:
        raise PermissionDenied
    comment.delete()
    process_mojo_action_down(comment_creator, 'diary_comment')
    # Does comment_creator have a comment in the diary entry?
    # If not, stop notifying them.
    if not entry.comments.filter(creator=comment_creator).exists():
        NewCommentEvent.stop_notifying(comment_creator, entry)
    return HttpResponseRedirect(reverse(
        'diary.single', kwargs=get_kwargs_for_diary_id(entry.pk)))
Beispiel #3
0
def delete(request, lets_id):
    """Delete a Lets object, only if logged in user is the creator."""

    lets = get_object_or_404(Lets, pk=lets_id)
    if lets.creator != request.user:
        raise PermissionDenied

    lets.delete()

    # Coins
    profile = request.user.profile
    user_key = Lets.u_cache_key(request.user)
    lets_key = cache.get(user_key)
    if lets_key:
        if lets_key > 0:
            # No 250 -
            cache.decr(user_key)

        if lets_key <= 0:
            # Yes 250 -
            profile.update(coins=profile.coins -
                           ucs.ACTIONS_COINS['lets']['daily'])
            cache.delete(user_key)
    else:
        # yes 250 -
        profile.update(coins=profile.coins -
                       ucs.ACTIONS_COINS['lets']['daily'])
    update_progress(profile, action='lets')
    update_rewards(request.user, 'lets')
    process_mojo_action_down(request.user, 'lets')

    # TODO: return progress_data with ajax request. Modify js on lets side to
    #   update profile completion widget
    next_url = reverse('lets.wall', args=[request.user.username])
    if request.is_ajax():
        return JSONResponse({'is_valid': True,
                             'msg': 'Deleted'})
    return HttpResponseRedirect(next_url)