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


Python meta.DBSession类代码示例

本文整理汇总了Python中pyrtos.models.meta.DBSession的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: file_create

    def file_create(self):
        """ New file view. Method for both post and get requests. """

        form = FileCreateForm(self.request.POST,
                              csrf_context=self.request.session)

        if self.request.method == 'POST' and form.validate():
            f = File()
            form.populate_obj(f)

            """ If file. Yes this method works without a file. """
            upload = self.request.POST.get('file')
            try:
                f.filename = f.make_filename(upload.filename)
                f.filemime = f.guess_mime(upload.filename)
                f.write_file(upload.file)
            except Exception:
                self.request\
                    .session.flash('File %s created but no file added' %
                                   (f.title), 'status')

            f.user_id = authenticated_userid(self.request)
            DBSession.add(f)
            self.request.session.flash('File %s created' %
                                       (f.title), 'success')
            return HTTPFound(location=self.request.route_url('files'))
        return {'title': 'New file',
                'form': form,
                'action': 'file_new'}
开发者ID:plastboks,项目名称:Pyrtos,代码行数:29,代码来源:file.py

示例2: all_queryed

    def all_queryed(cls,
                    ucid,
                    qry=False,
                    cats=False,
                    creds=False,
                    total_only=False,
                    fromdate=False,
                    todate=False,):
        base = DBSession.query(Invoice)
        if total_only:
            base = DBSession.query(func.sum(Invoice.amount).label('a_sum'))\

        base = base.join(Invoice.category)\
                   .join(Invoice.creditor)\
                   .filter(not_(and_(Category.private == True,
                                     Category.user_id != ucid)))

        """ if argument add filter(s)."""
        if qry:
            qry = "%"+qry+"%"
            base = base.filter(Invoice.title.like(qry))
        if cats:
            for c in cats:
                base = base.filter(Category.id == c.id)
        if creds:
            for c in creds:
                base = base.filter(Creditor.id == c.id)
        if fromdate:
            base = base.filter(Invoice.due >= fromdate)
        if todate:
            base = base.filter(Invoice.due <= todate)
        return base
开发者ID:plastboks,项目名称:Pyrtos,代码行数:32,代码来源:invoice.py

示例3: with_category

 def with_category(cls, id, total_only=False):
     if total_only:
         return DBSession.query(func.sum(Expenditure.amount)
                                    .label('a_sum'))\
                         .filter(and_(Expenditure.archived == False,
                                      Expenditure.category_id == id))\
                         .first()
     return DBSession.query(Expenditure)\
                     .filter(and_(Expenditure.category_id == id,
                                  Expenditure.archived == False)).all()
开发者ID:plastboks,项目名称:Pyrtos,代码行数:10,代码来源:expenditure.py

示例4: with_category_all_unpaid

    def with_category_all_unpaid(cls, cid, total_only=False):
        base = DBSession.query(Invoice)

        if total_only:
            base = DBSession.query(func.sum(Invoice.amount).label('a_sum'))\

        base = base.filter(and_(Invoice.category_id == cid,
                                Invoice.archived == False,
                                Invoice.paid == None))\
                   .all()
        return base
开发者ID:plastboks,项目名称:Pyrtos,代码行数:11,代码来源:invoice.py

示例5: creditor_create

    def creditor_create(self):
        """ New creditors. Method for both post and get request."""

        form = CreditorCreateForm(self.request.POST, csrf_context=self.request.session)

        if self.request.method == "POST" and form.validate():
            c = Creditor()
            form.populate_obj(c)
            c.user_id = authenticated_userid(self.request)
            DBSession.add(c)
            self.request.session.flash("Creditor %s created" % (c.title), "success")
            return HTTPFound(location=self.request.route_url("creditors"))
        return {"title": "New creditor", "form": form, "action": "creditor_new"}
开发者ID:plastboks,项目名称:Pyrtos,代码行数:13,代码来源:creditor.py

示例6: with_category_paid

    def with_category_paid(cls, cid, year, month, total_only=False):
        base = DBSession.query(Invoice)

        if total_only:
            base = DBSession.query(func.sum(Invoice.amount).label('a_sum'))\

        base = base.filter(and_(Invoice.category_id == cid,
                                Invoice.archived == False,
                                Invoice.paid != None))\
                   .filter(extract('year', Invoice.due) == year)\
                   .filter(extract('month', Invoice.due) == month)\
                   .all()
        return base
开发者ID:plastboks,项目名称:Pyrtos,代码行数:13,代码来源:invoice.py

