Closed rafaelrdealmeida closed 3 years ago
Hi
I'm using the bottle and I'm not able to disregard the escapes in the search interface.
the search is done correctly whether I enter the escape (I convert it) or not.
However, the escape appears for the user in the search box (I just wanted to change the box, in the url the escape could continue)
already tried:
my difficulty is dealing with the escape in the search box (I don't want it to appear). Any indication of what I'm doing wrong?
@bottle.route('/') @bottle.view('main') def main(): config = get_config() return {'dirs': get_dirs(config['dirs'], config['dirdepth']), 'query': get_query(), 'sorts': SORTS, 'config': config} @bottle.route('/results') @bottle.view('results') def results(): config = get_config() query = get_query() qs = query_to_recoll_string(query) msg(query) from unidecode import unidecode query['query'] = urllib.parse.unquote(query['query']) # query['query'] = ''.join([c if ord(c) < 128 else '?' for c in qs]).replace( # "????", "?").replace("??", "?") res, nres, timer = recoll_search(query) extra_res = [] # variavel que sera retornada for result in res: e_m = extra_metadata_func([result["url"].split("/")[-1]]) for k, v in e_m[0].items(): result[k] = v if "ano_publicacao" in result and result["ano_publicacao"] != '': try: obj_data = datetime.datetime.strptime( result["ano_publicacao"], "%Y-%m-%d") result['ano_publicacao_check'] = obj_data # result["ano_publicacao"] = obj_data.strftime('%a, %d %b %Y %H:%M:%S -0500') result["ano_publicacao"] = obj_data.strftime('%Y') except: pass # Aqui devemos usar a config. E apontar para a rota correta filepath = result["url"].replace("file://", "") commonpath = os.path.commonpath([RECOLLWEB_ROOTDIR, filepath]) if commonpath == RECOLLWEB_ROOTDIR: # TODO: Fazer URL encode / decode basefp = filepath.replace(commonpath + os.sep, "") url_formatada = os.path.join(RECOLLWEB_PREFIX, basefp) else: # TODO: Separar esse trecho de código em uma funcao url_formatada = filepath result["url_formatada"] = url_formatada # Cast para defaultdict extra_res.append(defaultdict(str, **result)) if config['maxresults'] == 0: config['maxresults'] = nres if config['perpage'] == 0: config['perpage'] = nres msg(qs) return {'res': extra_res, 'time': timer, 'query': query, 'dirs': get_dirs(config['dirs'], config['dirdepth']), 'qs': qs, 'sorts': SORTS, 'config': config, 'query_string': bottle.request.query_string, 'nres': nres, 'config': config}
pages.tpl
%q = dict(query) %def page_href(page): %q['page'] = page %q['query'] = q['query'].split(' dir:')[0] %return './results?%s' % urllib.parse.urlencode(q) %end %if nres > 0: %import math, urllib %npages = int(math.ceil(nres/float(config['perpage']))) %if npages > 1: <div id="pages"> <a title="First" class="page" href="{{page_href(1)}}">«</a> <a title="Previous" class="page" href="{{page_href(max(1,query['page']-1))}}">‹</a> %offset = int(query['page']) %for p in range(max(1,offset), min(offset+10,npages+1)): %if p == query['page']: %cls = "page current" %else: %cls = "page" %end <a href="{{page_href(p)}}" class="{{cls}}">{{p}}</a> %end <a title="Next" class="page" href="{{page_href(min(npages, query['page']+1))}}">›</a> <a title="Last" class="page" href="{{page_href(npages)}}">»</a> </div> %end %end
%import re <div id="searchbox"> <form action="results" method="get"> <table id="form"> <tr> <td width="50%"> <b>Query</b> <input tabindex="0" type="search" name="query" value="{{query['query']}}" autofocus><br><br> <input type="submit" value="Search"> <a href="./" tabindex="-1"><input type="button" value="Reset"></a> <!-- comment SETTINGS <a href="settings" tabindex="-1"><input type="button" value="Settings"></a> --> </td> <td width="30%"> <b>Folder</b><br> <select id="folders" name="dir"> %for d in sorted(dirs, key=str.lower): %style = "margin-left: %dem" % (2*d.count('/')) %if d in query['dir']: <option style="{{style}}" selected value="{{d}}">{{re.sub('.+/','', d)}}</option> %else: <option style="{{style}}" value="{{d}}">{{re.sub('.+/','', d)}}</option> %end %end </select><br> <!-- comment DATES <b>Dates</b> <small class="gray">YYYY[-MM][-DD]</small><br> <input name="after" value="{{query['after']}}" autocomplete="off"> — <input name="before" value="{{query['before']}}" autocomplete="off"> --> </td> <td> <b>Sort by</b> <select name="sort"> %for s in sorts: %if query['sort'] == s[0]: <option selected value="{{s[0]}}">{{s[1]}}</option> %else: <option value="{{s[0]}}">{{s[1]}}</option> %end %end </select><br> <b>Order</b> <select name="ascending"> %if int(query['ascending']) == 1: <option value="0">Descending</option> <option value="1" selected>Ascending</option> %else: <option value="0" selected>Descending</option> <option value="1">Ascending</option> %end </select> </td> </tr> </table> <input type="hidden" name="page" value="1" /> </form> </div> <!-- vim: fdm=marker:tw=80:ts=4:sw=4:sts=4:et:ai -->
In the end it was our mistakes here
Hi
I'm using the bottle and I'm not able to disregard the escapes in the search interface.
the search is done correctly whether I enter the escape (I convert it) or not.
However, the escape appears for the user in the search box (I just wanted to change the box, in the url the escape could continue)
already tried:
my difficulty is dealing with the escape in the search box (I don't want it to appear). Any indication of what I'm doing wrong?
pages.tpl