def get_proficiencies(self): from model.user import QuizTaker qt = QuizTaker.get_by_key_name(self.profile.unique_identifier) proficiency_levels = qt.proficiency_levels self.proficiencies = [] for pl in proficiency_levels: self.proficiencies.append({'name': pl.proficiency.name, 'key': pl.proficiency.key()})
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)
def set_awards(self, *args): from utils.appengine_utilities.sessions import Session self.session = Session() if not self.session['user']: return "Not Logged In" from accounts.methods import Awards from model.user import QuizTaker awards = Awards() return awards.check_all( QuizTaker.get_by_key_name(self.session['user'].unique_identifier) )
def set_levels(self, *args): from utils.appengine_utilities.sessions import Session self.session = Session() if not self.session['user']: return "Not Logged In" from quiztaker.methods import ProficiencyLevels from model.user import QuizTaker pl = ProficiencyLevels() return pl.set_for_user( QuizTaker.get_by_key_name(self.session['user'].unique_identifier) )