Esempio n. 1
0
File: rpc.py Progetto: jamslevy/PQ
  def nickname_check(self, *args):
	profile_path = args[0].lower()
	profile_path = profile_path.replace(' ','_')
	from model.user import Profile
	same_path = Profile.gql("WHERE profile_path = :1", profile_path).fetch(1)
	if same_path: return "not_available"
	else: return "available"
Esempio n. 2
0
  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)
Esempio n. 3
0
def delete_user(user_key):
  # check in case entity was sent
  if type(user_key).__name__ == "Profile":
    user_key = user_key.key()
  # this will only work with dummy users
  # does not yet get links, etc.
  # best for after messing up and creating a wrong user   
  from model.account import Account
  from model.user import Profile, QuizTaker
  from model.activity import ActivityProfile, UserTopicScores, PostedLink, Scoop, SharedItem
  from model.sponsor import Sponsor, Pledge
  from model.student import Student
  from model.timeline import ProfileTimeline
  
  delete = []    
  p = Profile.get(user_key)
  if p:
    delete.append(p)
  else:
    logging.error('unable to delete user. User key %s not found' % user_key)
    return False
  student = p.student.get()
  if student:
    delete.append(student)
    delete.extend(student.pledges.fetch(50))
  sponsor = p.sponsor.get()
  if sponsor:
    delete.append(sponsor)
    delete.extend(sponsor.pledges.fetch(50))
  key_name = p.key().name()
  failed_links = []
  activity_profiles = p.activity_profiles.fetch(5)
  for a in activity_profiles:
    if a:  
      delete.append(a)
      links = a.links.fetch(1000)
      failed_links.extend(links)
  delete_links(failed_links)
  ts = p.topic_scores.get()
  if ts:
    delete.append(ts)
  ac = Account.get_by_key_name(key_name)
  if ac:
    delete.append(ac)
  shared_items = p.shared_items.fetch(300)
  if shared_items:
    delete.extend(shared_items)
  pt = p.timeline.get()
  if pt:
    delete.append(pt)
  qt = QuizTaker.get_by_key_name(key_name)
  if qt:
    delete.append(qt)
  
  delete.extend(Scoop.all().filter(
    'scooper IN', [a.key() for a in activity_profiles]).fetch(1000))
  delete.extend(Scoop.all().filter(
    'scooped IN', [a.key() for a in activity_profiles]).fetch(1000))                      
  logging.error('deleting %d entities - %s' % (len(delete), str([e.key() for e in delete])))
  db.delete(delete)
Esempio n. 4
0
File: rpc.py Progetto: jamslevy/PQ
  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"
Esempio n. 5
0
File: rpc.py Progetto: jamslevy/PQ
  def reset_account(self):
  	from model.user import Profile
  	this_profile = Profile.gql("WHERE email = :1", self.request.get('email')).get()
  	if this_profile:
  		from accounts.mail import reset_account_access
  		reset_account_access(this_profile)
  		return "OK"	
	return "Profile Not Found"
Esempio n. 6
0
File: rpc.py Progetto: jamslevy/PQ
 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 ))
Esempio n. 7
0
File: views.py Progetto: jamslevy/PQ
	def get_profile(self):
		if not len(self.request.path.split('/sponsor/')[1]) > 0: return False
		from model.user import Profile
		self.profile = Profile.gql('WHERE profile_path = :1', self.request.path.split('/sponsor/')[1].lower()).get()
		try: self.profile.unique_identifier
		except: 
		    self.redirect('/profile_not_found/')
		    return False
		return True
Esempio n. 8
0
  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)	
Esempio n. 9
0
File: views.py Progetto: jamslevy/PQ
 def reset_account_access(self, template_values):
   from model.user import Profile
   try: 
       self.session['reset_account'] = Profile.get(self.request.get('reset'))
       assert self.session['reset_account'] is not False
       logging.info('Presenting Reset Account Options for User %s', (self.session['reset_account'].email))
       template_values['login_context'] = "reset"
   except: 
       logging.warning('unable to use key %s for login shortcut', self.request.get('secret'))
       template_values['error'] = "True" # TODO change text of error?
   return template_values        
Esempio n. 10
0
File: util.py Progetto: jamslevy/PQ
 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)
Esempio n. 11
0
File: rpc.py Progetto: jamslevy/PQ
 def intro_mail_message(self, *args):
 	from model.user import Profile
 	from accounts.mail import mail_intro_message
 	profiles = Profile.all().fetch(10)
 	for p in profiles:
 		mail_intro_message(p)