def refresh_employer_images(self, employer_list=False): #TODO: Reduce multiple writes from google.appengine.api import images save_profiles = [] from model.user import Profile, ProfilePicture if not employer_list: employers = Employer.all().fetch(1000) else: employers = employer_list logging.info('saving employer images for %s', employers) for e in employers: p_path = ROOT_PATH + "/data/img/business/" try: image_file = open(p_path + str(e.unique_identifier) + ".png") except: continue image = image_file.read() small_image = images.resize(image, 45, 45) large_image = images.resize(image, 95, 95) new_image = ProfilePicture(small_image = small_image, large_image = large_image, type = "employer" ) new_image.put() logging.info('saved employer image for %s', e.unique_identifier) this_profile = Profile.get_by_key_name(e.unique_identifier) try:this_profile.photo = new_image except: logging.info('unable to refresh employer image for %s', e.unique_identifier) continue save_profiles.append(this_profile) logging.info('refreshed %d employer images', len(save_profiles)) if save_profiles: print "refreshed employer images for", [p.unique_identifier for p in save_profiles] db.put(save_profiles)
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 pqmember(self, *args): from model.user import Profile pq = Profile.get_by_key_name("PlopQuiz") from model.proficiency import Proficiency ps = Proficiency.gql("WHERE status = 'public'").fetch(1000) from model.user import SubjectMember for p in ps: db.put(SubjectMember(key_name = pq.unique_identifier + "_" + p.name, user = pq, subject = p ))
def delete_employer_images(self): delete_list = [] from model.user import Profile, ProfilePicture for e in Employer.all().fetch(1000): try: this_profile = Profile.get_by_key_name(e.unique_identifier) if this_profile.photo.type != "pq": delete_list.append(this_profile.photo) except: pass db.delete(delete_list)
def check_login(self, *args): if self.request.method != 'GET': raise webapp.Error('The check_login decorator can only be used for GET ' 'requests') session = Session() from model.user import Profile this_user = Profile.get_by_key_name(self.session['user'].unique_identifier) if this_user.is_sponsor is True: self.session['user'] = False self.session['continue'] = self.request.path self.redirect('/login/?sponsor=true') return else: handler_method(self, *args)