Exemple #1
0
def xml_edit(request):
    if not request.user.is_authenticated():
        return xml_error('user not logged in')
    form = request.POST
    try: song = Song.objects.get(pk=int(form.get('id','')))
    except (ValueError, TypeError, Song.DoesNotExist), err:
        return xml_error(str(err))
Exemple #2
0
def xml_edit(request):
    if not request.user.is_authenticated():
        return xml_error('user not logged in')
    form = request.POST
    try:
        song = Song.objects.get(pk=int(form.get('id', '')))
    except (ValueError, TypeError, Song.DoesNotExist), err:
        return xml_error(str(err))
Exemple #3
0
def xml_control(request):
    form = request.POST
    action = form.get('action','')
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        if action == 'play': ctrl.unpause()
        elif action == 'pause': ctrl.pause()
        elif action == 'skip': ctrl.skip()
        elif action == 'shuffle': ctrl.shuffle()
        else: return xml_error('invalid action: ' + action)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Exemple #4
0
def xml_control(request):
    form = request.POST
    action = form.get('action', '')
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        if action == 'play': ctrl.unpause()
        elif action == 'pause': ctrl.pause()
        elif action == 'skip': ctrl.skip()
        elif action == 'shuffle': ctrl.shuffle()
        else: return xml_error('invalid action: ' + action)
    except ControlError, err:
        return xml_error(str(err))
Exemple #5
0
def xml_dequeue(request):
    form = request.POST
    # Get the selected songs.
    playids = get_int_list(form, 'playids')
    # Dequeue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try: ctrl.remove_songs(playids)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Exemple #6
0
def xml_queue(request):
    form = request.POST
    # Get the selected songs.
    songs = get_song_list(form)
    # Queue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try: ctrl.add_songs(songs)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Exemple #7
0
def xml_dequeue(request):
    form = request.POST
    # Get the selected songs.
    playids = get_int_list(form, 'playids')
    # Dequeue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        ctrl.remove_songs(playids)
    except ControlError, err:
        return xml_error(str(err))
Exemple #8
0
def xml_queue(request):
    form = request.POST
    # Get the selected songs.
    songs = get_song_list(form)
    # Queue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        ctrl.add_songs(songs)
    except ControlError, err:
        return xml_error(str(err))
Exemple #9
0
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
Exemple #10
0
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))
Exemple #11
0
def permission_required_xml(perm):
    return permission_required(perm, '', lambda r,text,act: xml_error(text))