Ejemplo n.º 1
0
Archivo: views.py Proyecto: jamslevy/PQ
 def get(self):
   logging.info('loading quiz item')
   template_values = {}
   if self.request.get('item_key'): this_quiz_item = QuizItem.get(self.request.get('item_key'))
   if self.request.get('token'): 
       from google.appengine.api import memcache
       self.session = memcache.get(self.request.get('token'))
       this_item = self.session.get('current_item', False)
       if this_item: this_quiz_item = QuizItem.get(this_item['key'])
       else: 
           logging.warning('token used past expiration', self.request.get('token'))
           return False
   quiz_item = {}
   try: quiz_item['topic_name'] = this_quiz_item.topic.name
   except: print this_quiz_item
   if this_quiz_item.content.endswith('.'): this_quiz_item.content = this_quiz_item.content[:-1] + "<br/>" # this should be done in advance,and it should replace </span>. with </span><br/>
   quiz_item['content'] = this_quiz_item.content
   quiz_item['answers'] = this_quiz_item.answers
   quiz_item['theme'] = this_quiz_item.theme
   template_values = quiz_item
   template_values['browser'] = self.get_browser()
   if self.request.get('demo') == 'true': path = tpl_path(QUIZDEMO_PATH + 'quiz_item.html')
   else: path = tpl_path(QUIZTAKER_PATH + 'quiz_item.html')
   if self.request.get("callback"):
           self.response.out.write(jsonp(self.request.get("callback"), template.render(path, template_values)))
   else:
           self.response.out.write(template.render(path, template_values))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: jamslevy/PQ
   def get(self):
	logging.info('Loading Quiz Completed Frame')
	template_values = {}
	path = tpl_path(QUIZDEMO_PATH + 'quiz_complete.html')
	if self.request.get("callback"):
			response = jsonp(self.request.get("callback"), template.render(path, template_values))
			self.response.out.write(response);
	else:
			self.response.out.write(template.render(path, template_values))
Ejemplo n.º 3
0
Archivo: views.py Proyecto: jamslevy/PQ
 def get(self):
         template_values = {}
         path = tpl_path(QUIZTAKER_PATH + 'quizframe.html')
         if self.request.get("callback"):
                 response = jsonp(self.request.get("callback"), template.render(path, template_values))
                 self.response.headers['Content-Type'] = 'application/x-javascript'
                 self.response.out.write(response);
         else:
                 self.response.out.write(template.render(path, template_values))
Ejemplo n.º 4
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
	logging.info('loading quiz intro')
	template_values = {}
	if self.request.get('subject'): template_values['proficiencies'] = self.get_quiz_subjects()
	    
	intro_template = QUIZTAKER_PATH + self.request.get('page') + ".html"
	if self.request.get('demo') == "true": intro_template = QUIZDEMO_PATH + self.request.get('page') + ".html" # only for demo
	path = tpl_path(intro_template)
	if self.request.get("callback"):
			response = jsonp(self.request.get("callback"), template.render(path, template_values))
			self.response.out.write(response);
	else:
			self.response.out.write(template.render(path, template_values))
Ejemplo n.º 5
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
	error_type = self.request.path.split('/error/')[1]   
	if error_type == "browser": return self.browser_error()
	template_values = {"error_type": error_type}
	logging.warning('loaded error page for error type %s',  error_type)
	path = tpl_path('utils/error.html')
	self.response.out.write(template.render(path, template_values))
Ejemplo n.º 6
0
 def load_quiz_js(self):
   JQUERY_VERSION = '1.3.2'
   DEFAULT_QUIZ_SUBJECT = "Recovery.Gov"
   try : 
       proficiency_arg = self.request.path.split('/quiz/')[1].replace('%20',' ')
       this_proficiency = Proficiency.get_by_key_name(proficiency_arg)
       assert this_proficiency != None
       self.these_proficiencies = [this_proficiency]
   except: self.these_proficiencies = [Proficiency.get_by_key_name(DEFAULT_QUIZ_SUBJECT)]
   proficiency_names = [str(p.name) for p in self.these_proficiencies] 
   session_token = self.get_session_token()
   
   template_values = {
   'proficiencies': encode(proficiency_names).replace("\n", ""), 
   'user_token': session_token, 
   'css': self.get_widget_css().replace('\n','').replace("'",'"'),
   'widget_html': self.get_widget_html(), 
   'widget_subject': self.these_proficiencies[0].key(),
   'jquery_version' : JQUERY_VERSION,
   'jquery_location': JQUERY_VERSION,
   'auto_start': self.get_auto_start() 
   }
    
   path = widget_path('pqwidget.js')
   from utils.random import minify
   self.response.out.write(  minify(template.render(path, template_values))  )
