Example #1
0
def delete_link(request, artist, album, link, template='tehorng/delete_confirm.html'):
    """
    A view for "deleting" a link from the website. Deleting marks objects is_deleted to True and excludes it from the site.
    """
    artist = Artist.objects.get(slug__iexact=artist)
    album = Album.objects.get(slug__iexact=album, artist=artist)
    link = Link.objects.get(id__iexact=link, album=album)
    
    user = request.user

    if not (user.is_superuser or user.is_staff or user == link.uploader):
        return HttpResponseRedirect(reverse('album-detail', args=[artist.slug, album.slug]))

    if request.method == 'POST' and 'yes' in request.POST:
        link.is_deleted = True
        link.save()
        delete_object.send(sender=inspect.stack()[0][3], instance=link, action="Delete")
        messages.success(request, "\"%s\" deleted." % link)
        return HttpResponseRedirect(reverse('album-detail', args=[artist.slug, album.slug]))
    elif request.method == 'POST' and 'no' in request.POST:
        messages.success(request, "Delete cancelled.")
        return HttpResponseRedirect(reverse('album-detail', args=[artist.slug, album.slug]))

    return render_to_response(template, {
        'artist': artist,
        'album': album,
        'link': link,
    }, context_instance=RequestContext(request))
Example #2
0
def delete_artist(request, artist, template="tehorng/delete_confirm.html"):
    """
    View for "deleteing" an artist on the website. Deleting marks objects is_deleted to True and excludes it from the site.
    """
    artist = Artist.objects.get(slug__iexact=artist)
    
    user = request.user

    if not (user.is_superuser or user.is_staff or user == artist.uploader):
        messages.warning(request, "You don't have permission to do that.")
        return HttpResponseRedirect(reverse('artist-detail', args=[artist.slug]))

    if request.method == 'POST' and 'yes' in request.POST:        
        artist.is_deleted = True 
        artist.save()
        delete_object.send(sender=inspect.stack()[0][3], instance=artist, action="Delete")
        messages.success(request, "\"%s\" deleted." % (artist.name,))
        return HttpResponseRedirect(reverse('artist-index'))
    elif request.method == 'POST' and 'no' in request.POST: 
        messages.success(request, "Delete cancelled.")
        return HttpResponseRedirect(reverse('artist-detail', args=[artist.slug]))
    return render_to_response(template, {'artist': artist}, context_instance=RequestContext(request))