我正在从数据库中过滤数据以进行边栏搜索。
我创建了用于搜索的过滤器,但“所有者”过滤器正在使用其他两个过滤器“尼斯分类”和“申请号”。无法正常工作,显示未找到结果。只需检查图像即可获得清晰的主意
代码在python 2.7以下,并且在这里使用了webapp2框架。
所有者过滤结果
“尼斯分类”和“申请号”
sidebar.html
<aside class="main-sidebar">
<section class="sidebar">
<form action="#" method="get" class="sidebar-form">
<h3 style="color: #ffffff; margin-top: 5px;">Filters</h3>
<div class="form-group">
<label>Markname</label>
<input id="s_query" type="text" class="form-control" placeholder="Enter Text">
</div>
<div class="form-group">
<label>Owners</label>
<select id="s_assignees" class="form-control select2" multiple="multiple" style="width: 100%;">
{% for assignee in project.assignees%}
<option value="{{assignee}}">{{assignee}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label> Nice classification </label>
<select id="s_classes" class="form-control select2" multiple="multiple" style="width: 100%;">
{% for cl in project.classes %}
<option value="{{cl}}">{{cl}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label> Application Number </label>
<select id="s_applicationNo" class="form-control select2" multiple="multiple" style="width: 100%;">
{% for ap in project.applicationNo %}
<option value="{{ap}}">{{ap}}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label>Legal Status</label>
<select id="s_legalStatus" class="form-control select2" multiple="multiple" style="width: 100%;">
{% for ls in project.legalStatus%}
<option value="{{ls}}">{{ls}}</option>
{% endfor %}
</select>
</div>
<button type="button" id="s_filter-btn" data-tid="" onclick="filtering_sidebar();" class="btn btn-sm bg-blue">Filter</button>
</form>
</section>
这是filtering_sidebar();查看报告页面上的功能
viewreport.html
function filtering_sidebar(){
var taxonomy_id = '';
var items = [];
$('#s_assignees option:selected').each(function(){ items.push($(this).val()); });
var assignees = items.join(',');
var items1 = [];
$('#s_classes option:selected').each(function(){ items1.push($(this).val()); });
var classes = items1.join(',');
var items2 = [];
$('#s_applicationNo option:selected').each(function(){ items2.push($(this).val()); });
var applicationNo = items2.join(',');
var items3 = [];
$('#s_legalStatus option:selected').each(function(){ items3.push($(this).val()); });
var legalStatus = items3.join(',');
console.log(legalStatus);
var ado = $('#s_a_date').val();
var ad1 = $('#s_a_date_start').val();
var ad2 = $('#s_a_date_end').val();
var tiabTxt = $('#s_query').val();
var flag = $('#s_flag').val();
var win = window.open('/t/filter-report/{{project.pid}}?tid=' + taxonomy_id + '&owners=' + encodeURIComponent(assignees) +
'&classes=' + encodeURIComponent(classes) + '&applicationNo=' + encodeURIComponent(applicationNo) +
'&legalStatus=' + encodeURIComponent(legalStatus) +
'&ado=' + ado + '&ad1=' + ad1 + '&ad2=' + ad2 +
'&query=' + tiabTxt + '&flag=' + flag, '_blank');
if (win) {
win.focus();
} else {
alert('Please allow popups for this website');
}
}
这是我们的处理程序
class FilterTMReportHandler(UserSessionHandler):
@login_required
def get(self, pid):
user = self.user_session_info
pid = str(urllib2.unquote(pid))
tid = self.request.get('tid')
owners = self.request.get('owners')
classes = self.request.get('classes')
applicationNo = self.request.get('applicationNo')
legalStatus = self.request.get('legalStatus')
ado = self.request.get('ado')
ad1 = self.request.get('ad1')
ad2 = self.request.get('ad2')
pdo = self.request.get('pdo')
pd1 = self.request.get('pd1')
pd2 = self.request.get('pd2')
rdo = self.request.get('rdo')
rd1 = self.request.get('rd1')
rd2 = self.request.get('rd2')
query = self.request.get('query')
flag = self.request.get('flag')
filters_dict = dict(owners=owners,
classes=classes,
applicationNo=applicationNo,
legalStatus=legalStatus,
ado=ado, ad1=ad1, ad2=ad2,
pdo=pdo,pd1=pd1,pd2=pd2,
rdo=rdo, rd1=rd1, rd2=rd2,
query=query, flag=flag)
taxonomy_items = []
prj_key = ndb.Key('YoProject', long(pid))
project = YoProject.get_by_key_query(prj_key).get()
file_blob_key = 'NA'
if project.file_blob_key is not None:
file_blob_key = project.file_blob_key
project_dict = dict(name=project.project_name,
pid=pid,
client=project.client_name,
client_spoc_name=project.client_spoc_name,
assignees=project.assignees,
file_blob_key=file_blob_key,
type_=project.type_,
applicationNo=project.applicationNo,
description=project.description,
taxonomy_id=project.taxonomy_id)
taxonomy_key = ndb.Key('Taxonomy', long(project.taxonomy_id))
taxonomy = Taxonomy.get_by_key_query(taxonomy_key).get()
taxonomy_l1s = TaxonomyItem.query(ndb.AND(TaxonomyItem.taxonomy_id == str(project.taxonomy_id), TaxonomyItem.level == 1)).fetch()
for taxonomy_l1 in taxonomy_l1s:
results = []
tm_result_query = TrademarkResult.query(ndb.AND(TrademarkResult.project_id ==str(pid),
TrademarkResult.taxonomy_id == str(project.taxonomy_id),
TrademarkResult.taxonomyItem == taxonomy_l1.name))
if len(owners) != 0:
a_list = owners.split(",")
tm_query_updated = tm_result_query.filter(TrademarkResult.ownerNames.IN(a_list))
else:
tm_query_updated = tm_result_query
if len(classes) != 0:
c_list = classes.split(",")
tm_query_updated = tm_query_updated.filter(TrademarkResult.classes.IN(c_list))
if len(applicationNo) != 0:
ap_list = applicationNo.split(",")
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationNo.IN(ap_list))
if len(legalStatus) != 0:
ls_list = legalStatus.split(",")
tm_query_updated = tm_query_updated.filter(TrademarkResult.legalStatus.IN(ls_list))
if len(ad1) != 0:
if ado == 'after':
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate >= datetime.datetime.strptime(str(ad1), '%m/%d/%Y'))
if ado == 'before':
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate <= datetime.datetime.strptime(str(ad1), '%m/%d/%Y'))
if ado == 'between' and len(ad2) != 0:
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate >= datetime.datetime.strptime(str(ad1), '%m/%d/%Y'))
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate <= datetime.datetime.strptime(str(ad2), '%m/%d/%Y'))
if len(flag) != 0:
tm_query_updated = tm_query_updated.filter(TrademarkResult.flag == int(flag))
tm_result_keys = tm_query_updated.fetch(keys_only=True)
if len(tm_result_keys) == 0:
continue
else:
tm_results = ndb.get_multi(tm_result_keys)
for tm_result in tm_results:
if len(query) != 0:
if query.lower() in tm_result.markName.lower():
if len(tm_result.markImgURLS) > 0:
markImgURL = tm_result.markImgURLS[0]
avail_result = dict(order=tm_result.order,
markName=tm_result.markName,
markImgURLS=markImgURL,
trademarkType=tm_result.trademarkType,
owners=tm_result.ownerNames,
classes=tm_result.classes,
applicationDate=tm_result.applicationDate,
registrationDate=tm_result.registrationDate,
designatedContractedStates=tm_result.designatedContractedStates,
legalStatus=tm_result.legalStatus,
id_=tm_result.key.id(),
applicationNo=tm_result.applicationNo,
registrtionNo=tm_result.registrtionNo,
goodsServices=tm_result.goodsServices[:100] + '...')
else:
avail_result = dict(order=tm_result.order,
markName=tm_result.markName,
trademarkType=tm_result.trademarkType,
owners=tm_result.ownerNames,
applicationDate=tm_result.applicationDate,
registrationDate=tm_result.registrationDate,
applicationNo=tm_result.applicationNo,
legalStatus=tm_result.legalStatus,
id_=tm_result.key.id(),
classes=tm_result.classes,
designatedContractedStates=tm_result.designatedContractedStates,
officeOfOrigin=tm_result.officeOfOrigin,
flag=tm_result.flag,
client_comment=tm_result.client_comment[:50] + '...',
registrtionNo=tm_result.registrtionNo,
goodsServices=tm_result.goodsServices[:100] + '...')
results.append(avail_result)
else:
if len(tm_result.markImgURLS) > 0:
markImgURL = tm_result.markImgURLS[0]
avail_result = dict(order=tm_result.order,
markName=tm_result.markName,
markImgURLS=markImgURL,
trademarkType=tm_result.trademarkType,
owners=tm_result.ownerNames,
classes=tm_result.classes,
applicationDate=tm_result.applicationDate,
registrationDate=tm_result.registrationDate,
designatedContractedStates=tm_result.designatedContractedStates,
legalStatus=tm_result.legalStatus,
id_=tm_result.key.id(),
applicationNo=tm_result.applicationNo,
registrtionNo=tm_result.registrtionNo,
goodsServices=tm_result.goodsServices[:100] + '...')
else:
avail_result = dict(order=tm_result.order,
markName=tm_result.markName,
trademarkType=tm_result.trademarkType,
owners=tm_result.ownerNames,
applicationDate=tm_result.applicationDate,
registrationDate=tm_result.registrationDate,
applicationNo=tm_result.applicationNo,
legalStatus=tm_result.legalStatus,
id_=tm_result.key.id(),
classes=tm_result.classes,
designatedContractedStates=tm_result.designatedContractedStates,
officeOfOrigin=tm_result.officeOfOrigin,
flag=tm_result.flag,
client_comment=tm_result.client_comment[:50] + '...',
registrtionNo=tm_result.registrtionNo,
goodsServices=tm_result.goodsServices[:100] + '...')
results.append(avail_result)
avail_tax_item = dict(name=taxonomy_l1.name,
results=results,
count=len(results),
id_=str(taxonomy_l1.key.id()))
taxonomy_items.append(avail_tax_item)
template_args = {'user': user,
'project': project_dict,
'taxonomy_items': taxonomy_items,
'filters': filters_dict,
'results': results}
self.render_template('filteredtmreport.html', template_args)
只希望搜索过滤器可以工作
答案 0 :(得分:0)
这不是平等的歌声,而是任务吗?
tm_result_keys = tm_query_updated.fetch(keys_only=True)
您要在此处覆盖值吗?
if ado == 'between' and len(ad2) != 0:
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate >= datetime.datetime.strptime(str(ad1), '%m/%d/%Y'))
tm_query_updated = tm_query_updated.filter(TrademarkResult.applicationDate <= datetime.datetime.strptime(str(ad2), '%m/%d/%Y'))
只是尝试通读代码以理解它,希望您可以打印一些输出并在此处查看值?