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


Python Session.query方法代码示例

本文整理汇总了Python中model.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Session的用法示例。


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

示例1: main_page

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def main_page():
	s = Session()
	meals = s.query(Meal).all()
	products = s.query(Product).all()
	s.close()

	return render_template('beta.html', meals=meals, products=products)
开发者ID:Azurin,项目名称:kk,代码行数:9,代码来源:controller.py

示例2: book_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def book_save(_id):
	status, msg = True, ''
	b_name = request.args.get('name')

	s = Session()
	b = s.query(Book).filter_by(id=_id).first()

	del b.authors[:]

	for key, val in request.args.items():
		if key == 'name':
			continue
		a = s.query(Author).filter_by(id=key).first()
		b.authors.append(a)

	b.name = b_name
	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The book with name %s already exists' % b_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:beta,代码行数:27,代码来源:controller.py

示例3: main_page

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def main_page():
	s = Session()
	books = s.query(Book).all()
	authors = s.query(Author).all()
	s.close()

	return render_template('beta.html', books=books, authors=authors)
开发者ID:Azurin,项目名称:beta,代码行数:9,代码来源:controller.py

示例4: clean_run

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def clean_run(name):
    session = Session()
    run = session.query(Run).filter(Run.name==name).first()
    if run is None:
        return
    session.query(Result).filter(Result.run==run).delete(synchronize_session=False)
    session.commit()
开发者ID:jgraham,项目名称:wptreport,代码行数:9,代码来源:dbhandler.py

示例5: remove_service

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def remove_service(service_id , group_id):
    try :
        session = Session()
        service = session.query(Service).filter(Service.id == service_id).first()
        group = session.query(ServerGroup).filter(ServerGroup.id == group_id).first()
        if server == None or group == None :
            return {"status":-1 , "val":None}
        if server in group.servers :
            group.service.remove(service)
            group.save(session)
        return {"status":0 , "val":None}
    except Exception , msginfo :
        return {"status":-1 , "val":msginfo}
开发者ID:fikgol,项目名称:vulcan,代码行数:15,代码来源:helper.py

示例6: add_service2group

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def add_service2group(service_id,group_id):
    try :
        session = Session()
        service = session.query(Service).filter(Service.id == service_id).first()
        group = session.query(ServerGroup).filter(ServerGroup.id == group_id).first()
        if service == None or group == None :
            return {"status":-1 , "val" : None}
        if service not in group.service :
            group.services.append(service)
            group.save(session)
            return {"status":0 , "val" : None}
        return {"status":-1 , "val":None}
    except Exception , msginfo :
        return {"status":-1 , "val":msginfo}
开发者ID:fikgol,项目名称:vulcan,代码行数:16,代码来源:helper.py

示例7: edit_book

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def edit_book(_id):
	s = Session()
	b = s.query(Book).filter_by(id=_id).first()

	current_authors = b.authors
	authors = s.query(Author).all()

	other_authors = []
	for a in authors:
		if a not in b.authors:
			other_authors.append(a)
	s.close()

	return render_template('edit_book.html', book=b, other_authors=other_authors, current_authors=current_authors)
开发者ID:Azurin,项目名称:beta,代码行数:16,代码来源:controller.py

示例8: edit_meal

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def edit_meal(_id):
	s = Session()
	b = s.query(Meal).filter_by(id=_id).first()

	current_products = b.products
	products = s.query(Product).all()

	other_products = []
	for a in products:
		if a not in b.products:
			other_products.append(a)
	s.close()

	return render_template('edit_meal.html', meal=b, other_products=other_products, current_products=current_products)
开发者ID:Azurin,项目名称:kk,代码行数:16,代码来源:controller.py

示例9: delete_serverGroup

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def delete_serverGroup(group_id):
    session=Session()
    serverGroup=session.query(ServerGroup).filter(ServerGroup.id==group_id).first()
    tasknum=session.query(Task).filter(Task.server_group_id==group_id).count()
    if len(serverGroup.servers):
        return {'status':-1,'val':'serverGroup still has server in it.'}
    if tasknum!=0:
        return {'status':-1,'val':'serverGroup still has been used in task'}
    try:
        if serverGroup==None:
            return {"status":-1,'val':"group is  not in db."}
        serverGroup.delete(session)
        return {"status":0,"val":None}
    except Exception,msginfo:
        return {"status":-1,"val":msginfo}
开发者ID:fikgol,项目名称:vulcan,代码行数:17,代码来源:helper.py

示例10: delete_task

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def delete_task(task_id) :
    try :
        session = Session()
        task = session.query(Task).filter(Task.id == task_id).first()
        taskStatuss = session.query(TaskStatus).filter(TaskStatus.task_id == task_id).all()

        for taskStatus in taskStatuss:
            taskStatus.delete(session)
        if task == None :
            return {"status":-1 , "val":None}
        task.delete(session)
        return {"status":0 , "val":None}
    except Exception , msginfo :
        print msginfo
        return {"status":-1 , "val":msginfo}
开发者ID:fikgol,项目名称:vulcan,代码行数:17,代码来源:helper.py