Ejemplo n.º 7
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
	merchant = self.merchant_info()
	# Create a (static) instance of Controller using your vendor ID and merchant key
	controller = Controller(merchant['id'], merchant['key'], is_sandbox=merchant['is_sandbox'])
	#Create your order:
	order = gmodel.checkout_shopping_cart_t(
		shopping_cart = gmodel.shopping_cart_t(items = [
			gmodel.item_t(merchant_item_id = 'oil_quiz',
						  name             = 'Oil Quiz',
						  description      = 'Oil quiz!',
						  unit_price       = gmodel.price_t(value    = DEFAULT_QUIZ_PRICE,
															currency = 'USD'),
						  quantity = 1),
			gmodel.item_t(merchant_item_id = 'energy_quiz',
						  name             = 'Energy Quiz',
						  description      = 'Energy quiz.',
						  unit_price       = gmodel.price_t(value    = DEFAULT_QUIZ_PRICE,
															currency = 'USD'),
						  quantity = 1),
		]),
		checkout_flow_support          = gmodel.checkout_flow_support_t(
			continue_shopping_url      = self.return_url() + user_id,
			request_buyer_phone_number = False))

	# Encode the order into XML, sign it with your merchant key and form
	# Google Checkout Button html.
	prepared = controller.prepare_order(order)

	# Now prepared.html contains the full google checkout button html
	template_values = {'checkout_button': prepared.html(), 'page_title': 'Take a Quiz' }
	path = tpl_path(STORE_PATH +'store.html')
	self.response.out.write(template.render(path, template_values))
Ejemplo n.º 8
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
    return self.redirect('/')
    logging.info('continue: %s', self.request.get('continue')) 
    login_response = str('http://' + self.request._environ['HTTP_HOST'] + '/login/response')
    template_values = {'token_url': login_response, 'no_quizlink': True}
    if self.request.get('continue'): self.session['continue'] = self.request.get('continue')
    if self.request.get('reset'): 
        self.session['user'] = False # log current user out, if logged in
        template_values = self.reset_account_access(template_values)
    
    """ TODO: test taking functionality -- not yet implemented. 
    if self.request.get('test'):
        template_values['pre_test'] = "True"
        self.session['continue'] = '/test/' + self.request.get('test')    
    """
    if self.session['user']: 
		if not self.session['continue']: self.session['continue'] = '/profile/' + self.session['user'].profile_path 
		self.redirect(self.session['continue'])
		self.session['continue'] = False
    #self.session['reset_account'] = False -- Why was this here? 
    if self.session['continue']: template_values['login_context'] = self.session['continue'].split('/')
    if self.request.get('sponsor'):
        template_values['login_context'] = "sponsor"
    self.session['post_quiz'] = False
    if self.request.get('error') == "true":
        template_values['error'] = "True"
    template_values['login_js'] = login_js(template_values)
    path = tpl_path(ACCOUNTS_PATH +'login.html')
    self.response.out.write(template.render(path, template_values))
Ejemplo n.º 9
0
Archivo: wsgi.py Proyecto: jamslevy/PQ
 def get(self):
     from utils.utils import tpl_path
     from utils.webapp import template
     path = tpl_path('utils/404.html')
     template_values = {'no_load': True}
     response = Response()
     response.set_status(404)
     response.out.write(template.render(path, template_values))
Ejemplo n.º 10
0
Archivo: js.py Proyecto: jamslevy/PQ
 def base_js(self):
     from utils.utils import tpl_path, Debug
     from utils.webapp import template
     if not Debug(): set_expire_header(self)
     template_values = {}
     path = tpl_path('base.js')
     from utils.random import minify 
     self.response.out.write( minify(template.render(path, template_values)) )
Ejemplo n.º 11
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
		#from model.proficiency import SubjectProfile
		#subjects = SubjectProfile.all().fetch(1000)
		#template_values = {"subjects": subjects}
		from model.proficiency import Proficiency
		proficiencies = Proficiency.all().fetch(1000)
		template_values = {'proficiencies': proficiencies}
		path = tpl_path(DEV_PATH + 'edit_subjects.html')
		self.response.out.write(template.render(path, template_values))		
