コード例 #1
0
ファイル: views.py プロジェクト: prathyush/reddit-music
def index(request):
    subreddits = []
    subreddit = request.GET.get("s", "progmetal")
    limit = request.GET.get("l", "200")
    subreddits.append(subreddit)
    playlist = getvideos(subreddits, int(limit))
    template = loader.get_template("vidlist/index.html")
    context = RequestContext(request, {"playlist": playlist})
    return HttpResponse(template.render(context))
コード例 #2
0
ファイル: views.py プロジェクト: prathyush/reddit-music
def player(request):
    subreddits = []
    response_dict = {}
    if not request.POST:
        subreddit = request.GET.get("s")
        template = loader.get_template("vidlist/player.html")
        if subreddit is not None:
            # Some one is messing around.
            print "Really? subreddit: " + subreddit
            limit = request.GET.get("l", "20")
            subreddits.append(subreddit)
            playlist = getvideos(subreddits, int(limit))
            # Convert into JSON.
            for song in playlist:
                response_dict[song.videoid] = {"title": song.title, "source": song.source, "url": song.url}
            response_json = simplejson.dumps(response_dict)
            context = RequestContext(
                request,
                {
                    "playlist_json": response_json,
                    "subreddit": subreddit,
                    "playlist": playlist,
                    "subreddits": ["/r/Jazz", "/r/ProgMetal"],
                },
            )
        else:
            print "Usual Execution"
            context = RequestContext(request, {"subreddits": getSubreddits()})
        return HttpResponse(template.render(context))

    subreddit = request.POST["subreddit"].split("/")[2]
    limit = request.POST["limit"]
    subreddits.append(subreddit)
    playlist = getvideos(subreddits, int(limit))
    if playlist is None:
        errors = {}
        errors["error"] = "Fetch Failed"
        return HttpResponse(simplejson.dumps(errors))
    template = loader.get_template("vidlist/playlist.html")
    context = RequestContext(request, {"playlist": playlist, "subreddit": subreddit})
    # 	return TemplateResponse(request, template, {'songs' : playlist})
    return HttpResponse(template.render(context))
コード例 #3
0
def index(request):
	subreddits = []
	subreddit = request.GET.get('s','progmetal')
	limit = request.GET.get('l', '200')
	subreddits.append(subreddit)
	playlist = getvideos(subreddits, int(limit))
	template = loader.get_template('vidlist/index.html')
	context = RequestContext(request, {
		'playlist': playlist,
	})
	return HttpResponse(template.render(context))
コード例 #4
0
def player(request):
	subreddits = []
	response_dict = {}
	if not request.POST:
		subreddit = request.GET.get('s')
		template = loader.get_template('vidlist/player.html')
		if subreddit is not None:
			#Some one is messing around.
			print "Really? subreddit: "+subreddit
			limit = request.GET.get('l', '20')
			subreddits.append(subreddit)
			playlist = getvideos(subreddits, int(limit))
			#Convert into JSON. 
			for song in playlist:
				response_dict[song.videoid] = {'title' : song.title, 'source' : song.source, 'url' : song.url}
			response_json = simplejson.dumps(response_dict)
			context = RequestContext(request, {
				'playlist_json': response_json,
				'subreddit': subreddit,
				'playlist': playlist,
				'subreddits': ['/r/Jazz', '/r/ProgMetal'],
			})
		else:
			print "Usual Execution"
			context= RequestContext(request, {'subreddits': getSubreddits()})
		return HttpResponse(template.render(context))

	subreddit = request.POST['subreddit'].split('/')[2]
	limit = request.POST['limit']
	subreddits.append(subreddit)
	playlist = getvideos(subreddits, int(limit))
	if (playlist is None):
		errors = {}
		errors['error'] = 'Fetch Failed'
		return HttpResponse(simplejson.dumps(errors));
	template = loader.get_template('vidlist/playlist.html')
	context = RequestContext(request, {'playlist' : playlist, 'subreddit' : subreddit})
#	return TemplateResponse(request, template, {'songs' : playlist})
	return HttpResponse(template.render(context))