本文整理汇总了Python中abstrackr.model.meta.Session类的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clear_this_user_locks
def _clear_this_user_locks(self, all_assignments):
priorities_locked_by_this_user = self._get_all_priorities_locked_by_this_user(all_assignments)
for p in priorities_locked_by_this_user:
p.is_out = 0
p.locked_by = None
Session.add(p)
Session.commit()
示例2: customize_citations
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")
示例3: __call__
def __call__(self, environ, start_response):
"""Invoke the Controller"""
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
try:
return WSGIController.__call__(self, environ, start_response)
finally:
Session.remove()
示例4: create_account_handler
def create_account_handler(self):
'''
Note that the verification goes on in model/form.py.
'''
# create the new user; post to db via sqlalchemy
new_user = model.User()
new_user.username = request.params['username']
new_user.fullname = " ".join([request.params['first_name'], request.params['last_name']])
new_user.experience = request.params['experience']
new_user._set_password(request.params['password'])
new_user.email = request.params['email']
# These are for citation settings,
# initialized to True to make everything in the citation visible by default.
new_user.show_journal = True
new_user.show_authors = True
new_user.show_keywords = True
Session.add(new_user)
Session.commit()
# send out an email
greeting_message = """
Hi, %s.\n
Thanks for signing up at abstrackr (%s). You
should be able to sign up now with username %s (only you know your password).
This is just a welcome email to say hello, and that we've got your email.
Should you ever need to reset your password, we'll send you instructions
to this email. In the meantime, happy screening!
-- The Brown EPC.
""" % (new_user.fullname, url('/', qualified=True), new_user.username)
try:
self.send_email_to_user(new_user, "welcome to abstrackr", greeting_message)
except:
# this almost certainly means we're on our Windows dev box :)
pass
###
# log this user in programmatically (issue #28)
rememberer = request.environ['repoze.who.plugins']['cookie']
identity = {'repoze.who.userid': new_user.username}
response.headerlist = response.headerlist + \
rememberer.remember(request.environ, identity)
rememberer.remember(request.environ, identity)
# if they were originally trying to join a review prior to
# registering, then join them now. (issue #8).
if 'then_join' in request.params and request.params['then_join'] != '':
redirect(url(controller="review", action="join", review_code=request.params['then_join']))
else:
redirect(url(controller="account", action="login"))
示例5: change_password
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")
示例6: my_projects
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')
示例7: _get_users_labels_for_assignment
def _get_users_labels_for_assignment(self, project_id, user_id, assignment_id):
"""Returns a user's list of labels across a specific project"""
labels_q = Session.query(model.Label)
labels = labels_q.filter_by(project_id=project_id,
user_id=user_id,
assignment_id=assignment_id).all()
return labels
示例8: _get_username_from_id
def _get_username_from_id(self, id):
if id == CONSENSUS_USER:
return "consensus"
if id not in self.user_dict:
user_q = Session.query(model.User)
self.user_dict[id] = user_q.filter(model.User.id == id).one().username
return self.user_dict[id]
示例9: _build_tags_dict
def _build_tags_dict(self):
tags = Session.query(model.Tag, model.TagType).filter(model.Tag.citation_id.in_(self.all_citations)).join(model.TagType, model.Tag.tag_id == model.TagType.id).all()
for citation_id in self.all_citations:
if citation_id not in self.citation_to_tags_dict:
self.citation_to_tags_dict[citation_id] = []
for tag in tags:
self.citation_to_tags_dict[tag[0].citation_id].append(tag[1].text)
示例10: _get_notes_for_citation
def _get_notes_for_citation(self, citation_id, user_id):
notes_q = Session.query(model.Note)
notes = notes_q.filter(and_(\
model.Note.citation_id == citation_id,
model.Note.creator_id == user_id)).all()
if len(notes) > 0:
return notes[0]
return None
示例11: gen_token_to_reset_pwd
def gen_token_to_reset_pwd(self, user):
# generate a random token for the user to reset their password; stick
# it in the database
make_token = lambda N: ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
reset_pwd_q = Session.query(model.ResetPassword)
existing_tokens = [entry.token for entry in reset_pwd_q.all()]
token_length=10
cur_token = make_token(token_length)
while cur_token in existing_tokens:
cur_token = make_code(token_length)
reset = model.ResetPassword()
reset.token = cur_token
reset.user_email = user.email
Session.add(reset)
Session.commit()
return cur_token
示例12: _row_unique
def _row_unique(row, project_id, user_id):
try:
labeledfeatures = Session.query(model.LabeledFeature).\
filter_by(term = row[0]).\
filter_by(label = row[1]).\
filter_by(project_id = project_id).\
filter_by(user_id = user_id).all()
except IndexError, e:
return False, 2
示例13: confirm_password_reset
def confirm_password_reset(self, id):
token = str(id)
reset_pwd_q = Session.query(model.ResetPassword)
# we pull all in case they've tried to reset their pwd a few times
# by the way, these should time-expire...
matches = reset_pwd_q.filter(model.ResetPassword.token == token).all()
if len(matches) == 0:
return """
Hrmm... It looks like you're trying to reset your password, but I can't match the provided token.
Please go back to the email that was sent to you and make sure you've copied the URL correctly.
"""
user = controller_globals._get_user_from_email(matches[0].user_email)
for match in matches:
Session.delete(match)
user._set_password(token)
Session.commit()
return '''
ok! your password has been set to %s (you can change it once you've logged in).\n
<a href="%s">log in here</a>.''' % (token, url('/', qualified=True))
示例14: _get_all_priorities_locked_by_this_user
def _get_all_priorities_locked_by_this_user(self, all_assignments):
locked_priorities = []
for a in all_assignments:
user_id = a.user_id
project_id = a.project_id
priorities_q = Session.query(model.Priority).filter_by(project_id=project_id).\
filter_by(locked_by=user_id)
priorities = priorities_q.all()
locked_priorities.extend([p for p in priorities])
return list(set(locked_priorities))
示例15: _build_notes_dict
def _build_notes_dict(self):
notes = Session.query(model.Note).filter(model.Note.citation_id.in_(self.all_citations)).all()
for citation_id in self.all_citations:
if citation_id not in self.citation_to_notes_dict:
self.citation_to_notes_dict[citation_id] = {}
for labeler in self.all_labelers:
self.citation_to_notes_dict[citation_id][labeler.username] = None
for note in notes:
self.citation_to_notes_dict[note.citation_id][self._get_username_from_id(note.creator_id)] = note