def show(request, show): show = get_object_or_404(Show, relative_url=show) isBroadcasting = False pubCode = None client = JtvClient(JTVKey, JTVSecret) login = show.jtv_login try: clips = client.get('/channel/clips/' + login + '.xml').read() except OAuthError: clips = "" # Parse xml clips and get embed codes p = SimpleParserMultiple() try: p.feed(clips, 'embed_code') except(AttributeError): pass if p.data: episodes = p.data else: episodes = [] if request.user.is_authenticated(): curr = currentTimeSlot() if curr and (curr.last_week_winner == show) and (request.user == show.owner): isBroadcasting = True token = OAuthToken(show.jtv_token, show.jtv_secret) try: pubCode = client.get('/channel/publisher_embed.html', token).read() except OAuthError: pass return render_to_response('demTV/show.html', { 'baseUser': getAuthUser(request), 'show': show, 'episodes': episodes, 'request': request, 'minutes': getMinutes(), 'seconds': getSeconds(), 'isBroadcasting': isBroadcasting, 'pubCode': pubCode, })
def live(request): timeslot = currentTimeSlot() embedCode = None if timeslot is not None: show = timeslot.last_week_winner client = JtvClient(JTVKey, JTVSecret) try: embedCode = client.get('/channel/embed/' + show.jtv_login + '?consumer_key=' + JTVKey + '&auto_play=true').read() except OAuthError: embedCode = None return render_to_response('demTV/live.html', { 'baseUser': getAuthUser(request), 'tabSelected': 'live', 'timeslot': timeslot, 'minutes': getMinutes(), 'seconds': getSeconds(), 'embedCode': embedCode, })
def editShows(request, username): if request.user.username != username: return render_to_response('demTV/error.html', { 'baseUser': getAuthUser(request), 'error': "You can't edit other people's shows.", }) ShowFormSet = inlineformset_factory(User, Show, formset=BaseShowFormSet, extra=1, fields=('name', 'description', 'time_slot')) try: user = User.objects.get(username=username) except(User.DoesNotExist): return render_to_response('demTV/error.html', { 'baseUser': getAuthUser(request), 'error': 'There is no such user.', }) result = None if request.method == 'POST': formset = ShowFormSet(request.POST, request.FILES, instance=user) if formset.is_valid(): forms = formset.save(commit=False) for form in forms: # Check if new show if not form.votes: form.votes = 0 # Create jtv channel/login login = "******" + randomString() password = randomString() form.jtv_login = login form.jtv_password = password client = JtvClient(JTVKey, JTVSecret) try: channel = client.post('/channel/create.xml', { 'login': login, 'password': password, 'birthday': '1980-01-01', 'email': DEFAULT_JUSTINTV_EMAIL, 'category': 'None', 'title': form.name.lower(), }).read() except OAuthError: channel = "" # Process returned channel credentials here # Parse xml clips into episodes p = SimpleParserDict() try: p.feed(channel, ['access_token', 'access_token_secret']) except(AttributeError): pass if 'access_token' in p.data and 'access_token_secret' in p.data: form.jtv_token = p.data['access_token'] form.jtv_secret = p.data['access_token_secret'] else: result = "There was an error creating the new show. Please try again and make sure that the name is appropriate." # Else if old show, check if timeslot changed. If so, reset votes else: show = Show.objects.get(pk=form.pk) if form.time_slot != show.time_slot: form.votes = 0 Vote.objects.filter(show=show).delete() if not result: form.owner = user url = form.name.lower().replace(" ", "_") form.relative_url = url form.save() if not result: result = "Shows updated successfully" # Reset formset to display new one to user formset = ShowFormSet(instance=user) else: formset = ShowFormSet(instance=user) return render_to_response('demTV/manageShow.html', { 'baseUser': getAuthUser(request), 'formset': formset, 'result_message': result, })