예제 #1
0
def index(request):
    if not is_party_assigned(request):
        return redirect('webpage:index')

    if request.method == 'POST':
        search_query = request.POST.get('search_query')
        if search_query == '':
            return render(request, "webparty/index.html")

        encoded_query = urllib.parse.urlencode({'search_query': search_query})
        response = urllib.request.urlopen('https://www.youtube.com/results?' +
                                          encoded_query)
        page_src = response.read()
        response.close()
        parsed = BeautifulSoup(page_src)

        search_results = []
        div_results = parsed.body.find('div', attrs={'id': 'results'})
        songs_divs = div_results.find_all('div',
                                          attrs={'class': 'yt-lockup-content'})
        for div in songs_divs:
            link = div.find('a')
            search_results.append((link.get('href')[9:], link.text))

        context = {
            'search_query': search_query,
            'search_results': search_results,
            'user': get_user(request),
        }
        return render(request, "webparty/index.html", context)

    return render(request, "webparty/index.html", {'user': get_user(request)})
예제 #2
0
파일: views.py 프로젝트: przxmek/qparty
def leave(request):
    if not is_party_assigned(request):
        return redirect('webpage:index')

    user = get_user(request)
    user.party = None
    user.save()

    return redirect('webpage:index')
예제 #3
0
def downvote(request, song_id=-1):
    if not is_party_assigned(request):
        raise Http404

    user = get_user(request)
    song = user.party.songs.get(pk=song_id)
    user.downvote_song(song)

    return HttpResponse(json.dumps((song.pk, song.voting_result)),
                        content_type="application/json")
예제 #4
0
파일: views.py 프로젝트: przxmek/qparty
def player(request, template_name='webplayer/player.html'):
    if not is_party_assigned(request):
        raise Http404

    user = get_user(request)

    context = {
        'user': user,
    }

    return render(request, template_name, context)
예제 #5
0
파일: views.py 프로젝트: przxmek/qparty
def pop_song(request):
    if not request.is_ajax():
        raise Http404

    if not is_party_assigned(request):
        raise Http404

    user = get_user(request)
    user.party.songs.order_by('-voting_result', 'id')[0].delete()

    return HttpResponse(status=204)
예제 #6
0
파일: views.py 프로젝트: przxmek/qparty
def playlist(request, template_name='webplayer/playlist.html'):
    if not request.is_ajax():
        raise Http404

    if not is_party_assigned(request):
        raise Http404

    user = get_user(request)
    songs_list = user.party.songs.order_by('-voting_result', 'id')[:10]

    return render(request, template_name, {'songs_list': songs_list,
                                           'user': user})
예제 #7
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)
예제 #8
0
파일: views.py 프로젝트: przxmek/qparty
def next_song(request):
    if not request.is_ajax():
        raise Http404

    if not is_party_assigned(request):
        raise Http404

    user = get_user(request)
    next = user.party.songs.order_by('-voting_result', 'id')[0]
    next.voting_result = 20000
    next.save()

    return HttpResponse(json.dumps(next.service_id), content_type="application/json")
예제 #9
0
파일: views.py 프로젝트: przxmek/qparty
def index(request, template_name='webpage/index.html'):
    if is_party_assigned(request):
        return redirect('webparty:index')

    join_party_form = JoinPartyForm(request.POST or None)
    join_party_form.fields['admin_password'].widget = forms.HiddenInput()
    set_passwd_form = SetPasswordForm(request.POST or None)

    if join_party_form.is_valid():
        party_tag = join_party_form.cleaned_data['party_tag']

        try:
            party = Party.objects.get(tag=party_tag)
        except:
            party = None

        user = get_user(request)
        if not user:
            user = User(session=Session.objects.get(
                session_key=request.session.session_key),
                        party=party)
        else:
            user.party = party
        user.save()

        return redirect('webparty:index')

    if set_passwd_form.is_valid():
        party = Party()
        party.init_party()
        user = get_user(request)
        if not user:
            user = User(session=Session.objects.get(
                session_key=request.session.session_key),
                        party=party)
        else:
            user.party = party
        user.save()
        party.admins.add(user)
        party.password = set_passwd_form.cleaned_data['password']
        party.save()

        return redirect('player')

    context = {
        'join_form': join_party_form,
        'host_form': set_passwd_form,
    }

    return render(request, template_name, context)