Exemplo n.º 1
0
	def submit_note(self, note_id, **params):
		note = db.Note.objects.with_id(note_id)
		groups_ans = []
		tcount = 0
		allow_total = 0
		for gidx, group in enumerate(note.question_groups):
			if ('pn-%i' % (gidx + 1)) in params:
				answers = []
				if group.qtype.key!='yes-no': allow_total += 1
				for qidx, question in enumerate(group.questions):
					key = 'pn-%iq%i' % (gidx+1, qidx+1)
					if key in params:
						if group.qtype.key=='yes-no':
							tcount += 1
						answers.append((question, params[key]))
					elif group.qtype.key=='yes-no':
						answers.append((question, False))
				groups_ans.append({'name': group.header, 'type': group.qtype.key, 'answers': answers, 'count': tcount})
		note_content = env.get_template('publish.tpl.html').render(answers=groups_ans, note=note, total=tcount, allow_total=allow_total)
		if 'format' in params:
			if params['format']=='json':
				return json.dumps({'data':groups_ans,'html':note_content})
			elif params['format'] == 'html':
				return note_content
		else:
			if ('session_id' not in cherrypy.request.cookie.keys()):
				raise cherrypy.HTTPRedirect(FBApi.authorize_url())
			else:
				fbapi = FBApi(str(cherrypy.request.cookie['session_key'].value))
				db.Note.objects(id=note.id).update_one(inc__taken=1)
				out = json.loads(fbapi.publish_note(note.name, ' '.join(note_content.split())))
				if 'id' in out:
					raise cherrypy.HTTPRedirect('/done?note_id='+out['id'])
				else:
					return 'Something went wrong... Email the developers to get this fixed.'
Exemplo n.º 2
0
	def connect(self):
		raise cherrypy.HTTPRedirect(FBApi.authorize_url())