Skip to content

Commit

Permalink
Remove UserArtists
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkay committed Oct 11, 2011
1 parent 9e5407d commit 3ec7885
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def add(cls, user, artist):
except IntegrityError:
pass

@classmethod
def remove(cls, user, mbids):
with transaction.commit_on_success():
for mbid in mbids:
q = cls.objects.filter(user__id=user.id)
q = q.filter(artist__mbid=mbid)
q.delete()

class UserProfile(models.Model):

code_length = 16
Expand Down
17 changes: 17 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ def artists_add(request):
messages.success(request, "%s has been added!" % artist.name)
return redirect('/artists')

@login_required
def artists_remove(request):
names = request.POST.getlist('name')
mbids = request.POST.getlist('id')
if not names and not mbids:
messages.info(request, 'Use checkboxes to select the artists you want to remove.')
return redirect('/artists')

if names:
UserSearch.remove(request.user, names)
messages.success(request, 'Removed %d pending artists.' % len(names))
return redirect('/artists')

UserArtist.remove(request.user, mbids)
messages.success(request, 'Removed %d artist%s.' % (len(mbids), 's' if len(mbids) > 1 else ''))
return redirect('/artists')

def blog(request):
posts = get_posts()
root = request.build_absolute_uri('/')
Expand Down
8 changes: 4 additions & 4 deletions templates/artists.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,27 @@ <h2>Artists you are following:</h2>

$("#name-all").click(function() {
var checked_status = this.checked;
$("input[@name=name]").each(function() {
$("input[name=name]").each(function() {
this.checked = checked_status;
});
});

$("#id-all").click(function() {
var checked_status = this.checked;
$("input[@name=id]").each(function() {
$("input[name=id]").each(function() {
this.checked = checked_status;
});
});

$("#form-pending").submit(function() {
var checked = $("input[@name=name]:checked").length;
var checked = $("input[name=name]:checked").length;
if(checked < 2) return true;
return confirm("Are you sure you want to remove " +
checked.toString() + " artists?");
});

$("#form-artists").submit(function() {
var checked = $("input[@name=id]:checked").length;
var checked = $("input[name=id]:checked").length;
if(checked < 2) return true;
return confirm("Are you sure you want to remove " +
checked.toString() + " artists?");
Expand Down
2 changes: 1 addition & 1 deletion urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
(r'^artist/([0-9a-f\-]+)$', 'artist'),
(r'^artists$', 'artists'),
(r'^artists-add$', 'artists_add'),
# (r'^artists-remove$', 'artists_remove'),
(r'^artists-remove$', 'artists_remove'),
(r'^blog$', 'blog'),
(r'^blog/feed$', 'blog_feed'),
# (r'^calendar$', 'calendar'),
Expand Down

0 comments on commit 3ec7885

Please sign in to comment.