本文整理汇总了Python中models.session.query函数的典型用法代码示例。如果您正苦于以下问题:Python query函数的具体用法?Python query怎么用?Python query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"
示例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()
示例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)
示例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("	", 1)
row.content = _from_template[0] + _content + "	" + _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("	", 1)
row.content = _from_template[0] + _content + "	" + _from_template[1]
row.submitted_id = "e" + str(existingList.edit_id)
row.submitted = _submitted
session.add(row)
else:
_from_save = existingList.content.split("	", 1)
session.query(bot_comments_anetpool).filter_by(edit_id=existingList.edit_id).update(
{"content": _from_save[0] + _content + "	" + _from_save[1], "submitted": False}
)
session.commit()
示例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)
示例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)
示例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)
示例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)
示例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)
示例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()
示例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()
示例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}
示例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()
示例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()
示例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