• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python session.query函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: mod

def mod():
    global __HEXDIGEST__
    if request.method == "GET":
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if mess is None or mess.approved == True:
            flash('No new messages to edit')
            return render_template('edit.html')
        dct = json.loads(mess.everything)
        form = EditForm()
        form.subject.data = dct.get('subject')
        form.text.data = dct.get('body-plain')
        form.approved.data = mess.approved
        return render_template('edit.html', form=form) 
    else:
        form = EditForm(request.form)
        mess = session.query(EmailMessage).get(__HEXDIGEST__)
        if form.approved.data == True:
            send_message(form.data)
            mess.approved = True
            session.add(mess)
            session.commit()
            flash('message sent')
            return render_template('edit.html')
        flash("bad form")
        return "bad form"
开发者ID:NSkelsey,项目名称:verdant,代码行数:25,代码来源:app.py


示例2: terminal_visual

def terminal_visual():
    print_line_count = 0
    print colored('TIMELORD v.0.0.1', 'white', attrs=['bold'])
    print_line_count += 1

    # work
    todays_work = session.query(func.sum(WorkTime.work)).filter(WorkTime.datetime >= datetime.date.today()).one()
    if todays_work:
        todays_work = todays_work[0]
    if not todays_work:
        todays_work = 0

    print colored('work: ', 'cyan') + \
            colored(str(todays_work / 60.), 'green') + \
            colored(' hrs', 'cyan')
    print_line_count += 1

    # tasks
    print colored('task progress:', 'cyan')
    print_line_count += 1
    todays_progress = session.query(Milestone).filter(Milestone.datetime >= datetime.date.today()).all()
    if todays_progress:
        for tp in todays_progress:
            print colored('    ' + str(tp), 'yellow')
            print_line_count += 1
    else:
        print colored('    none', 'red')
        print_line_count += 1

    for i in range(print_line_count):
        print '\033[1A' + '\r',
        sys.stdout.flush()
开发者ID:maxvitek,项目名称:timelord,代码行数:32,代码来源:monitor.py


示例3: wemo

def wemo(request, command=None, device=None):
    if not command:
        raise NoCommandSpecified()
    if device:
        device = urllib.unquote(device)

    if command == 'ls':
        devices = session.query(distinct(WemoTimeSeries.device_name)).all()
        response = '<p>'
        for d in devices:
            response += "'" + d[0] + "'</br>"
        response += '</p>'
    
    elif command == 'on':
        wemo = WemoCC().on(device)
        response = '<p>' + device + ' turned on.</p>'
    
    elif command == 'off':
        wemo = WemoCC().off(device)
        response = '<p>' + device + ' turned off.</p>'

    elif command == 'completion':
        completion = []
        devices = session.query(distinct(WemoTimeSeries.device_name)).all()
        for d in devices:
            completion.append(d.lower().replace(' ', '_'))
        response = json.dumps(completion)

    return HttpResponse(response)
开发者ID:maxvitek,项目名称:homespun_site,代码行数:29,代码来源:views.py


示例4: addEdit

    def addEdit(self, _thread_id, _content, _submitted=False):
        existingList = (
            session.query(bot_comments_anetpool)
            .filter_by(thread_id=_thread_id)
            .order_by(desc(bot_comments_anetpool.edit_id))
            .first()
        )

        if existingList is None:
            row = bot_comments_anetpool()
            row.thread_id = _thread_id
            _from_template = self.anetpool_template.split("&#009;", 1)
            row.content = _from_template[0] + _content + "&#009;" + _from_template[1]
            row.submitted = _submitted
            session.add(row)
        else:
            if len(existingList.content) + len(_content) >= 10000:
                row = bot_comments_anetpool()
                row.thread_id = _thread_id
                _from_template = self.anetpool_template.split("&#009;", 1)
                row.content = _from_template[0] + _content + "&#009;" + _from_template[1]
                row.submitted_id = "e" + str(existingList.edit_id)
                row.submitted = _submitted
                session.add(row)
            else:
                _from_save = existingList.content.split("&#009;", 1)
                session.query(bot_comments_anetpool).filter_by(edit_id=existingList.edit_id).update(
                    {"content": _from_save[0] + _content + "&#009;" + _from_save[1], "submitted": False}
                )
        session.commit()
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:30,代码来源:polarbytebot.py


示例5: item_edit

def item_edit(item_title):
    categories = session.query(Category).all()
    item = session.query(Item).filter_by(
        title=item_title).one()
    user = session.query(User).filter_by(
        id=login_session.get('user_id')).one()
    if item.user is not None and item.user.id != user.id:
        return redirect(url_for('home'))
    if request.method == 'POST':
        form = vh.ItemForm(request.form, item)
        file_storage_err = vh.store_item_pic(
            item, request.files['picture'])
        if (not form.validate() or file_storage_err is not None):
            return render_template('item_edit.html',
                                   form=form,
                                   file_err=file_storage_err)
        form.populate_obj(item)
        try:
            session.add(item)
            session.commit()
        except ValueError as e:
            return "Database validation error: " + str(e)
        except SQLAlchemyError as e:
            # todo: log error, but don't display detailed message
            # for security reasons
            return "Database error: " + str(e)
        return redirect(url_for('home'))
    else:
        form = vh.ItemForm(obj=item)
        return render_template('item_edit.html',
                               form=form,
                               file_err=None)
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:32,代码来源:views.py


