Example #1
0
def index():
	# print get_home()
	try:
		tst=pgsql_fb.data_pgsql_fb(db_url,session)
	except:
		print 'got exception'
	fb=pgsql_fb.data_fb(session)
	tokens=fb.login()
	#print tokens
	channel_url = url_for('get_channel', _external=True)
	channel_url = channel_url.replace('http:', '').replace('https:', '')

	me = fb.me(strict=False)
	fb_app = fb.get_fb_app()
	
	redir = get_home() + 'close/'
	url = request.url
	  	
	categories=fb.get_categories()
	
	suggestions=fb.fb.call('app/objects/'+FBNS+':suggestion',args={'access_token': fb.fb.app_access_token,'fields':'id,created_time,data'})#,pos_votes,neg_votes,category_id'})
	sort=request.args.get('sort','votes')
	if suggestions.has_key('data'):
	  	suggestions=suggestions['data']
	  	for i in range(0,len(suggestions)):
	  		if not suggestions[i].has_key('data'):
	  		  del suggestions[i]
	  	if sort=='date':
	  		suggestions.sort(key=lambda k: k['created_time'])
	  		suggestions.reverse()
	  	elif sort=='votes':
	  		suggestions.sort(key=lambda k: k['data']['pos_votes']+k['data']['neg_votes'])
	  #	suggestions=l_obj
	disp_suggestions=[]
	for i in range(0,min(10,len(suggestions))):
	  disp_sug=fb.get_suggestion(suggestions[i]['id'])
	  disp_suggestions+=[disp_sug]
	content=''#+str(disp_suggestions)+str(request.args)#+' '+str(request.form)+str(request.cookies)
	
	return render_template(
	      'index.html', app_id=FB_APP_ID, app=fb_app,
	      me=me, url=url,
	      channel_url=channel_url, name=FB_APP_NAME+' '+FBNS+'  2',suggestions=disp_suggestions ,content=content,permission_list=permission_list)
Example #2
0
def suggestion_new():
	fb=pgsql_fb.data_fb(session)
	if request.method=="GET":
	  tokens=fb.login()
	  if not tokens:
	  	return "Error please try again"
	  me = fb.me()
	  return render_template('suggestion_new.html',me=me)
	elif request.method=="POST":
		tokens=fb.login()
		if not tokens:
			return "Error please try again"
		me = fb.me()
		channel_url = url_for('get_channel', _external=True)
		channel_url = channel_url.replace('http:', '').replace('https:', '') 
		content=request.form['content']
		if (not request.form.has_key('category_id')) or request.form['category_id']=='' or request.form['category_id']==None:
			categories=fb.fb.call('app/objects/'+FBNS+':category',args={'access_token': tokens['app_access_token']})
			if len(categories['data'])==1:
				category_id=categories['data'][0]['id']
		else:
			category_id=request.form['category_id']
		perm=fb.fb.call('me/permissions',args={'access_token': tokens['user_access_token']})
		me=fb.me()
		# facebook object suggestion required fields ( og:title:'<the suggestion text>', creator_id:'<int:me.id>',pos_votes:<int>, neg_votes:<int>,closed:<bool>)
		if not type(me)==bool and me.has_key('id'):
		  fbc=fb.fb.call('app/objects/'+FBNS+':suggestion',args={'access_token': tokens['app_access_token'],'method':'POST', 'object': "{'title':'"+content+"','data':{'creator_id':'"+str(me['id'])+"','pos_votes':'0','neg_votes':'0','category_id':'"+category_id+"','closed':'False'}}" })
		else:
			fbc={}
		#facebook object user_suggestion required fields ( og:title:'<empty string>', suggestion_id:<int> )
		if fbc.has_key('id'):
		  fbc1=fb.fb.call('me/objects/'+FBNS+':user_suggestion',args={'access_token': tokens['user_access_token'],'method':'POST', 'object': "{'title':'','data':{'suggestion_id':'"+fbc['id']+"'}}" })
		  
		  pg=pgsql_fb.data_pgsql(db_url)
		  pg0=pg.new_suggestion(suggestion_id=fbc['id'],creator_id=me['id'],category_id=category_id)
		  
		else:
			fbc1='error saving'
			pg0="fbc_err"
		dbg="save suggestion: <br>"+content+"<br>"+str(fbc)+"<br>"+str(fbc1)+'\n pg:'+str(pg0)+' <br>user: '******'<br>perms:<br>'+str(perm)+'<br><br>'+str(request.form)
		return render_template('suggestion_saved.html',me=me,dbg=dbg,content='')
Example #3
0
def suggestion_show(suggestion_id):
	fb=pgsql_fb.data_fb(session)
	tokens=fb.login()
	me = fb.me(strict=False)
	suggestion=fb.get_suggestion(suggestion_id)
	return render_template('suggestion_show.html',me=me,content=str(suggestion)+str(request.form),suggestion_url=get_home()+'suggestion/'+str(suggestion_id),permission_list=permission_list)