Skip to content

Commit

Permalink
Filter releases by user when authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkay committed Oct 14, 2011
1 parent 3fcdc41 commit 3ae58f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions app/models.py
Expand Up @@ -128,6 +128,13 @@ class Meta:
artist = models.ForeignKey(Artist)
date = models.DateTimeField(auto_now_add=True)

@classmethod
def get(cls, user, artist):
try:
return cls.objects.get(user=user, artist=artist)
except cls.DoesNotExist:
return None

@classmethod
def add(cls, user, artist):
user_artist = cls(user=user, artist=artist)
Expand Down
10 changes: 5 additions & 5 deletions app/views.py
Expand Up @@ -57,15 +57,15 @@ def artist(request, mbid):

PER_PAGE = 10
offset = int(request.GET.get('offset', 0))
user_has_artist = False #TODO: (request.user.is_authenticated() and
# UserArtist.find(request.user, mbid))
user_has_artist = request.user.is_authenticated() and UserArtist.get(request.user, artist)
if user_has_artist:
show_stars = True
releases = UserRelease.get_releases(request.user, mbid,
PER_PAGE, offset)
release_groups = ReleaseGroup.get(
artist=artist, user=request.user, limit=PER_PAGE, offset=offset)
else:
show_stars = False
release_groups = ReleaseGroup.get(artist=artist, limit=PER_PAGE, offset=offset)
release_groups = ReleaseGroup.get(
artist=artist, limit=PER_PAGE, offset=offset)

offset = offset + PER_PAGE if len(release_groups) == PER_PAGE else None
return render(request, 'artist.html', {
Expand Down

0 comments on commit 3ae58f8

Please sign in to comment.