Ejemplo n.º 12
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def LoadAnswers(self):     
		correct_answer = self.request.get('correct_answer')
		item_text = self.request.get('item_text')
		from editor.answers import Answers
		answers = Answers()
		from utils.webapp import template
		from utils.utils import tpl_path        
		template_values = {"answers": answers.load(correct_answer, item_text)}
		path = tpl_path(EDITOR_PATH + 'answer_template.html')
		return template.render(path, template_values)
Ejemplo n.º 13
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def NewTopic(self):   # set moderation status for raw item
		this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name')).get()
		new_topic = ProficiencyTopic(name = self.request.get('topic_name'), proficiency = this_subject)
		db.put([this_subject, new_topic])
		if self.request.get('no_template'): return "OK"
		from utils.webapp import template
		from utils.utils import tpl_path
		template_values = {"subject": this_subject, "new_topic":new_topic}
		path = tpl_path(EDITOR_PATH + 'item_topic.html')
		return template.render(path, template_values)
Ejemplo n.º 14
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def upload_subject_img(self):
	  subject_name = self.request.path.split('/subject_img/')[1].replace('%20',' ')
	  from model.proficiency import Proficiency
	  this_subject = Proficiency.get_by_key_name(subject_name)
	  new_image = this_subject.new_image(self.request.get('subject_img'))
	  db.put([this_subject, new_image])
	  logging.info('saved new image for subject %s' % (this_subject.name))
	  from utils.webapp import template
	  path = tpl_path(EDITOR_PATH +'load_subject_images.html')
	  template_values = {'s': {"subject": this_subject, "is_member": "admin" }} # Only admins can upload photos, for now. 
	  return template.render(path, template_values)
Ejemplo n.º 15
0
Archivo: views.py Proyecto: jamslevy/PQ
  def quiz_item(self, item_key):
		from model.quiz import QuizItem
		item = QuizItem.get(item_key)
		item_answers = []
		[item_answers.append(str(a)) for a in item.answers]  		
		quiz_item = {"answers": item_answers, "answer1" : item.answers[0], "answer2" : item.answers[1], "answer3": item.answers[2],  #answer1,2,3 is deprecated
		"proficiency": item.proficiency.name, "topic": item.topic.name, "key": item.key()}      
		template_values = {"quiz_items": [quiz_item]}
		logging.debug('loaded quiz...')
		path = tpl_path(QUIZTAKER_PATH + 'debug_quiz.html')
		self.response.out.write(template.render(path, template_values))
