本文整理汇总了Python中standup.database.get_session函数的典型用法代码示例。如果您正苦于以下问题:Python get_session函数的具体用法?Python get_session怎么用?Python get_session使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_session函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_destroy
def test_destroy(self):
"""Test removing a team."""
response = self.client.post(self.url, data=self.data)
eq_(response.status_code, 200)
db = get_session(self.app)
eq_(0, db.query(Team).count())
示例2: statusize
def statusize():
"""Posts a status from the web."""
db = get_session(current_app)
user_id = session.get('user_id')
if not user_id:
return forbidden('You must be logged in to statusize!')
user = db.query(User).get(user_id)
message = request.form.get('message', '')
if not message:
return page_not_found('You cannot statusize nothing!')
status = Status(user_id=user.id, content=message, content_html=message)
project = request.form.get('project', '')
if project:
project = db.query(Project).filter_by(id=project).first()
if project:
status.project_id = project.id
# TODO: reply handling
db.add(status)
db.commit()
# Try to go back from where we came.
referer = request.headers.get('referer', url_for('status.index'))
redirect_url = request.form.get('redirect_to', referer)
return redirect(redirect_url)
示例3: globals
def globals():
db = get_session(app)
ctx = dict()
# Projects, teams and current user
ctx['projects'] = db.query(Project).order_by(Project.name)
ctx['teams'] = db.query(Team).order_by(Team.name)
ctx['weeks'] = get_weeks()
ctx['current_user'] = None
if session and 'user_id' in session:
user = db.query(User).get(session['user_id'])
if user:
ctx['current_user'] = user
# Time stuff
ctx['today'] = date.today()
ctx['yesterday'] = date.today() - timedelta(1)
# CSRF
def csrf_field():
return ('<div style="display: none;">'
'<input type="hidden" name="_csrf_token" value="%s">'
'</div>' % csrf._get_token())
ctx['csrf'] = csrf_field
return ctx
示例4: test_new_profile_create_missing_data
def test_new_profile_create_missing_data(self):
"""Test profile creation attempts with missing data."""
db = get_session(self.app)
u = db.query(User)
# No email
data = {'email': '', 'username': 'new-username',
'github_handle': 'test-handle', 'name': 'Test User'}
response = self.client.post('/profile/new/', data=data)
eq_(response.status_code, 200)
eq_(u.count(), 0)
# No username
data = {'email': '[email protected]', 'username': '',
'github_handle': 'test-handle', 'name': 'Test User'}
response = self.client.post('/profile/new/', data=data)
eq_(response.status_code, 200)
eq_(u.count(), 0)
# No name
data = {'email': '[email protected]', 'username': 'new-username',
'github_handle': 'test-handle', 'name': ''}
response = self.client.post('/profile/new/', data=data)
eq_(response.status_code, 200)
eq_(u.count(), 0)
# No GitHub handle
data = {'email': '[email protected]', 'username': 'new-username',
'github_handle': '', 'name': 'Test User'}
response = self.client.post('/profile/new/', data=data)
eq_(response.status_code, 302)
eq_(u.count(), 1)
示例5: new_profile
def new_profile():
"""Create a new user profile"""
if (not (session or request.method == 'POST') or 'user_id' in session
or not ('email' in session or 'email' in request.form)):
return redirect(url_for('status.index'))
data = MultiDict()
try:
data['email'] = session['email']
session.pop('email')
except KeyError:
pass
if request.method == 'POST':
data = request.form
form = ProfileForm(data)
if request.method == 'POST' and form.validate():
db = get_session(current_app)
u = User(name=data['name'], email=data['email'],
username=data['username'], slug=data['username'],
github_handle=data['github_handle'])
db.add(u)
db.commit()
session['email'] = u.email
session['user_id'] = u.id
flash('Your profile was created.', 'success')
return redirect(url_for('status.index'))
return render_template('users/new_profile.html', form=form)
示例6: profile
def profile():
"""Shows the user's profile page."""
db = get_session(current_app)
user_id = session.get('user_id')
if not user_id:
return forbidden('You must be logged in to see a profile!')
user = db.query(User).get(user_id)
if request.method == 'POST':
data = request.form
else:
data = MultiDict(user.dictify())
form = ProfileForm(data)
if request.method == 'POST' and form.validate():
user.name = data['name']
user.username = data['username']
user.slug = data['username']
user.github_handle = data['github_handle']
db.add(user)
db.commit()
flash('Your profile was updated.', 'success')
return render_template('users/profile.html', form=form)
示例7: test_update
def test_update(self):
"""Test update team info."""
response = self.client.post(self.url, data=self.data)
eq_(response.status_code, 200)
db = get_session(self.app)
team = db.query(Team).filter_by(slug=self.data['slug']).one()
eq_(team.name, self.data['name'])
示例8: saving_func
def saving_func(*args, **kwargs):
save = kwargs.pop('save', False)
ret = func(*args, **kwargs)
if save:
db = get_session(current_app)
db.add(ret)
db.commit()
return ret
示例9: index_feed
def index_feed():
"""Output every status in an Atom feed."""
db = get_session(current_app)
statuses = db.query(Status).filter_by(reply_to=None)\
.order_by(desc(Status.created))
return render_feed('All status updates', statuses)
示例10: update_team
def update_team():
"""Update a team's info."""
db = get_session(current_app)
try:
team = _get_team()
except ApiError, e:
return api_error(e.code, str(e))
示例11: timesince_last_update
def timesince_last_update():
"""Get the time since the users last update in seconds"""
db = get_session(current_app)
try:
user = _get_user()
except ApiError, e:
return api_error(e.code, str(e))
示例12: destroy_team
def destroy_team():
"""Removes a team."""
db = get_session(current_app)
try:
team = _get_team()
except ApiError, e:
return api_error(e.code, str(e))
示例13: create_team_member
def create_team_member():
"""Add a user to the team."""
db = get_session(current_app)
try:
team = _get_team()
user = _get_user()
except ApiError, e:
return api_error(e.code, str(e))
示例14: destroy_team_member
def destroy_team_member():
"""Remove a user from the team."""
db = get_session(current_app)
try:
team = _get_team()
user = _get_user()
except ApiError, e:
return api_error(e.code, str(e))
示例15: test_no_name
def test_no_name(self):
"""Test team creation with no name."""
self.data.pop('name')
response = self.client.post(self.url, data=self.data)
eq_(response.status_code, 200)
db = get_session(self.app)
team = db.query(Team).filter_by(slug=self.data['slug']).one()
eq_(team.name, self.data['slug'])