示例#1
0
def editSong(request):
    if request.method == 'POST':
        form = newSong(request.POST)

        if form.is_valid():
            song_id = form.cleaned_data['song_id']
            name = form.cleaned_data['name'].rstrip().lstrip()
            album = form.cleaned_data['album'].rstrip().lstrip()
            artist = form.cleaned_data['artist'].rstrip().lstrip()
            content = form.cleaned_data['content']

            user = request.user.get_profile()
            if song_id != None:
                toAdd = Song.objects.get(id=song_id)
                author = toAdd.author
                createdDate = toAdd.timeCreated
            else:
                author = user
                createdDate = todaysDate()

            # change authorship for the song
            if song_id == None  \
                or 'w' not in toAdd. permission:

                toAdd = Song(name=name,
                             artist=artist,
                             album=album,
                             content=content,
                             author=author,
                             lastEdit=user,
                             timeLastEdit=todaysDate(),
                             timeCreated=createdDate)
            else:
                toAdd.name = name
                toAdd.album = album
                toAdd.artist = artist
                toAdd.content = contentToHTML(content)
                toAdd.lastEdit = user
                toAdd.timeLastEdit = todaysDate()

            toAdd.save()
            user.songs.add(toAdd)

            return HttpResponseRedirect('/viewSong?song=%s' % toAdd.id)
    elif request.GET.has_key('song'):
        try:
            form = newSong(fillForm(request.GET['song']))
            song_id = request.GET['song']
        except ObjectDoesNotExist:
            raise Http404
    else:
        song_id = 0
        form = newSong()

    return render_to_response('editSong.html', {
        'form': form,
        'song_id': song_id,
        'searchForm': searchForm()
    },
                              context_instance=RequestContext(request))
示例#2
0
def enqueue_song(request):
    if not is_party_assigned(request):
        return redirect('webpage:index')

    song = Song(service_id=request.POST.get('songid'),
                name=request.POST.get('songname'))
    song.save()
    user = get_user(request)
    user.party.songs.add(song)
    user.save()

    return HttpResponse(status=204)
示例#3
0
def addSong(artist, song, content):
    me = User.objects.get(username='******')
    date = "10/10/10"

    toAdd = Song(name=song,
                 artist=artist,
                 album='',
                 content='<br>'.join(content),
                 author=me.get_profile(),
                 lastEdit=me.get_profile(),
                 timeLastEdit=date,
                 timeCreated=date)

    toAdd.save()

    me.songs.add(toAdd)