示例11: new_meal_save

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def new_meal_save():
	status, msg = True, ''

	b_name = request.args.get('name')

	s = Session()
	b = Meal(b_name)

	for key, val in request.args.items():
		if key == 'name':
			continue
		a = s.query(Product).filter_by(id=key).first()
		b.products.append(a)

	s.add(b)

	try:
		s.commit()
	except IntegrityError:
		status = False
		msg = 'The meal with name %s already exists' % b_name

	s.close()

	return json.dumps({'ok': status, 'msg': msg})
开发者ID:Azurin,项目名称:kk,代码行数:27,代码来源:controller.py

示例12: LogHandlerTests

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
class LogHandlerTests(reader.LogHandler):
    def __init__(self):
        self.session = Session()
        self.tests = {(item.test, item.subtest) for item in self.session.query(Test)}
        self.new_tests = []

    def _insert_test(self, test, subtest):
        if (test, subtest) not in self.tests:
            test_obj = {"test": test,
                        "subtest": subtest}
            self.new_tests.append(test_obj)
            self.tests.add((test, subtest))

    def test_status(self, data):
        test = self._insert_test(data["test"], data["subtest"])

    def test_end(self, data):
        self._insert_test(data["test"], None)
        sys.stdout.write("-")
        sys.stdout.flush()

    def suite_end(self, data):
        self.session.bulk_insert_mappings(Test, self.new_tests)
        self.session.commit()
        sys.stdout.write(" committing\n")
开发者ID:jgraham,项目名称:wptreport,代码行数:27,代码来源:dbhandler.py

示例13: draw_table

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
    def draw_table(self):
        s = Session()
        self.orders = s.query(Order).all()
        s.close()
        self.ui.orders_table.clear()
        self.ui.orders_table.setRowCount(1)
        self.ui.orders_table.setColumnCount(5)
        self.ui.orders_table.setHorizontalHeaderLabels([QString.fromUtf8('Номер'), QString.fromUtf8('Поломка'),
                                                        QString.fromUtf8('Дата приемки'), QString.fromUtf8('Клиент'),
                                                        QString.fromUtf8('Статус')])
        #self.ui.orders_table.resizeColumnsToContents()

        for order in self.orders:
            data = []
            data.append(str(order.id))
            data.append(QString.fromUtf8(order.device))
            data.append(str(order.get_ordered_date()))
            data.append(QString.fromUtf8(order.get_client().get_fio()))
            data.append(QString.fromUtf8(order.get_status(1).to_string()))
            for i in range(0,5):
                tableitem = QTableWidgetItem()
                tableitem.setText(data[i])
                tableitem.font = QFont("Arial", 10)
                tableitem.font.setBold(True)
                tableitem.textcolor = QColor("black")
                self.ui.orders_table.setItem(self.ui.orders_table.rowCount() - 1,i,tableitem)
            self.ui.orders_table.setRowCount(self.ui.orders_table.rowCount()+1)
        self.ui.orders_table.resizeColumnsToContents()
开发者ID:frolova,项目名称:sc,代码行数:30,代码来源:OrdersWidget.py

示例14: initialize_device

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def initialize_device():
    """
    Set up the Device info into the database.
    By this time, the HardwareDefinition and SoftwareDefinition
    entries must be entered.
    """
    session = Session()

    hd = session.query(HardwareDefinition).one()
    sd = session.query(SoftwareDefinition).one()

    device = Device(id=hd.serial_number,
                    interior_sensor=hd.interior_sensor,
                    exterior_sensor=hd.exterior_sensor)

    device.hardware_version = hd.hardware_version
    device.software_version = sd.software_version
    device.database_service = True  # database always set to True
    device.device_service = sd.device_service
    device.grainbin_service = sd.grainbin_service
    session.add(device)

    # set grainbin info
    if sd.grainbin_service:
        grainbins = initialize_grainbin(device.id, hd.grainbin_reader_count)
        device.grainbin_count = len(grainbins)
        session.add_all(grainbins)

    session.commit()
    session.close()
    return
开发者ID:nstoik,项目名称:farm_device,代码行数:33,代码来源:db_manage.py

示例15: on_message

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import query [as 别名]
def on_message(msg, server):
    text = msg.get("text", "")
    match = re.findall(r"!status( .*)?", text)
    if not match: return

    session = Session()
    
    try:
        realm = session.query(Realm).filter(Realm.name == wowconfig["realm"]).one()
        
        status = u"Currently *{0}* is ".format(realm.name)
        
        if realm.online:
            status += "online (last check: {0})".format(
                humanize.naturaltime(realm.lastchecked)
            )
            status += "\n\n*Battleground status*:\n```"
            for area in realm.areas:
                status += "{0} : {1} controlled : {2} : next in {3}\n".format(
                   area.name,
                   area.faction,
                   area.status,
                   humanize.naturaldelta(area.next),
                )
            status += "```"
        else:
            status += "offline (last check: {0}, last seen: {1})".format(
                humanize.naturaltime(realm.lastchecked), 
                humanize.naturaltime(realm.lastseen)
            )
        
        return status 
    except NoResultFound:
        return u"No status known on *{0}*".format(wowconfig["realm"])
开发者ID:Michaeljmeyer3,项目名称:slackcraft,代码行数:36,代码来源:status.py


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