示例7: user_restore

    def user_restore(self):
        """ Restore user, returns redirect. """

        id = int(self.request.matchdict.get('id'))

        u = User.by_id(id)
        if not u:
            return HTTPNotFound()

        u.archived = False
        DBSession.add(u)
        self.request.session.flash('User %s restored' %
                                   (u.email), 'status')
        return HTTPFound(location=self.request.route_url('users_archived'))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:14,代码来源:user.py

示例8: _initTestingDB

def _initTestingDB(makeuser=False):
    engine = create_engine('sqlite://')
    Base.metadata.create_all(engine)
    DBSession.configure(bind=engine)
    if makeuser:
        m = BPM()
        hashed = m.encode(u'1234567')
        with transaction.manager:
            user = User(email=u'[email protected]',
                        password=hashed,
                        group='admin',
                        )
            DBSession.add(user)
    return DBSession
开发者ID:plastboks,项目名称:Pyrtos,代码行数:14,代码来源:base.py

示例9: creditor_restore

    def creditor_restore(self):
        """ Restore creditor, returns redirect. """

        id = int(self.request.matchdict.get("id"))

        c = Creditor.by_id(id)
        if not c:
            return HTTPNotFound()
        """ Authorization check. """
        if c.private and c.user_id is not authenticated_userid(self.request):
            return HTTPForbidden()

        c.archived = False
        DBSession.add(c)
        self.request.session.flash("Creditor %s restored" % (c.title), "status")
        return HTTPFound(location=self.request.route_url("creditors_archived"))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:16,代码来源:creditor.py

示例10: all_active

 def all_active(cls, request, id=False):
     if not id:
         id = authenticated_userid(request)
     return DBSession.query(Creditor)\
                     .filter(Creditor.archived == False)\
                     .filter(not_(and_(Creditor.private == True,
                                       Creditor.user_id != id)))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:7,代码来源:creditor.py

示例11: all_private

 def all_private(cls, request, id=False):
     if not id:
         id = authenticated_userid(request)
     return DBSession.query(Category)\
                     .filter(and_(Category.user_id == id,
                                  Category.private == True,
                                  Category.archived == False))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:7,代码来源:category.py

示例12: category_create

    def category_create(self):
        """ New category view. """

        form = CategoryCreateForm(self.request.POST,
                                  csrf_context=self.request.session)

        if self.request.method == 'POST' and form.validate():
            c = Category()
            form.populate_obj(c)
            c.user_id = authenticated_userid(self.request)
            DBSession.add(c)
            self.request.session.flash('Category %s created' %
                                       (c.title), 'success')
            return HTTPFound(location=self.request.route_url('categories'))
        return {'title': 'New category',
                'form': form,
                'action': 'category_new'}
开发者ID:plastboks,项目名称:Pyrtos,代码行数:17,代码来源:category.py

示例13: category_archive

    def category_archive(self):
        """ Archive category, returns redirect. """

        id = int(self.request.matchdict.get('id'))

        c = Category.by_id(id)
        if not c:
            return HTTPNotFound()

        """ Authorization check. """
        if c.private and c.user_id is not authenticated_userid(self.request):
            return HTTPForbidden()

        c.archived = True
        DBSession.add(c)
        self.request.session.flash('Category %s archived' %
                                   (c.title), 'status')
        return HTTPFound(location=self.request.route_url('categories'))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:18,代码来源:category.py

示例14: user_archive

    def user_archive(self):
        """ Archive user, returns redirect. """

        a = authenticated_userid(self.request)
        id = int(self.request.matchdict.get('id'))

        """ User one (1) is a bit special..."""
        if id is 1:
            return HTTPNotFound()

        u = User.by_id(id)
        if not u:
            return HTTPNotFound()

        u.archived = True
        DBSession.add(u)
        self.request.session.flash('User %s archived' %
                                   (u.email), 'status')
        return HTTPFound(location=self.request.route_url('users'))
开发者ID:plastboks,项目名称:Pyrtos,代码行数:19,代码来源:user.py

示例15: user_create

    def user_create(self):
        """ New user view. Method handles both post and get
        requests.
        """

        form = UserCreateForm(self.request.POST,
                              csrf_context=self.request.session)

        if self.request.method == 'POST' and form.validate():
            u = User()
            form.populate_obj(u)
            u.password = u.pm.encode(form.password.data)
            DBSession.add(u)
            self.request.session.flash('User %s created' %
                                       (u.email), 'success')
            return HTTPFound(location=self.request.route_url('users'))
        return {'title': 'New user',
                'form': form,
                'action': 'user_new'}
开发者ID:plastboks,项目名称:Pyrtos,代码行数:19,代码来源:user.py


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