本文整理汇总了Python中query.Query.getData方法的典型用法代码示例。如果您正苦于以下问题:Python Query.getData方法的具体用法?Python Query.getData怎么用?Python Query.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.getData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selectDiffColumns
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
def selectDiffColumns(self, recievedData):
""" given a dic of data recieve about a record
compare it to the data in the DB
remove entries in the recieved dictionary that already exist
return truncated dict"""
query = Query()
where = "book.book_id =" + str(self.book_id)
recordData = query.getData("edit", where)
remove = []
for col, val in recordData[0].items():
if val == "":
recordData[0][col] = None
else:
recordData[0][col] = str(val)
for col in recievedData:
if recievedData[col] == recordData[0][col]:
remove.append(col)
for col in remove:
del recievedData[col]
return recievedData
示例2: Report
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
class Report():
def __init__(self, report):
self.query = Query()
self.forms = HTMLutils()
self.author = Author()
self.when = WhenRead()
self.report = report
self.columns = loadYaml('columns')
self.pages = loadYaml('pages')
if report == 'add':
page = 'edit'
else:
page = report
self.display_names = self.getDisplayNames(page)
def buildMain(self, where= None, order_by = None):
'''build table seen on main page using all books. Accepts optional
arguements to filter (search) or sort. Returns table'''
bookData = self.query.getData('main', where, order_by)
# start html table
mainTable = HtmlTable(border=1, cellpadding=3)
# table header, uses display name and enables sorting
table_header = ['#']
for field, name in self.display_names:
sortflag =''
if field == order_by:
sortflag = ' ^'
js = "document.form1.order_by.value='%s';" % field
js += "document.form1.submit();"
h = '<a onclick="javascript:%s">%s%s</a>' % (js, name, sortflag)
table_header.append(h)
mainTable.addHeader(table_header)
# table body- build a numbered row for each record
i = 0
activity = 'view'
for rec in bookData:
i += 1
href = '<a href="detail.py?book_id=%d&activity=%s">%s'\
% (rec['book_id'], activity, rec['title'])
# format date
if rec['date']:
dates = '<br>'.join(['<nobr>%s</nobr>' % d.strip()
for d in rec['date'].split('&')])
else:
dates = '-'
mainTable.addRow(\
[i,
href,
rec['author'] or '' ,
rec['notes' ] ,
dates])
return mainTable.getTable()
def buildDetail(self, book_id):
'''Static table to view book details'''
where = 'book.book_id =' + str(book_id)
bookData = self.query.getData('record', where)
detailTable = HtmlTable(border=1, cellpadding=3)
detailTable.addHeader(['Field', 'Entry'])
for column, display in self.display_names:
for rec in bookData:
if rec[column]:
data = rec[column]
else:
data = '-'
detailTable.addRow([display, data])
return detailTable.getTable()
def buildRecordForm (self, book_id = None):
'''responisble for building the composite form for book records by
gathering all data, calling necessary helper methods, and adding all
sub-forms together. Form has 3 sub-parts:
(1) the book form which holds all data fields with a 1:1 relationship
to a book_id
(2) the edit author from which itself has 2 sub-parts:
(2a) the remove author feature (currently inactive)
(2b) add author section which defaults to hidden
(3) the dates read add/remove (currently inactive)
form is used for adding records and editing records. If a book_id is
recieved current values for that book_id are pulled from the DB and
used to pre-populate form fields (used for edit). Otherwise the form
is built blank, with no default values (used for add).
#.........这里部分代码省略.........
示例3: Query
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
'title' : title,
'series' : series,
'notes' : notes,
'series_num' : series_num,
'owner_status.status' : owner_status,
'published' : published,
'type' : type,
'when_read.when_read' : when_read
}
for k, v in formDict.items():
if v == 'None':
v = 'NULL'
query = Query()
where = 'book_id =' + book_id
results = query.getData('record', where)
#build html_header
if activity == 'edit':
header = 'Edit Record'
else:
header = 'Book Record'
html_header= '''
<html>
<h3>%s</h3>
'''%header
#build debug_section
debug_section = 'Book ID = %s' % (book_id)
示例4: Report
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
class Report():
def __init__(self, report):
self.query = Query()
self.forms = HTMLutils()
self.report = report
self.columns = loadYaml('columns')
self.pages = loadYaml('pages')
if report == 'add':
page = 'edit'
else:
page = report
self.display_names = self.getDisplayNames(page)
def buildMain(self, where= None, order_by = None):
'''build table seen on main page using all books. Accepts optional
arguements to filter (search) or sort. Returns table'''
bookData = self.query.getData('main', where, order_by)
# start html table
mainTable = HtmlTable(border=1, cellpadding=3)
# table header, uses display name and enables sorting
table_header = ['#']
for field, name in self.display_names:
sortflag =''
if field == order_by:
sortflag = ' ^'
js = "document.form1.order_by.value='%s';" % field
js += "document.form1.submit();"
h = '<a onclick="javascript:%s">%s%s</a>' % (js, name, sortflag)
table_header.append(h)
mainTable.addHeader(table_header)
# table body- build a numbered row for each record
i = 0
activity = 'view'
for rec in bookData:
i += 1
href = '<a href="detail.py?book_id=%d&activity=%s">%s'\
% (rec['book_id'], activity, rec['title'])
# format dates
if rec['date']:
dates = '<br>'.join(['<nobr>%s</nobr>' % d.strip()
for d in rec['date'].split('&')])
else:
dates = '-'
mainTable.addRow(\
[i,
href,
rec['author'] or '' ,
rec['notes' ] ,
dates])
return mainTable.getTable()
def buildDetail(self, book_id):
'''Static table to view book details'''
where = 'book.book_id =' + str(book_id)
bookData = self.query.getData('record', where)
detailTable = HtmlTable(border=1, cellpadding=3)
detailTable.addHeader(['Field', 'Entry'])
for column, display in self.display_names:
for rec in bookData:
if rec[column]:
data = rec[column]
else:
data = '-'
detailTable.addRow([display, data])
return detailTable.getTable()
def buildBookForm(self, book_id= None):
'''dynamic composite table. made of three parts:
the book form which has all form elements for all elements related to
the book except the date, and author which a book has a many:many
relationship with.
Date is a sperate form (INACTIVE currently)
Author has two parts: the edit author table holds all author
information, eventually removing authors will be enabled. It has a
sub table of add author.
Accepts a book id, finds relevant data, calls helper methods.
Returns composite table of all above sub-parts.
'''
if self.report == 'edit' and book_id != None:
where = 'book.book_id =' + str(book_id)
bookData = self.query.getData('edit', where)
#.........这里部分代码省略.........
示例5: record
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
class LibraryHTML:
'''Given an actitvity to prefrom on a record (view, edit, add)
return a list of html building blocks to paint the page'''
def __init__(self, book_id, activity):
self.book_id = book_id
self.activity = activity
self.connection = getDictConnection()
self.conn = getConnection()
#bring in yaml metadata
metadata = Metadata()
self.columns = metadata.loadYaml('columns')
self.pages = metadata.loadYaml('pages')
self.list = []
if activity == 'edit':
self.header = 'Edit Record'
self.page = 'edit'
self.new_activity = 'update'
self.button_text = 'Submit'
self.show_blank = ''
self.cancel_button_text = 'Cancel'
self.cancel_button_address = 'detail.py?book_id=%s&activity=view'\
%book_id
if activity == 'view':
self.header = 'Book Record'
self.page = 'record'
self.new_activity = 'edit'
self.button_text = 'Edit'
self.show_blank = '-'
self.cancel_button_address = 'main.py'
self.cancel_button_text = 'Back to Catalog'
if activity == 'add':
self.header = 'Enter New Record'
self.page = 'edit'
self.new_activity = 'submit_new'
self.button_text = 'Save'
self.show_blank = ''
self.cancel_button_address = 'main.py'
self.cancel_button_text = 'Cancel'
# build the right query for the page and bring in the data
if activity != 'add':
self.query = Query()
where = 'book.book_id =' + str(self.book_id)
self.recordData = self.query.getData(self.page, where)
def build_html_header(self):
html_header= '''
<html>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script src = "jquery_1.11.1.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script>
$(function(){
$("#autoC").autocomplete({source: %s});
});
</script>
<h3>%s</h3>
'''% (self.list, self.header)
return html_header
def build_form_header(self):
form_header = '''
<form method = "POST" action = "detail.py" name = "form">
'''
return form_header
def build_report(self):
metadata = Metadata()
display_data = metadata.interrogateMetadata(self.page, 'display')
display_names = display_data['col_attributes']
table = HtmlTable(border=1, cellpadding=3)
table.addHeader(['Field', 'Entry'])
for column, display in display_names:
if self.activity == 'view':
# make a simple table, not a form
for rec in self.recordData:
if rec[column]:
data = rec[column]
else:
data = self.show_blank
table.addRow([display, data])
else:
#use methods to build form
form = self.columns[column][0]['form_type']
# type_method = {'text' :' self.getTextField(column)',
# 'drop_down' : 'self.getDropDown(column)',
# 'radio_static': 'self.getStaticRadio(column)',
# 'autocomplete': 'self.getAutocomplete(column)'
# }
if form == 'text':
form_field =self.getTextField(column)
#.........这里部分代码省略.........
示例6: HtmlTable
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import getData [as 别名]
table = HtmlTable(border=1, cellpadding=3)
table.addHeader(['Field', 'Entry'])
loadyaml = LoadYaml()
columns = loadyaml.loadYaml('columns')
pages = loadyaml.loadYaml('pages')
query = Query()
where = 'book.book_id =' + book_id
if activity == 'view':
page = 'record'
if activity == 'edit':
page = 'edit'
results = query.getData(page, where)
ordered_rows= []
for item in pages[page]:
ordered_rows.append(item)
# making a list of lists holding the col name and display names
# make a list of cols that need drop down menus
display_names = []
drop_down = []
for item in ordered_rows:
x = []
x.append(item)
for element in columns[item]:
if 'foreign_table' in element:
drop_down.append(item)