Пример #1
0
	def check_all(self, awards): # start from awards, checks for all users. 
		self.save_sponsorships = [] # for batch datastore trip
		awards = Award.all().fetch(1000) # TODO: should only get unactivated awards. Award.sponsorships is reference collection. 
		for award in awards:
			self.check_award(award)
		db.put(self.save_sponsorships)
		return len(self.save_sponsorships)
Пример #2
0
	def upgrade_awards(self, qt):
		for proficiency, type in self.awarded_proficiencies.items():
			logging.info('upgrading awards for user %s and proficiency %s', qt.unique_identifier, proficiency)
			#topic_list = self.topics_in_proficiency[proficiency]   - Only Needed if we need all the topics in the proficiency
			if type == "fluency": rankings = self.fluency[proficiency]
			if type == "excellence": rankings = self.excellence[proficiency]
			this_account = Account.get_by_key_name(qt.unique_identifier)
			this_profile = Profile.get_by_key_name(qt.unique_identifier)
			if not this_account: 
			    this_account = register_account(qt.unique_identifier)
			award_topics = [] 
			award_levels = []
			for rank_dict in rankings:
				for topic, level in rank_dict.items():
					award_topics.append(topic)
					award_levels.append(level)
					
			# make sure that awards are not duplicated - can we avoid the loop in general? 
			award_key_name = str(this_profile.unique_identifier) + str(proficiency.name) + str(type) # you can get more than one type of award per proficiency
			new_award = Award.get_or_insert(key_name = award_key_name,
			                   type = type,
			                   topics = award_topics,
			                   levels = award_levels,
			                   proficiency = proficiency,
			                   winner = this_profile )
			self.save_awards.append(new_award)
Пример #3
0
def load_action_feed():
	action_feed = []
	from model.account import Sponsorship, Award
	#recent_sponsorships = Sponsorship.all().order('-date').fetch(ACTION_THRESHOLD)
	#action_feed.extend(recent_sponsorships)
	recent_awards = Award.all().order('-date').fetch(ACTION_THRESHOLD)
	action_feed.extend(recent_awards)
	from operator import attrgetter
	action_feed.sort(key = attrgetter('date'), reverse = True)
	from google.appengine.api import memcache
	memcache.set('action_feed',action_feed, 60000)
	memcache.set('next_items',action_feed, 60000)
	return update_action_feed()