示例6: project_change

    def project_change(self, name, index, mode):
        project = session.query(Project).filter(Project.name == self.early_p_id.get())[0]
        # What tasks does this project have?
        tasks = session.query(Task).filter(Task.project == project.id)

        if tasks.count() > 0:
            self._fill_tasks(tasks)
开发者ID:hellsgate1001,项目名称:Time-tracker,代码行数:7,代码来源:addearliertask.py


示例7: list_responses

def list_responses(account_name):
    a = session.query(Account).filter_by(name=account_name).first()
    responses = session.query(Response).filter_by(from_email=a.email).all()
    if len(responses) == 0:
        message = "This User has made no public statements."
        return render_template('list_posts.html', responses=responses, account=a, message=message)
    return render_template('list_posts.html', responses=responses, account=a)
开发者ID:NSkelsey,项目名称:pcomment,代码行数:7,代码来源:serv.py


示例8: home

def home():
    categories = session.query(Category).all()
    # todo: most recent
    items = session.query(Item).order_by(desc(Item.last_update))
    return render_template('home.html',
                           session=login_session,
                           categories=categories,
                           items=items)
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:8,代码来源:views.py


示例9: test_add_tag

 def test_add_tag(self):
     p = session.query(Photo).filter_by(filename='bee.jpg').one()
     self.assertEqual(p.tags, [])
     p.add_tag('Family')
     self.assertEqual(p.tags, [session.query(Tag).filter_by(name='Family').one()])
     self.assertEqual(p.tagnames, ['Family'])
     p.add_tag('family')
     self.assertEqual(len(p.tags), 1)
开发者ID:leplatrem,项目名称:pyfspot,代码行数:8,代码来源:tests.py


示例10: delete_test

def delete_test():
    tom = session.query(Teacher).get(1)
    print tom.students
    session.delete(tom)
    # lucy = session.query(Student).get(1)
    # session.delete(lucy)
    session.commit()
    print session.query(Teacher).all()
    print session.query(Student).all()
开发者ID:EmuxEvans,项目名称:py_learn,代码行数:9,代码来源:test.py


示例11: get_members

 def get_members(remove = None):
     """ 获取所有成员
     Arguments:
         `remove`    -   排除成员
     """
     remove_email = get_email(remove)
     if remove:
         return session.query(Member).filter(Member.email != remove_email).all()
     return session.query(Member).all()
开发者ID:Jack1007,项目名称:clubot,代码行数:9,代码来源:logics.py


示例12: serialize_catalog

def serialize_catalog():
    categories = session.query(Category).all()
    categories_json = [c.serialize for c in categories]
    for category_json in categories_json:
        items = session.query(Item).filter_by(
            category_id=category_json['id']).all()
        if len(items) > 0:
            category_json['Item'] = [
                i.serialize for i in items]
    return {'Category': categories_json}
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:10,代码来源:view_helpers.py


示例13: __delete_old_data

 def __delete_old_data(self, pdbs):
     """When recalculate=True, delete all data from pdb_redundant_nucleotides
     and set pdb_analysis_status to None in the redundant_nts column"""
     session.query(RedundantNucleotide).filter(RedundantNucleotide.pdb_id.in_(pdbs)).delete(
         synchronize_session="fetch"
     )
     for statusObj in session.query(PdbAnalysisStatus).filter(PdbAnalysisStatus.id.in_(pdbs)).all():
         statusObj.redundant_nts = None
         session.merge(statusObj)
     session.commit()
开发者ID:BGSU-RNA,项目名称:RNA-3D-Hub-core,代码行数:10,代码来源:RedundantNucleotidesLoader.py


示例14: __delete_old_data

 def __delete_old_data(self, pdbs):
     """When recalculate=True, delete all data from pdb_best_chains_and_models
     and set pdb_analysis_status to None in the best_chains_and_models column"""
     session.query(PdbBestChainsAndModels).filter(PdbBestChainsAndModels.pdb_id.in_(pdbs)).delete(
         synchronize_session="fetch"
     )
     for statusObj in session.query(PdbAnalysisStatus).filter(PdbAnalysisStatus.id.in_(pdbs)).all():
         statusObj.best_chains_and_models = None
         session.merge(statusObj)
     session.commit()
开发者ID:BGSU-RNA,项目名称:RNA-3D-Hub-core,代码行数:10,代码来源:BestChainsAndModelsLoader.py


