def artist_list(request): user = request.user.myuser if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>" ) artists = Artist.objects.all() query = request.GET.get("q") if query: artists = artists.filter( Q(name__icontains=query) ) artists = artists.distinct() datas = cache.get(user.key("like")) if not datas: datas = map( lambda x: { "artist": x, "status": (True if Like.objects.filter(user=user, artist=x) else False), }, artists) cache.set(user.key("like"), list(datas), 5 * 60) context = { "datas": datas, } return render (request, "artists/artist_list.html", context)
def user_list(request): user = request.user.myuser if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") users = MyUser.objects.all() now = datetime.date.today() start = now - datetime.timedelta(days=3) datas = cache.get(user.key("list")) if not datas: datas = map( lambda x: { "user": x, "num": (lambda y: len(y) if y else 0)(x.playlist.all()), "new": (lambda y: len(y) if y else 0) (x.playlist.filter(year_released__gt=start)), "status": (True if Follow.objects.filter(fan=user, star=x) else False), }, users) cache.set(user.key("list"), list(datas), 5 * 60) context = { "datas": datas, } return render(request, "core/user_list.html", context)
def song_list(request): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") f = SongFilter(request.GET, queryset=Song.objects.all()) context = { "filter": f, } return render(request, "songs/song_list.html", context)
def follow_list(request): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") user = request.user.myuser follow = Follow.objects.filter(fan=user) stars = [f.star for f in follow] context = { "stars": stars, } return render(request, "core/follow_list.html", context)
def like_list(request): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") user = request.user.myuser likes = Like.objects.filter(user=user) artists = [l.artist for l in likes] context = { "artists": artists, } return render(request, "core/like_list.html", context)
def play_history(request): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") user = request.user.myuser play = Play.objects.filter(user=user) song = [p.song for p in play] timestamp = [p.timestamp for p in play] context = { "song": song, "timestamp": timestamp, } return render(request, "core/play_history.html", context)
def album_detail(request, id): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>" ) album = get_object_or_404(Album, pk=id) context = { "album": album, "songs": album.track.all(), } return render(request, "albums/album_detail.html", context)
def playlist_list(request, uid): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") if uid == '0': playlists = Playlist.objects.all() creator = None else: playlists = Playlist.objects.filter(creator_id=uid) creator = MyUser.objects.get(pk=uid) f = PlaylistFilter(request.GET, queryset=playlists) context = { "playlists": playlists, "creator": creator, "filter": f, } return render(request, "playlists/playlist_list.html", context)
def user_detail(request, id): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") user = get_object_or_404(MyUser, pk=id) loginuser = request.user state = 'unfollow' if Follow.objects.filter(star=user, fan=loginuser.myuser): state = 'follow' if loginuser.pk == user.user.pk: editable = True else: editable = False context = { "user": user, "editable": editable, "state": state, } return render(request, "core/user_detail.html", context)
def artist_detail(request, id): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>" ) artist = get_object_or_404(Artist, pk=id) user = request.user state = 'unlike' if Like.objects.filter(user=user.myuser, artist=artist): state = 'like' songs = artist.song.all() context = { "state": state, "artist": artist, "songs": songs, } # return HttpResponse("Here are the artists") return render (request, "artists/artist_detail.html", context)
def song_detail(request, id): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") song = get_object_or_404(Song, pk=id) try: rate = Rate.objects.get(user=request.user.myuser, song=song) scores = [False for i in range(5)] scores[rate.score - 1] = True except Rate.DoesNotExist: scores = [False for i in range(5)] scores[0] = True context = { "song": song, "scores": scores, } # return HttpResponse("song details!") return render(request, "songs/song_detail.html", context)
def playlist_detail(request, id): if anti_spider(request): return response.HttpResponseNotFound( content="<h1>Not Found</h1><p>The requested URL " + request.path_info + " was not found on this server.</p>") try: playlist = Playlist.objects.get(pk=id) except Playlist.DoesNotExist: raise Http404 user = request.user.myuser creator = playlist.creator if creator.pk == user.pk: editable = True else: editable = False context = { "playlist": playlist, "songs": playlist.song.all(), "editable": editable, } return render(request, "playlists/playlist_detail.html", context)