def xml_update(request): # TODO(rnk): This code is dead and untested. form = request.POST channel_id = get_integer(form, 'channel', 1) try: channel = Channel.objects.get(pk=channel_id) except Channel.DoesNotExist: return xml_error('invalid channel id: ' + repr(channel_id)) timestamp = get_integer(form, 'timestamp', None) if timestamp is None: return xml_error('invalid timestamp') elif timestamp >= channel.last_touched_timestamp(): # up-to-date timestamp try: snapshot = request.get_channel_snapshot(channel) if snapshot.status != "playing": return simple_xml_response('continue') elapsed_time = snapshot.time_elapsed total_time = snapshot.current_song.time return render_xml_to_response('aenclave/update.xml', {'elapsed_time':elapsed_time, 'total_time':total_time}) except ControlError, err: return xml_error(str(err)) else: return simple_xml_response('reload') # old timestamp
def xml_update(request): # TODO(rnk): This code is dead and untested. form = request.POST channel_id = get_integer(form, 'channel', 1) try: channel = Channel.objects.get(pk=channel_id) except Channel.DoesNotExist: return xml_error('invalid channel id: ' + repr(channel_id)) timestamp = get_integer(form, 'timestamp', None) if timestamp is None: return xml_error('invalid timestamp') elif timestamp >= channel.last_touched_timestamp(): # up-to-date timestamp try: snapshot = request.get_channel_snapshot(channel) if snapshot.status != "playing": return simple_xml_response('continue') elapsed_time = snapshot.time_elapsed total_time = snapshot.current_song.time return render_xml_to_response('aenclave/update.xml', { 'elapsed_time': elapsed_time, 'total_time': total_time }) except ControlError, err: return xml_error(str(err))
def delete_playlist(request): # Get the playlist to be deleted. form = request.POST try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid')) except Playlist.DoesNotExist: return html_error(request, 'That playlist does not exist.', 'Delete Playlist') # Make sure the user is allowed to delete the playlist. if not playlist.can_cede(request.user): return html_error(request, 'You may only delete your own playlists.', 'Delete Playlist') # Delete the playlist and redirect to the user's playlists page. playlist.delete() return HttpResponseRedirect(reverse('aenclave-user-playlist', args=[request.user.username]))
def remove_from_playlist(request): # Get the playlist to be removed from. form = request.POST try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid')) except Playlist.DoesNotExist: return html_error(request, 'That playlist does not exist.', 'Remove Songs') # Make sure the user is allowed to edit this playlist. if not playlist.can_edit(request.user): return html_error(request, 'You lack permission to edit this' ' playlist.', 'Remove Songs') # Remove the songs and redirect to the detail page for this playlist. songs = get_song_list(form) PlaylistEntry.objects.filter(song__in=songs).delete() return HttpResponseRedirect(playlist.get_absolute_url())
def add_to_playlist(request): # Get the playlist to be added to. form = request.POST try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid')) except Playlist.DoesNotExist: return html_error(request, 'That playlist does not exist.', 'Add Songs') # Make sure the user is allowed to edit this playlist. if not playlist.can_edit(request.user): return html_error(request, 'You lack permission to edit this' ' playlist.', 'Add Songs') # Add the songs and redirect to the detail page for this playlist. songs = get_song_list(form) playlist.append_songs(songs) return HttpResponseRedirect(playlist.get_absolute_url())
def delete_playlist(request): # Get the playlist to be deleted. form = request.POST try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid')) except Playlist.DoesNotExist: return html_error(request, 'That playlist does not exist.', 'Delete Playlist') # Make sure the user is allowed to delete the playlist. if not playlist.can_cede(request.user): return html_error(request, 'You may only delete your own playlists.', 'Delete Playlist') # Delete the playlist and redirect to the user's playlists page. playlist.delete() return HttpResponseRedirect( reverse('aenclave-user-playlist', args=[request.user.username]))
song.title = title audio['title'] = title # Update album. album = get_unicode(form, 'album') if album is not None: song.album = album audio['album'] = album # Update artist. artist = get_unicode(form, 'artist') if artist is not None: song.artist = artist audio['artist'] = artist # Update track number. if form.get('track', None) == '': song.track = 0 else: track = get_integer(form, 'track') if track is not None and 0 <= track < 999: song.track = track audio['tracknumber'] = unicode(track) # Save and report success. song.save() audio.save() return render_xml_to_response('done_editing.xml', {'song':song}) @permission_required_json('aenclave.change_song') def json_edit(request): if not request.user.is_authenticated(): return json_error('user not logged in') form = request.POST try: song = Song.objects.get(pk=int(form.get('id','')))
song.title = title audio['title'] = title # Update album. album = get_unicode(form, 'album') if album is not None: song.album = album audio['album'] = album # Update artist. artist = get_unicode(form, 'artist') if artist is not None: song.artist = artist audio['artist'] = artist # Update track number. if form.get('track', None) == '': song.track = 0 else: track = get_integer(form, 'track') if track is not None and 0 <= track < 999: song.track = track audio['tracknumber'] = unicode(track) # Save and report success. song.save() audio.save() return render_xml_to_response('done_editing.xml', {'song': song}) @permission_required_json('aenclave.change_song') def json_edit(request): if not request.user.is_authenticated(): return json_error('user not logged in') form = request.POST