Ejemplo n.º 16
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def remove_link(self):
		from model.proficiency import Proficiency, Link 
		subject_name = self.request.get('subject_name')
		this_subject = Proficiency.get_by_key_name(subject_name) 
		this_link = Link.get( self.request.get('link_key') )
		logging.info('removed link: %s', this_link.url )
		db.delete(this_link)		
		db.put(this_subject)	
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'subject/links_list.html')
		template_values = {'s': {"subject": this_subject, "is_member": "admin" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Ejemplo n.º 17
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def delete_subject_image(self):
		from model.proficiency import Proficiency, SubjectImage
		subject_name = self.request.get('subject_name')
		this_subject = Proficiency.get_by_key_name(subject_name) 
		this_img = SubjectImage.get( self.request.get('img_key') )
		logging.info('removed img for subject %s', this_subject.name )
		db.delete(this_img)
		db.put(this_subject)		
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'load_subject_images.html')
		template_values = {'s': {"subject": this_subject, "is_member": "admin" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Ejemplo n.º 18
0
Archivo: views.py Proyecto: jamslevy/PQ
 def get(self):
   load_proficiencies = self.get_proficiencies()
   proficiencies = load_proficiencies[0]
   vendor = load_proficiencies[1] 
   if proficiencies[0] == None:
       logging.info('quiz not found for argument %s', load_proficiencies[0])
       return self.redirect('/quiz_not_found/') 
   load_quiz = LoadQuiz()
   if vendor == "": vendor = self.get_default_vendor()
   template_values = {"proficiencies": proficiencies, "quiz_subject": str(proficiencies[0].name), "vendor_name": vendor.name.capitalize(), "vendor": vendor.key() }
   path = tpl_path(QUIZTAKER_PATH + 'takequiz.html')
   self.response.out.write(template.render(path, template_values))
Ejemplo n.º 19
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def refresh_subjects(self):	
		from utils.appengine_utilities.sessions import Session
		self.session = Session()	
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'subject_container.html')
		from editor.methods import get_subjects_for_user     
		offset = int(self.request.get('offset'))
		new_subjects = get_subjects_for_user(self.session['user'], offset=offset)
		if len(new_subjects) < 5: new_offset = 0
		else: new_offset = offset + 5
		template_values = { 'subjects' : new_subjects, 'offset': new_offset}
		return template.render(path, template_values)	
Ejemplo n.º 20
0
Archivo: views.py Proyecto: jamslevy/PQ
 def get(self):
 	proficiencies = Proficiency.gql("WHERE status = :1", "public");
 	proficiencies = proficiencies.fetch(1000)
 	buy_buttons = []
 	for p in proficiencies: 
 	    p.checkout_button = checkout.render_quiz_button(self, p.tag(), p.name)
 	    buy_buttons.append( { 'tag': p.tag().lower(), 'html' : p.checkout_button})
 	    
 	prof_json = encode(proficiencies)
     template_values = {'proficiencies' : proficiencies, 'prof_json': prof_json, 'buy_buttons': encode(buy_buttons), 'load': 2000}
     path = tpl_path(STORE_PATH + 'proficiency.html')
     self.response.out.write(template.render(path, template_values))
Ejemplo n.º 21
0
Archivo: views.py Proyecto: jamslevy/PQ
  def from_quiz_redirect(self):      
	# redirect after quiz
	logging.info('Redirecting From Quiz')
	token = self.request.path.split('/from_quiz/')[1]
	from utils.utils import set_flash
	self.set_flash = set_flash
	self.set_flash('post_quiz')
	from quiztaker.load_quiz import QuizSession
	quiz_session = QuizSession()
	quiz_session.update_scores(token, self.session['user'].unique_identifier) # re-assigns token scores to this user
	template_values = {'redirect_path': '/profile/' + self.session['user'].profile_path}
	path = tpl_path(ACCOUNTS_PATH +'post_quiz.html')
	self.response.out.write(template.render(path, template_values))      
Ejemplo n.º 22
0
  def get(self):    
	"""

	The splashpage for QuiztheBill, containing an introduction
	and a list of bills.

	"""  
	template_values = { 'bills': self.get_bills(),
						# subject for quiz widget
						'featured_subject': "QuiztheBill" }
					   
	path = tpl_path(TEMPLATE_PATH + 'frontpage.html')
	self.response.out.write(template.render(path, template_values))
	return
Ejemplo n.º 23
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def add_link(self):
		from model.proficiency import Proficiency, Link 
		subject_name = self.request.get('subject_name')
		this_subject = Proficiency.get_by_key_name(subject_name) 
		try: new_link = Link(key_name = subject_name + "_" + self.request.get('link_url'),
		                  url = self.request.get('link_url'), 
		                 title = self.request.get('link_title'), 
		                 subject = this_subject )
		except BadValueError: return "error"
		db.put([this_subject,new_link])
		logging.info('new link with url %s and title %s for subject %s' % (this_subject.name, str(new_link.url), new_link.title ) )
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'subject/links_list.html')
		template_values = {'s': {"subject": this_subject, "is_member": "admin" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Ejemplo n.º 24
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def change_video(self):
		from model.proficiency import Proficiency
		subject_name = self.request.get('subject_name')
		this_subject = Proficiency.get_by_key_name(subject_name) 
		if "p=" not in self.request.get('new_video_url'):
			logging.info('video url %s is not recognizable as video playlist link', self.request.get('new_video_url'))
			return "error"
		video_code = self.request.get('new_video_url').split("p=")[1]
		this_subject.video_html = video_code
		logging.info('changed video for subject %s to %s' % (this_subject.name,video_code) )
		db.put(this_subject)		
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'subject/video_object.html')
		template_values = {'s': {"subject": this_subject, "is_member": "admin" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Ejemplo n.º 25
0
Archivo: views.py Proyecto: jamslevy/PQ
	def get(self):
		from model.quiz import QuizItem
		from model.user import Profile
		from model.proficiency import ProficiencyTopic
		try: self.get_subject()
		except: print "SUBJECT NOT FOUND" #self.redirect('/error/subject_not_found')
		from editor.methods import get_membership, get_user_items
		try: self.subject_membership = get_membership(self.session['user'], self.this_subject)
		except: print "NOT A MEMBER"
		template_values = {'subject': self.this_subject, 
		                   'user_items': get_user_items(self.session['user'], self.this_subject), 
		                   'subject_membership': self.subject_membership }
		template_values['ANSWERCOUNT'] = range(1,3)
		path = tpl_path(EDITOR_PATH + 'quiz_item_editor.html')
		self.response.out.write(template.render(path, template_values))
Ejemplo n.º 26
0
 def get_html(self):   
   import urllib
   template_values = {'text': urllib.unquote( self.request.get('text') ) }
   from model.proficiency import Proficiency 
   if self.request.get('subject_key'): template_values['subject_key'] = self.request.get('subject_key')
   else: 
     subjects = Proficiency.gql("WHERE status = 'public'").fetch(1000) 
     template_values['subjects'] = subjects
   if self.request.get('topic_key'): template_values['topic_key'] = self.request.get('topic_key')
   if self.request.get('topic_name'): 
       from model.proficiency import ProficiencyTopic
       p = ProficiencyTopic.gql("WHERE name = :1",  self.request.get('topic_name')).get()
       template_values['topic_key'] = p.key()
   path = tpl_path(DEV_PATH +'ubiquity_builder.html')
   response = simplejson.dumps(template.render(path, template_values))
   self.response.out.write(jsonp(self.request.get("callback"), response))
Ejemplo n.º 27
0
Archivo: views.py Proyecto: jamslevy/PQ
  def get(self):
	print ""
	json_file = open(ROOT_PATH + "/data/topics.json")
	json_str = json_file.read()
	from utils import simplejson
	newdata = simplejson.loads(json_str) # Load JSON file as object
	topics = []
	types = []
	for t in newdata:
	   topics.append(t)
	   print t['name']

	return
	template_values = {}
	path = tpl_path(DEV_PATH +'admin.html')
	self.response.out.write(template.render(path, template_values))
Ejemplo n.º 28
0
Archivo: rpc.py Proyecto: jamslevy/PQ
	def join_subject(self):
		from utils.appengine_utilities.sessions import Session
		self.session = Session()	
		from model.proficiency import Proficiency	
		this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get()
		from model.user import SubjectMember
		admin_status = False
		from google.appengine.api import users
		user = users.get_current_user()
		if user: admin_status = True
		this_membership = SubjectMember(keyname = self.session['user'].unique_identifier + "_" + this_subject.name, user = self.session['user'], subject = this_subject, is_admin = admin_status)
		logging.info('user %s joined subject %s'% (self.session['user'].unique_identifier, this_subject.name) )
		db.put([this_membership])		
		from utils.webapp import template
		path = tpl_path(EDITOR_PATH +'load_member_section.html')
		template_values = {'s': {"subject": this_subject, "is_member": "contributor" }} # Only admins can edit links, for now. 
		return template.render(path, template_values)	
Ejemplo n.º 29
0
 def browser_error(self):
   DEFAULT_QUIZ_SUBJECT = "Recovery.Gov"
   if not Debug(): self.set_expire_header()
   try : 
       proficiency_arg = self.request.path.split('/quiz/')[1].replace('%20',' ')
       this_proficiency = Proficiency.get_by_key_name(proficiency_arg)
       assert this_proficiency != None
       self.these_proficiencies = [this_proficiency]
   except: self.these_proficiencies = [Proficiency.get_by_key_name(DEFAULT_QUIZ_SUBJECT)]
   proficiency_names = [str(p.name) for p in self.these_proficiencies] 
   session_token = self.get_session_token()
   
   template_values = {
   'quiz_subject': encode(proficiency_names[0]).replace("\n", "")
   }
    
   path = widget_path('error.js')
   from utils.random import minify
   self.response.out.write(  minify(template.render(path, template_values))  )
Ejemplo n.º 30
0
  def get(self):    
	"""
	
	Renders an frame with a webpage used to create quizzes. For this app,
	the frame contains the text of pending Congressional legislation.
	
	"""
	import urllib 
	bill_name = urllib.unquote( self.request.path.split('/bill/')[1] )
	self.this_bill = Bill.get_by_key_name(bill_name)
	if self.this_bill is None:
	  logging.error('bill %s not found', bill_name) 
	  return self.redirect('/bill_not_found')
	  	  
	from models import ProficiencyTopic
	template_values = {'url': self.get_bill_url(), 'subject_key': APP_NAME,
	                   'topic_name': self.this_bill.title, }
	path = tpl_path(TEMPLATE_PATH + 'iframe.html')
	self.response.out.write(template.render(path, template_values))
	return