예제 #1
0
파일: dj.py 프로젝트: pwhelan/djshouts
def facebook_setup(request):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')
	
	facebook_profile = request.user.get_or_create(user = u).get_facebook_profile()
	
	dj = DJ()
	dj.user_id = request.user.id
	dj.picture = download("http://graph.facebook.com/" + facebook_profile.username + "/picture?type=large")
예제 #2
0
파일: dj.py 프로젝트: pwhelan/djshouts
def edit(request):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/')
	
	f_user = FacebookUser.objects.get(contrib_user=request.user.id)
	facebook_profile = None
	
	try:
		dj = DJ.objects.get(user_id=request.user.id)
	except ObjectDoesNotExist:
		dj = DJ()
		dj.user_id = request.user.id
	
	try:
		oauths = OAuth2Access.objects.filter(user_id=request.user.id, token_type = TOKEN_ACCESS).all()
		services = {}
		for oauth in oauths:
			services[oauth.service] = True
			fb_profile = urllib.urlopen('https://graph.facebook.com/me?access_token=%s' % oauth.token)
			facebook_profile = json.load(fb_profile)
	except ObjectDoesNotExist:
		services = {}
	
	
	if request.method == 'POST':
		form = EditDJForm(request.POST, request.FILES, instance = dj)
		form.save()
				
		return HttpResponseRedirect('/shows/')
	
	upload_url, upload_data = prepare_upload(request, '/dj/me')
	
	if dj.picture:
		blob_info = dj.picture.file.blobstore_info
		data = blobstore.fetch_data(blob_info.key(), 0, 50000) 
		image = images.Image(image_data=data)
	else:
		image = None
	
	try:
		connections = FacebookConnection.objects.filter(user_id=request.user.id).all()
	except ObjectDoesNotExist, e:
		connections = None