def dec_likes(request): success = False mimetype = 'application/json' # checking for band/user is_band, band_id = check_for_session(request) if request.is_ajax(): song_id = request.GET.get('song_id') try: song_obj = Song.objects.get(id=song_id) if is_band and band_id: band = Band.objects.get(id=band_id) # for now getting all objects and deleting it SongLike.objects.filter(band=band, song=song_obj).delete() else: # for now getting all objects and deleting it SongLike.objects.filter(user=request.user, song=song_obj).delete() song_obj.likes -= 1 song_obj.save() success = True except: pass return HttpResponse(json.dumps({'success': success, 'like_count': song_obj.likes}), mimetype)
def inc_likes(request): success = False mimetype = 'application/json' # checking for band/user is_band, band_id = check_for_session(request) if request.is_ajax(): song_id = request.GET.get('song_id') try: song_obj = Song.objects.get(id=song_id) # if band then creating Songlike object for band if is_band and band_id: band = Band.objects.get(id=band_id) SongLike.objects.create(band=band, song=song_obj) else: SongLike.objects.create(user=request.user, song=song_obj) song_obj.likes += 1 song_obj.save() success = True except: pass return HttpResponse(json.dumps({'success': success, 'like_count': song_obj.likes}), mimetype)
def inc_likes(request): success = False mimetype = 'application/json' # checking for band/user is_band, band_id = check_for_session(request) if request.is_ajax(): song_id = request.GET.get('song_id') try: song_obj = Song.objects.get(id=song_id) # if band then creating Songlike object for band if is_band and band_id: band = Band.objects.get(id=band_id) SongLike.objects.create(band=band, song=song_obj) else: SongLike.objects.create(user=request.user, song=song_obj) song_obj.likes += 1 song_obj.save() success = True except: pass return HttpResponse( json.dumps({ 'success': success, 'like_count': song_obj.likes }), mimetype)
def dec_likes(request): success = False mimetype = 'application/json' # checking for band/user is_band, band_id = check_for_session(request) if request.is_ajax(): song_id = request.GET.get('song_id') try: song_obj = Song.objects.get(id=song_id) if is_band and band_id: band = Band.objects.get(id=band_id) # for now getting all objects and deleting it SongLike.objects.filter(band=band, song=song_obj).delete() else: # for now getting all objects and deleting it SongLike.objects.filter(user=request.user, song=song_obj).delete() song_obj.likes -= 1 song_obj.save() success = True except: pass return HttpResponse( json.dumps({ 'success': success, 'like_count': song_obj.likes }), mimetype)
def base_view(request): """ :param request: :return: """ template = 'pages/home.html' user = request.user song_like_dict = {} success = False # for now getting all songs songs = Song.objects.all() # checking for the session is_band, band_id = check_for_session(request) for song in songs: try: # if object exists then success is True if is_band and band_id: band = Band.objects.get(id=band_id) SongLike.objects.get(band=band, song=song) else: SongLike.objects.get(user__id=user.id, song=song) success = True except SongLike.DoesNotExist: success = False song_like_dict.update({ song.id: { 'success': success, 'name': song.name, 'url': song.upload.url, 'count': song.likes } }) return render_to_response(template, { 'songs': songs, 'song_like_dict': song_like_dict }, context_instance=RequestContext(request))
def base_view(request): """ :param request: :return: """ template = 'pages/home.html' user = request.user song_like_dict = {} success = False # for now getting all songs songs = Song.objects.all() # checking for the session is_band, band_id = check_for_session(request) for song in songs: try: # if object exists then success is True if is_band and band_id: band = Band.objects.get(id=band_id) SongLike.objects.get(band=band, song=song) else: SongLike.objects.get(user__id=user.id, song=song) success = True except SongLike.DoesNotExist: success = False song_like_dict.update({song.id: {'success': success, 'name': song.name, 'url': song.upload.url, 'count': song.likes } }) return render_to_response(template, {'songs': songs, 'song_like_dict': song_like_dict}, context_instance=RequestContext(request))