def unstarred_word(word_id,user_id): word = UserWord.query.get(word_id) user = User.find_by_id(user_id) user.starred_words.remove(word) model.db.session.commit() print word + " is now *unstarred* for user " + user.name return "OK"
def unstarred_word(word_id, user_id): word = UserWord.query.get(word_id) user = User.find_by_id(user_id) user.starred_words.remove(word) model.db.session.commit() print word + " is now *unstarred* for user " + user.name return "OK"
def _link_teacher_cohort(user_id, cohort_id): ''' Takes user_id and cohort_id and links them together in teacher_cohort_map table. ''' from zeeguu.model import TeacherCohortMap user = User.find_by_id(user_id) cohort = Cohort.find(cohort_id) db.session.add(TeacherCohortMap(user, cohort)) db.session.commit() return 'added teacher_cohort relationship'
def recompute_for_users(): """ recomputes only those caches that are already in the table and belong to a user. if multiple users have the same preferences the computation is donne only for the first because this is how recompute_recommender_cache_if_needed does. To think about: - what happens when this script is triggered simultaneously with triggering recompute_recommender_cache_if_needed from the UI? will there end up be duplicated recommendations? should we add a uninque constraint on (hash x article)? Note: in theory, the recomputing should be doable independent of users in practice, the recompute_recommender_cache takes the user as input. for that function to become independent of the user we need to be able to recover the ids of the languages, topics, searchers, etc. from the content_hash to do this their ids would need to be comma separated OTOH, in the future we might still want to have a per-user cache because the recommendations might be different for each user since every user has different language levels!!! :param existing_hashes: :return: """ already_done = [] for user_id in User.all_recent_user_ids(): try: user = User.find_by_id(user_id) reading_pref_hash = reading_preferences_hash(user) if reading_pref_hash not in already_done: recompute_recommender_cache_if_needed(user, session) print(f"Success for {reading_pref_hash} and {user}") already_done.append(reading_pref_hash) else: print( f"nno need to do for {user}. hash {reading_pref_hash} already done" ) except Exception as e: print(f"Failed for user {user}")
def starred_word(word_id,user_id): word = UserWord.query.get(word_id) user = User.find_by_id(user_id) user.star(word) model.db.session.commit() return "OK"
def starred_word(word_id, user_id): word = UserWord.query.get(word_id) user = User.find_by_id(user_id) user.star(word) model.db.session.commit() return "OK"
#!/usr/bin/env python """ Script that lists recent users To be called from a cron job. """ from zeeguu.model import User for user_id in User.all_recent_user_ids(): user = User.find_by_id(user_id) print(user.name) print(user.email)
def __get_bookmarks_for_user(self, user_id): user = User.find_by_id(user_id) print('Using user ' + user.name + ' with id ' + str(user.id)) return user.all_bookmarks()