def get_fixture_subject(self): try: fixture_subject = Setting.get_by_key_name('fixture_subject').status from model.proficiency import Proficiency this_subject = Proficiency.get_by_key_name(fixture_subject) assert this_subject is not None return Proficiency.get_by_key_name(fixture_subject) except: DEFAULT_SUBJECT = "Smart Grid" logging.error('unable to load fixture subject - returning default: %s', DEFAULT_SUBJECT) return DEFAULT_SUBJECT
def sponsor_settings(self): PLEDGE_NUM = 500 # get employer this_employer = Employer.get_by_key_name(self.request.get('sponsor')) # save message this_employer.sponsorship_message = self.request.get('sponsorship_message') #save quiz subjects this_employer.quiz_subjects = [ self.request.get('quiz_subject') ] # also save it in the profile_image from model.user import Profile this_user = Profile.get_by_key_name(this_employer.unique_identifier) from model.proficiency import Proficiency this_proficiency = Proficiency.get_by_key_name(self.request.get('quiz_subject')) # TODO: Should changing your sponsored subject cancel out your existing auto pledges? # old_pledges = AutoPledge.gql("WHERE employer = :1 AND proficiency != :2", % (this_employer, this_proficiency)) #this_user.sponsored_subjects.append( Proficiency.get_by_key_name(self.request.get('quiz_subject')) ) -- Multiple Entries this_user.sponsored_subjects = [ this_proficiency.key() ] # create auto_pledge from model.employer import AutoPledge # save sponsor account new_pledge = AutoPledge(key_name = this_employer.unique_identifier + "_" + this_proficiency.name, employer = this_employer, proficiency = this_proficiency, count = PLEDGE_NUM) db.put([this_employer, this_user, new_pledge]) return "OK"
def update_subject_blurb(self): from model.proficiency import Proficiency subject_name = self.request.get('subject_name') this_subject = Proficiency.get_by_key_name(subject_name) if this_subject is None: logging.error('no subject found when saving blurb for subject_name %s ', subject_name) return "no subject found" this_subject.blurb = self.request.get('new_blurb') db.put(this_subject) return "OK"
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 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 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 make_scores(self, *args): if len(args) < 2: return "Specify A Proficiency, and Correct Ratio" from utils.appengine_utilities.sessions import Session self.session = Session() from model.proficiency import Proficiency this_proficiency = Proficiency.get_by_key_name(args[0]) correct_prob = args[1] if not self.session['user']: return "Not Logged In" this_user = self.session['user'] from dev.fixtures import Scores scores = Scores() save_scores = scores.make_scores(this_user, this_proficiency, correct_prob, SCORE_NUM = 10) db.put(save_scores)
def working(self, *args): from model.proficiency import Proficiency, ProficiencyTopic q = Proficiency.get_by_key_name("QuiztheBill") save = [] pts = ProficiencyTopic.all().fetch(1000) for p in pts: if p.subject is None: p.subject = q print p.name save.append(p) db.put(save)
def get_test(self): if len(self.request.path.split('/sponsor/')[1]) > 0: employer = Employer.gql('WHERE name = :1', self.request.path.split('/quiz/')[1].lower()) try: these_proficiencies = employer.get().proficiencies except: return None proficiencies = [] for p in these_proficiencies: this_p = Proficiency.get_by_key_name(p) proficiencies.append(this_p.name) return [proficiencies, employer.get()] #except: return [proficiency.name for proficiency in all_proficiencies.fetch(4)] if self.request.get('proficiencies'): proficiencies = self.request.get('proficiencies') return [eval(proficiencies,{"__builtins__":None},{}), self.get_default_vendor()] return None
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 add_auto_pledge(self, *args): if not args: return "Specify A Business Identifier, Proficiency Name, and Number of Pledges." if len(args) > 3: return "Specify A Business Identifier, Proficiency Name, and Number of Pledges." business_name = args[0] from model.employer import Employer this_employer = Employer.get_by_key_name(business_name) if not this_employer: return "employer does not exist" proficiency_name = args[1] from model.proficiency import Proficiency #import string -- Capwords sucks, darnit. #this_proficiency = Proficiency.get_by_key_name(string.capwords(proficiency_name)) this_proficiency = Proficiency.get_by_key_name(proficiency_name) pledge_num = int(args[2]) from model.employer import AutoPledge new_pledge = AutoPledge(employer = this_employer, proficiency = this_proficiency, count = pledge_num) new_pledge.put() return encode(new_pledge)
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_subject(self): # Get subject from path import string #string.capwords() subject_name = self.request.path.split('/edit/')[1].replace("%20"," ") #TODO - instead of capwords, make all subject names lowercase self.this_subject = Proficiency.get_by_key_name(subject_name) assert self.this_subject is not None