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))
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))
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))
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)) )
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))
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))
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)
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)
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)
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))
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))
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)
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)
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)
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))
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
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)
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)
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))
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))
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)
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
def change_rights(self): from utils.appengine_utilities.sessions import Session self.session = Session() from model.proficiency import Proficiency from model.user import SubjectMember subject_name = self.request.get('subject_name') this_subject = Proficiency.get_by_key_name(subject_name) this_change = self.request.get('rights_action') this_membership = SubjectMember.gql("WHERE subject = :1 AND user = :2", this_subject, self.session['user']).get() if this_change == "make_admin": logging.info('make admin') this_membership.is_admin = True if this_change == "remove_admin": this_membership.is_admin = False db.put([this_subject,this_membership]) logging.info('user %s has had admin status set to %s for subject %s' % (self.session['user'].unique_identifier, str(this_membership.is_admin), this_subject.name)) from utils.webapp import template path = tpl_path(EDITOR_PATH +'subject/admin_rights.html') template_values = {'s': {"subject": this_subject}} return template.render(path, template_values)
def get(self): logging.info('Loading Registration Page') self.session['user'] = registered(self.session['unique_identifier']) if self.session['user']: logging.warning('user %s attempting to register while signed in', self.session['user'].unique_identifier) if not self.session['continue']: self.session['continue'] = '/profile/' + self.session['user'].profile_path self.redirect(self.session['continue']) self.session['continue'] = False if not self.session['unique_identifier']: # you should only be visiting this page after a redirect from login page self.redirect('/login') return False if self.request.get('nickname'): return self.create_user() nickname, email = None, None if self.session['nickname']: nickname = self.session['nickname'] if self.session['email']: email = self.session['email'] template_values = {'nickname': nickname, 'email': email, 'no_quizlink': True} template_values['register_js'] = register_js(template_values) path = tpl_path(ACCOUNTS_PATH +'signup.html') self.response.out.write(template.render(path, template_values)) return
def create_new_subject(self): from utils.appengine_utilities.sessions import Session self.session = Session() from model.proficiency import Proficiency existing_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get() if existing_subject is not None: logging.warning("user %s attempted to create duplicate subject with name %s" %(self.session['user'].unique_identifier, self.request.get('subject_name')) ) return "exists" this_subject = Proficiency(key_name = self.request.get('subject_name'), name = self.request.get('subject_name')) from model.user import SubjectMember this_membership = SubjectMember(keyname = self.session['user'].unique_identifier + "_" + this_subject.name, user = self.session['user'], subject = this_subject, status = "public", is_admin = True) logging.info('user %s created subject %s'% (self.session['user'].unique_identifier, this_subject.name) ) db.put([this_subject, this_membership]) from utils.webapp import template path = tpl_path(EDITOR_PATH +'subject_container.html') from editor.methods import get_subjects_for_user template_values = { 'subjects' : get_subjects_for_user(self.session['user'])} return template.render(path, template_values)
def SubmitItem(self): from model.proficiency import Proficiency, ProficiencyTopic this_subject = Proficiency.gql("WHERE name = :1", self.request.get('subject_name') ).get() logging.info('submitting item') from utils.appengine_utilities.sessions import Session session = Session() if len( self.request.get('item_key') ) < 1: this_item = QuizItem(pending_proficiency = this_subject) if session['user']: this_item.author= session['user'] else: this_item = QuizItem.get(self.request.get('item_key')) if self.request.get('item_status') == "approved": this_item.active = True this_item.pending_proficiency = None this_item.proficiency = this_subject if self.request.get('item_status') == "not_approved": this_item.active = False this_item.pending_proficiency = this_subject this_item.proficiency = None this_item.topic = ProficiencyTopic.get( self.request.get('topic_key') ) this_item.index = self.request.get('correct_answer') this_item.answers = [a.strip("'") for a in self.request.get('answers').split(",")] this_item.content = self.request.get('item_text') save = [ this_subject, this_item] #if session['user']: save.append(session['user']) db.put( save ) logging.info('saving new quiz item %s with subject %s and index %s' % (this_item.__dict__, self.request.get('subject_name'), self.request.get('correct_answer') )) if self.request.get('ubiquity'): return "OK" from utils.webapp import template from utils.utils import tpl_path from editor.methods import get_membership, get_user_items template_values = {"subject": this_subject, 'subject_membership': get_membership(session['user'], this_subject), 'user_items': get_user_items(session['user'], this_subject), } path = tpl_path(EDITOR_PATH + 'quiz_item_editor_template.html') return template.render(path, template_values)
def get(self): # Now prepared.html contains the full google checkout button html account = Account.get_by_key_name(self.session['user']) account.pass_count = 1 account.put() try: pass_count = account.pass_count except: # no pass count yet try: account.pass_count = 1 # this is just to upgrade model. pass_count = account.pass_count except: from accounts.methods import register_account register_account(self.session['user']) account = Account.get_by_key_name(self.session['user']) account.pass_count = 1 pass_count = account.pass_count # take previous block out account.put() test = self.get_test() template_values = {'pass_count': pass_count} path = tpl_path(STORE_PATH +'take_test.html') self.response.out.write(template.render(path, template_values))
def register_js(template_values): path = tpl_path(ACCOUNTS_PATH + 'scripts/register.js') from utils.random import minify return minify( template.render(path, template_values) )
def get_js(self): template_values = {} path = tpl_path(DEV_PATH +'ubiquity_builder.js') self.response.out.write(template.render(path, template_values))
def get_html(self): from model.proficiency import Proficiency subjects = Proficiency.gql("WHERE status = 'public'").fetch(1000) template_values = {'text': self.request.get('text'), 'subjects': subjects} path = tpl_path(DEV_PATH +'ubiquity_builder.html') self.response.out.write(template.render(path, template_values))