示例15: list

    def list(self):
        address_list = []
        if "limit" in self.data:
            query = session.query(Endereco).limit(self.data["limit"])
        else:
            query = query = session.query(Endereco)

        for q in query:
            address_list.append(to_json(q))

        return address_list
开发者ID:alfredocdmiranda,项目名称:challenge-cep,代码行数:11,代码来源:api.py


示例16: items_list

def items_list(category_name):
    category = session.query(Category).filter_by(
        name=category_name).one()
    categories = session.query(Category).all()
    items = session.query(Item).filter_by(
        category_id=category.id).all()
    return render_template('items.html',
                           session=login_session,
                           categories=categories,
                           category=category,
                           items=items)
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:11,代码来源:views.py


示例17: updateLatestObjectIds

 def updateLatestObjectIds(self, _last_comment_id, _last_submission_id):
     lastIds = session.query(subreddit).filter_by(website="reddit").first()
     if lastIds == None:
         row = subreddit()
         row.website = "reddit"
         row.last_comment = _last_comment_id
         row.last_submission = _last_submission_id
         session.add(row)
     else:
         session.query(subreddit).filter_by(website="reddit").update(
             {"last_submission": _last_submission_id, "last_comment": _last_comment_id}
         )
开发者ID:networkjanitor,项目名称:polarbytebot,代码行数:12,代码来源:polarbytebot.py


示例18: home

def home(request):

    session.rollback()
    session.commit()

    filter_date = datetime.datetime.utcnow() - datetime.timedelta(seconds=60)
    
    wemo_device_count = session.query(func.count(distinct(WemoTimeSeries.device_name))).first()[0]
    wemo = session.query(WemoTimeSeries).order_by(WemoTimeSeries.datetime.desc()).limit(wemo_device_count).all()

    hue_device_count = session.query(func.count(distinct(HueTimeSeries.device_name))).first()[0]
    hue = session.query(HueTimeSeries).order_by(HueTimeSeries.datetime.desc()).limit(hue_device_count).all()

    nest = session.query(NestTimeSeries).order_by(NestTimeSeries.datetime.desc()).limit(1).first()

    apex = session.query(ApexTimeSeries).filter(ApexTimeSeries.value != None).filter(ApexTimeSeries.datetime>filter_date).all()
   
    roomba_device_count = session.query(func.count(distinct(RoombaTimeSeries.device_name))).first()[0]
    roomba = session.query(RoombaTimeSeries).order_by(RoombaTimeSeries.datetime.desc()).limit(roomba_device_count).all()
    
    f = Flower()
    flower = f.get_data(.001)[-1]
    
    return render(request, template_name='home.html', dictionary={'wemo': wemo, 
                                                                  'hue': hue, 
                                                                  'nest': nest,
                                                                  'apex': apex,
                                                                  'roomba': roomba,
                                                                  'flower': flower,
                                                                 })
开发者ID:maxvitek,项目名称:homespun_site,代码行数:30,代码来源:views.py


示例19: get_create_user

def get_create_user(name, email):
    """ get or create user record """
    try:
        user = session.query(User).filter_by(
            email=email).one()
    # todo: catch specific sqlalchemy exception
    except:
        new_user = User(name=name,
                        email=email)
        session.add(new_user)
        session.commit()
        user = session.query(User).filter_by(
            email=email).one()
    return user.id
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:14,代码来源:view_helpers.py


示例20: login

def login():
    if request.method == 'POST':
        if request.form.get('sign-in') is not None:
            try:
                user = session.query(User).filter_by(
                    email=request.form.get('email')).one()
            except NoResultFound:
                return ("no user record found for email '%s'" %
                        request.form.get('email'))
            if user.password is None:
                return ("user account created with third-party service"
                        "<br>"
                        "sign up locally or sign in with third-party")
            if check_password_hash(user.password,
                                   request.form.get('password')):
                login_session['user_id'] = user.id
            else:
                return "bad password"
        else:
            # request.form.get('sign-up') is not None
            if ((request.form.get('password') !=
                 request.form.get('password-confirm'))):
                return "passwords don't match"
            try:
                user = session.query(User).filter_by(
                    email=request.form.get('email')).one()
            except NoResultFound:
                user = User(email=request.form.get('email'))
            if user.password is not None:
                return "user already registered"
            user.password = generate_password_hash(
                request.form.get('password'))
            user.name = request.form.get('name')
            session.add(user)
            session.commit()
            user = session.query(User).filter_by(
                email=request.form.get('email')).one()
            login_session['user_id'] = user.id
        return redirect(url_for('home'))
    else:
        state = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(32)
        )
        login_session['state'] = state
        return render_template(
            'login.html',
            state=state,
            G_CLIENT_ID=G_CLIENT_ID,
            GH_CLIENT_ID=app.config['GITHUB_CLIENT_ID'])
开发者ID:ransomw,项目名称:udacity-fsnd-p3,代码行数:50,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python course_details.CourseDetails类代码示例发布时间:2022-05-27
下一篇:
Python session.commit函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap