2012-08-17 20:41:55 -07:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2012-08-18 09:27:56 -07:00
|
|
|
from django.http import HttpResponse
|
2012-08-17 20:41:55 -07:00
|
|
|
from django.shortcuts import redirect, render_to_response
|
2012-08-17 22:24:21 -07:00
|
|
|
from django.template import RequestContext
|
2012-08-17 20:26:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
2012-08-17 20:41:55 -07:00
|
|
|
'''Index page. Everyone starts here. If the user is logged in (that is, they
|
2012-08-17 20:44:27 -07:00
|
|
|
have a session id) return the follower_graph view. Otherwise, render the
|
|
|
|
index page.'''
|
2012-08-18 09:27:56 -07:00
|
|
|
if request.user.is_authenticated():
|
2012-08-18 16:02:31 -07:00
|
|
|
return redirect('graph_followers')
|
2012-08-17 20:49:57 -07:00
|
|
|
# Set a test cookie. When the user clicks the 'Login' button, test and make
|
|
|
|
# sure this cookie was set properly.
|
|
|
|
request.session.set_test_cookie()
|
2012-08-18 09:17:04 -07:00
|
|
|
return render_to_response('index.html', RequestContext(request))
|
2012-08-17 20:41:55 -07:00
|
|
|
|
|
|
|
|
2012-08-17 20:44:27 -07:00
|
|
|
def login(request):
|
|
|
|
'''Do a quick check to make sure cookies are enabled. If so, redirect to
|
|
|
|
GitHub so the user can login.'''
|
2012-08-17 20:49:57 -07:00
|
|
|
# Make sure the user can accept cookies.
|
2012-08-17 20:41:55 -07:00
|
|
|
if request.session.test_cookie_worked():
|
|
|
|
request.session.delete_test_cookie()
|
2012-08-18 18:27:56 -07:00
|
|
|
return redirect('socialauth_begin', backend='github')
|
2012-08-17 20:41:55 -07:00
|
|
|
else:
|
2012-08-18 12:41:03 -07:00
|
|
|
# During development, I've landed here a lot, despite having cookies
|
|
|
|
# enabled. So, set the test cookie so that trying to login from here
|
|
|
|
# actually works.
|
|
|
|
request.session.set_test_cookie()
|
2012-08-17 22:24:21 -07:00
|
|
|
# Render an error -- fix your damn cookies!
|
2012-08-18 09:17:04 -07:00
|
|
|
return render_to_response('index.html',
|
2012-08-17 22:24:21 -07:00
|
|
|
{ 'error': "Fix your damn cookies!" })
|
2012-08-17 20:41:55 -07:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2012-08-18 09:52:40 -07:00
|
|
|
def graph_followers(request):
|
2012-08-18 16:02:31 -07:00
|
|
|
return render_to_response('graph_followers.html', {
|
|
|
|
'repos': request.github.get_iter('users/%s/repos' % request.user.username)
|
|
|
|
}, RequestContext(request))
|
2012-08-18 11:21:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
2012-08-18 16:02:31 -07:00
|
|
|
def graph_repo(request, user=None, repo=None):
|
2012-08-18 11:47:13 -07:00
|
|
|
return render_to_response('graph_repo.html', {
|
2012-08-18 16:02:31 -07:00
|
|
|
'graph_user': user,
|
|
|
|
'graph_repo': repo,
|
|
|
|
'repos': request.github.get_iter('users/%s/repos' % request.user.username)
|
|
|
|
}, RequestContext(request))
|