当前位置: 首页>>代码示例>>Python>>正文


Python database.get_session函数代码示例

本文整理汇总了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())
开发者ID:chinna1986,项目名称:standup,代码行数:7,代码来源:test_api2.py

示例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)
开发者ID:Ms2ger,项目名称:standup,代码行数:32,代码来源:views.py

示例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
开发者ID:Ms2ger,项目名称:standup,代码行数:27,代码来源:main.py

示例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)
开发者ID:Ms2ger,项目名称:standup,代码行数:32,代码来源:test_users.py

示例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)
开发者ID:Ms2ger,项目名称:standup,代码行数:34,代码来源:views.py

示例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)
开发者ID:Ms2ger,项目名称:standup,代码行数:27,代码来源:views.py

示例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'])
开发者ID:chinna1986,项目名称:standup,代码行数:8,代码来源:test_api2.py

示例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
开发者ID:chinna1986,项目名称:standup,代码行数:8,代码来源:__init__.py

示例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)
开发者ID:Ms2ger,项目名称:standup,代码行数:8,代码来源:views.py

示例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))
开发者ID:Ms2ger,项目名称:standup,代码行数:8,代码来源:views.py

示例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))
开发者ID:Ms2ger,项目名称:standup,代码行数:8,代码来源:views.py

示例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))
开发者ID:Ms2ger,项目名称:standup,代码行数:8,代码来源:views.py

示例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))
开发者ID:Ms2ger,项目名称:standup,代码行数:9,代码来源:views.py

示例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))
开发者ID:Ms2ger,项目名称:standup,代码行数:9,代码来源:views.py

示例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'])
开发者ID:chinna1986,项目名称:standup,代码行数:9,代码来源:test_api2.py


注:本文中的standup.database.get_session函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。