def reset_password(self): user_email = request.params['email'] user_for_email = controller_globals._get_user_from_email(user_email) if user_for_email: token = self.gen_token_to_reset_pwd(user_for_email) message = """ Hi, %s. \n Someone (hopefully you!) asked to reset your abstrackr password. To do so, follow this link:\n \t %saccount/confirm_password_reset/%s.\n Note that your password will be temporarily changed if you follow this link! If you didn't request to reset your password, just ignore this email. """ % (user_for_email.fullname, url( '/', qualified=True), token) print token self.send_email_to_user(user_for_email, "resetting your abstrackr password", message) c.pwd_msg = "OK -- check your email (and your spam folder!)" return render('/accounts/recover.mako') else: c.pwd_msg = """ Well, this is awkward. We don't have a user in our database with email: %s. Try again?""" % user_email return render('/accounts/recover.mako')
def customize_citations(self): # Obtain the parameters. show_journal_str = request.params['toggle_journal'] show_authors_str = request.params['toggle_authors'] show_keywords_str = request.params['toggle_keywords'] # Obtain the User object (as opposed to the auth.User object). cur_user = controller_globals._get_user_from_email( request.environ.get('repoze.who.identity')['user'].email) # Make changes to the booleans of the user object. cur_user.show_journal = {"Show": True, "Hide": False}[show_journal_str] cur_user.show_authors = {"Show": True, "Hide": False}[show_authors_str] cur_user.show_keywords = { "Show": True, "Hide": False }[show_keywords_str] # Add the changes to the database. Session.commit() # These messages appear in their designated separate locations, # i.e. on the top left corner of the div that corresponds to this function. # This is more appropriate than having a general message on some part of the screen. c.account_msg = "" c.account_msg_citation_settings = "Citation Settings changes have been applied." return render("/accounts/account.mako")
def customize_citations(self): # Obtain the parameters. show_journal_str = request.params['toggle_journal'] show_authors_str = request.params['toggle_authors'] show_keywords_str = request.params['toggle_keywords'] # Obtain the User object (as opposed to the auth.User object). cur_user = controller_globals._get_user_from_email(request.environ.get('repoze.who.identity')['user'].email) # Make changes to the booleans of the user object. cur_user.show_journal = {"Show":True, "Hide":False}[show_journal_str] cur_user.show_authors = {"Show":True, "Hide":False}[show_authors_str] cur_user.show_keywords = {"Show":True, "Hide":False}[show_keywords_str] # Add the changes to the database. Session.commit() # These messages appear in their designated separate locations, # i.e. on the top left corner of the div that corresponds to this function. # This is more appropriate than having a general message on some part of the screen. c.account_msg = "" c.account_msg_citation_settings = "Citation Settings changes have been applied." return render("/accounts/account.mako")
def my_projects(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person # Get user object from db. user = controller_globals._get_user_from_email(person.email) # Set user's show preference defaults in case they weren't set. if (user.show_journal == True or user.show_journal == False): c.show_journal = user.show_journal else: user.show_journal = True if (user.show_authors == True or user.show_authors == False): c.show_authors = user.show_authors else: user.show_authors = True if (user.show_keywords == True or user.show_keywords == False): c.show_keywords = user.show_keywords else: user.show_keywords = True project_q = Session.query(model.Project) c.leading_projects = user.leader_of_projects leading_project_ids = [proj.id for proj in c.leading_projects] c.participating_projects = [ p for p in user.member_of_projects if p.id not in leading_project_ids ] c.review_ids_to_names_d = self._get_review_ids_to_names_d( c.participating_projects) statuses_q = Session.query(model.PredictionsStatus) c.statuses = {} c.do_we_have_a_maybe = {} for project_id in leading_project_ids: predictions_for_review = statuses_q.filter( model.PredictionsStatus.project_id == project_id).all() if len(predictions_for_review ) > 0 and predictions_for_review[0].predictions_exist: c.statuses[project_id] = True else: c.statuses[project_id] = False c.do_we_have_a_maybe[project_id] = False # Flag projects that have locked priorities c.projects_w_locked_priorities = self._get_projects_w_locked_priorities( leading_project_ids) c.my_work = False c.my_projects = True return render('/accounts/dashboard.mako')
def show_merge_review_screen(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person projects_person_leads = self._get_projects_person_leads(person) c.reviews = projects_person_leads return render('/reviews/merge_reviews.mako')
def show_merge_review_screen(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person user = controller_globals._get_user_from_email(person.email) projects_person_leads = self._get_projects_person_leads(user) c.reviews = projects_person_leads return render('/reviews/merge_reviews.mako')
def change_password(self): current_user = request.environ.get('repoze.who.identity')['user'] if request.params["password"] == request.params["password_confirm"]: current_user._set_password(request.params['password']) model.Session.commit() c.account_msg = "ok, your password has been changed." else: c.account_msg = "whoops -- the passwords didn't match! try again." return render("/accounts/account.mako")
def change_password(self): current_user = request.environ.get('repoze.who.identity')['user'] if request.params["password"] == request.params["password_confirm"]: current_user._set_password(request.params['password']) Session.commit() c.account_msg = "ok, your password has been changed." else: c.account_msg = "whoops -- the passwords didn't match! try again." c.account_msg_citation_settings = "" return render("/accounts/account.mako")
def my_projects(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person # Get user object from db. user = controller_globals._get_user_from_email(person.email) # Set user's show preference defaults in case they weren't set. if (user.show_journal==True or user.show_journal==False): c.show_journal = user.show_journal else: user.show_journal = True if (user.show_authors==True or user.show_authors==False): c.show_authors = user.show_authors else: user.show_authors = True if (user.show_keywords==True or user.show_keywords==False): c.show_keywords = user.show_keywords else: user.show_keywords = True project_q = Session.query(model.Project) c.leading_projects = user.leader_of_projects leading_project_ids = [proj.id for proj in c.leading_projects] c.participating_projects = [p for p in user.member_of_projects if p.id not in leading_project_ids] c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects) statuses_q = Session.query(model.PredictionsStatus) c.statuses = {} c.do_we_have_a_maybe = {} for project_id in leading_project_ids: predictions_for_review = statuses_q.filter(model.PredictionsStatus.project_id==project_id).all() if len(predictions_for_review) > 0 and predictions_for_review[0].predictions_exist: c.statuses[project_id] = True else: c.statuses[project_id] = False c.do_we_have_a_maybe[project_id] = False # Flag projects that have locked priorities c.projects_w_locked_priorities = self._get_projects_w_locked_priorities(leading_project_ids) c.my_work = False c.my_projects = True return render('/accounts/dashboard.mako')
def reset_password(self): user_email = request.params['email'] user_for_email = controller_globals._get_user_from_email(user_email) if user_for_email: token = self.gen_token_to_reset_pwd(user_for_email) message = """ Hi, %s. \n Someone (hopefully you!) asked to reset your abstrackr password. To do so, follow this link:\n \t %saccount/confirm_password_reset/%s.\n Note that your password will be temporarily changed if you follow this link! If you didn't request to reset your password, just ignore this email. """ % (user_for_email.fullname, url('/', qualified=True), token) print token self.send_email_to_user(user_for_email, "resetting your abstrackr password", message) c.pwd_msg = "OK -- check your email (and your spam folder!)" return render('/accounts/recover.mako') else: c.pwd_msg = """ Well, this is awkward. We don't have a user in our database with email: %s. Try again?""" % user_email return render('/accounts/recover.mako')
def login(self): """ This is where the login form should be rendered. Without the login counter, we won't be able to tell if the user has tried to log in with wrong credentials. """ identity = request.environ.get('repoze.who.identity') came_from = str(request.GET.get('came_from', '')) or \ url(controller='account', action='welcome') if identity: redirect(url(came_from)) else: c.came_from = came_from c.login_counter = request.environ['repoze.who.logins'] + 1 return render('/accounts/login.mako')
def my_projects(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person project_q = model.meta.Session.query(model.Review) c.leading_projects = project_q.filter(model.Review.project_lead_id == person.id).all() leading_project_ids = [proj.review_id for proj in c.leading_projects] # pull the reviews that this person is participating in junction_q = model.meta.Session.query(model.ReviewerProject) participating_project_ids = \ [p.review_id for p in junction_q.filter(model.ReviewerProject.reviewer_id == person.id).all()] c.participating_projects = [p for p in project_q.all() if p.review_id in participating_project_ids and \ not p.review_id in leading_project_ids] c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects) statuses_q = model.meta.Session.query(model.PredictionsStatus) c.statuses = {} #c.conflicts = {} c.do_we_have_a_maybe = {} for project_id in leading_project_ids: predictions_for_review = statuses_q.filter(model.PredictionsStatus.review_id==project_id).all() if len(predictions_for_review) > 0 and predictions_for_review[0].predictions_exist: c.statuses[project_id] = True else: c.statuses[project_id] = False #c.statuses[project_id] = False import time start_time = time.time() #c.conflicts[project_id] = controller_globals._does_a_conflict_exist(project_id) end_time = time.time() elapsed = end_time-start_time #pdb.set_trace() #len(controller_globals._get_conflicts(project_id)) > 0 # conflicting labels for this review? c.do_we_have_a_maybe[project_id] = False#= len(controller_globals._get_maybes(project_id)) > 0 # Do we have maybes for this project? c.my_work = False c.my_projects = True return render('/accounts/dashboard.mako')
def my_work(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person # pull all assignments for this person assignment_q = model.meta.Session.query(model.Assignment) all_assignments = assignment_q.filter(model.Assignment.reviewer_id == person.id).all() c.outstanding_assignments = [a for a in all_assignments if not a.done] # if there's an initial assignment, we'll only show that. assignment_types = [assignment.assignment_type for assignment in \ c.outstanding_assignments] ##### # for any review that has an initial assignment, we will show # *only* that assignment, thereby forcining participants to # finish initial assignments before moving on to other # assignments. fix for issue #5. #### # which reviews have (outstanding) initial assigments? reviews_with_initial_assignments = [] for assignment in c.outstanding_assignments: if assignment.assignment_type == "initial": reviews_with_initial_assignments.append(assignment.review_id) # now remove other (non-initial) assignments for reviews # that have an initial assignment filtered_assigments = [assignment for assignment in c.outstanding_assignments if \ assignment.review_id not in reviews_with_initial_assignments or \ assignment.assignment_type == "initial"] c.outstanding_assignments = filtered_assigments c.finished_assignments = [a for a in all_assignments if a.done] project_q = model.meta.Session.query(model.Review) junction_q = model.meta.Session.query(model.ReviewerProject) participating_project_ids = \ [p.review_id for p in junction_q.filter(model.ReviewerProject.reviewer_id == person.id).all()] c.participating_projects = [p for p in project_q.all() if p.review_id in participating_project_ids] c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects ) c.my_work = True c.my_projects = False return render('/accounts/dashboard.mako')
def login(self): """ This is where the login form should be rendered. Without the login counter, we won't be able to tell if the user has tried to log in with wrong credentials. """ identity = request.environ.get('repoze.who.identity') came_from = str(request.GET.get('came_from', '')) or \ url(controller='account', action='welcome') if identity: session['flash'] = 'Login successful.' session.save() redirect(url(came_from)) else: c.came_from = came_from c.login_counter = request.environ['repoze.who.logins'] + 1 return render('/accounts/login.mako')
def privacy(self): c.root_path = url('/', qualified=True) return render("/static_pages/privacy.mako")
def recover_password(self): c.pwd_msg = "" return render('/accounts/recover.mako')
def my_account(self): c.current_user = request.environ.get('repoze.who.identity')['user'] c.account_msg = "" c.account_msg_citation_settings = "" return render("/accounts/account.mako")
def create_account(self): if 'then_join' in request.params: c.then_join = request.params['then_join'] return render('/accounts/register.mako')
def my_work(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person user = controller_globals._get_user_from_email(c.person.email) if not user: log.error('''\ Hum...fetching user from the database returned False. We need to investigate. Go remove the catch all in controller_globals.py, method _get_user_from_email() to see which OperationalError is being raised ''') # If somehow the user's citation settings variables don't get initialized yet, # then the following 3 if-else blocks should take care of it in order to avoid # any errors due to the values of the variables being null: c.show_journal = user.show_journal if not user.show_journal is None else True if (user.show_authors == True or user.show_authors == False): c.show_authors = user.show_authors else: user.show_authors = True if (user.show_keywords == True or user.show_keywords == False): c.show_keywords = user.show_keywords else: user.show_keywords = True # pull all assignments for this person assignment_q = Session.query(model.Assignment) all_assignments = assignment_q.filter( model.Assignment.user_id == person.id).all() # This process is incredibly slow. Take it out for now and find out # why the .done and .done_so_far field on assignment is off sometimes. #self._set_assignment_done_status(all_assignments) self._clear_this_user_locks(all_assignments) # Build assignment completion status dictionary c.d_completion_status = self._get_assignment_completion_status( all_assignments) c.outstanding_assignments = [a for a in all_assignments if not a.done] # if there's an initial assignment, we'll only show that. assignment_types = [assignment.assignment_type for assignment in \ c.outstanding_assignments] ##### # for any review that has an initial assignment, we will show # *only* that assignment, thereby forcining participants to # finish initial assignments before moving on to other # assignments. fix for issue #5. #### # which reviews have (outstanding) initial assigments? reviews_with_initial_assignments = [] for assignment in c.outstanding_assignments: if assignment.assignment_type == "initial": reviews_with_initial_assignments.append(assignment.project_id) # now remove other (non-initial) assignments for reviews # that have an initial assignment filtered_assignments = [assignment for assignment in c.outstanding_assignments if \ assignment.project_id not in reviews_with_initial_assignments or \ assignment.assignment_type == "initial"] c.outstanding_assignments = filtered_assignments c.finished_assignments = [a for a in all_assignments if a.done] project_q = Session.query(model.Project) c.participating_projects = user.member_of_projects c.review_ids_to_names_d = self._get_review_ids_to_names_d( c.participating_projects) c.my_work = True c.my_projects = False return render('/accounts/dashboard.mako')
def my_work(self): person = request.environ.get('repoze.who.identity')['user'] c.person = person user = controller_globals._get_user_from_email(c.person.email) if not user: log.error('''\ Hum...fetching user from the database returned False. We need to investigate. Go remove the catch all in controller_globals.py, method _get_user_from_email() to see which OperationalError is being raised ''') # If somehow the user's citation settings variables don't get initialized yet, # then the following 3 if-else blocks should take care of it in order to avoid # any errors due to the values of the variables being null: c.show_journal = user.show_journal if not user.show_journal is None else True if (user.show_authors==True or user.show_authors==False): c.show_authors = user.show_authors else: user.show_authors = True if (user.show_keywords==True or user.show_keywords==False): c.show_keywords = user.show_keywords else: user.show_keywords = True # pull all assignments for this person assignment_q = Session.query(model.Assignment) all_assignments = assignment_q.filter(model.Assignment.user_id == person.id).all() # This process is incredibly slow. Take it out for now and find out # why the .done and .done_so_far field on assignment is off sometimes. #self._set_assignment_done_status(all_assignments) self._clear_this_user_locks(all_assignments) # Build assignment completion status dictionary c.d_completion_status = self._get_assignment_completion_status(all_assignments) c.outstanding_assignments = [a for a in all_assignments if not a.done] # if there's an initial assignment, we'll only show that. assignment_types = [assignment.assignment_type for assignment in \ c.outstanding_assignments] ##### # for any review that has an initial assignment, we will show # *only* that assignment, thereby forcining participants to # finish initial assignments before moving on to other # assignments. fix for issue #5. #### # which reviews have (outstanding) initial assigments? reviews_with_initial_assignments = [] for assignment in c.outstanding_assignments: if assignment.assignment_type == "initial": reviews_with_initial_assignments.append(assignment.project_id) # now remove other (non-initial) assignments for reviews # that have an initial assignment filtered_assignments = [assignment for assignment in c.outstanding_assignments if \ assignment.project_id not in reviews_with_initial_assignments or \ assignment.assignment_type == "initial"] c.outstanding_assignments = filtered_assignments c.finished_assignments = [a for a in all_assignments if a.done] project_q = Session.query(model.Project) c.participating_projects = user.member_of_projects c.review_ids_to_names_d = self._get_review_ids_to_names_d(c.participating_projects) c.my_work = True c.my_projects = False return render('/accounts/dashboard.mako')
def show_reviews(self): q = model.Session.query(model.Project) c.reviews = q.limit(5) return render("/index.mako")
def show_reviews(self): q = model.Session.query(model.Review) c.reviews= q.limit(5) return render("/index.mako")
def help(self): c.root_path = url('/', qualified=True) return render("/static_pages/help.mako")
def citing(self): c.root_path = url('/', qualified=True) return render("/static_pages/citing.mako")