add a setting for local access url paths

This commit is contained in:
koniu 2012-12-19 11:02:56 +00:00
parent 8fe7918ff6
commit 68ca48cf80
3 changed files with 25 additions and 10 deletions

View file

@ -19,7 +19,11 @@
%d = res[i]
<div class="search-result">
<div class="search-result-number"><a href="#r{{d['sha']}}">#{{i+1}}</a></div>
<div class="search-result-title" id="r{{d['sha']}}" title="{{d['abstract']}}"><a href="{{d['url']}}">{{d['label']}}</a></div>
%url = d['url'].replace('file://', '')
%for dr, prefix in config['mounts'].items():
%url = url.replace(dr, prefix)
%end
<div class="search-result-title" id="r{{d['sha']}}" title="{{d['abstract']}}"><a href="{{url}}">{{d['label']}}</a></div>
%if len(d['ipath']) > 0:
<div class="search-result-ipath">[{{d['ipath']}}]</div>
%end
@ -27,13 +31,11 @@
<div class="search-result-author">{{d['author']}}</div>
%end
<div class="search-result-url">
<a href="{{d['url'].replace('/'+d['filename'],'')}}">
%urllabel = d['url'].replace('/'+d['filename'],'').replace('file://','')
%for r in roots:
%urllabel = urllabel.replace(r.rsplit('/',1)[0] + '/' , '')
%end
{{urllabel}}
</a>
%urllabel = d['url'].replace('/'+d['filename'],'').replace('file://','')
%for r in roots:
%urllabel = urllabel.replace(r.rsplit('/',1)[0] + '/' , '')
%end
<a href="{{url.replace('/'+d['filename'],'')}}">{{urllabel}}</a>
</div>
<div class="search-result-date">{{d['time']}}</div>
%for q in shlex.split(query['keywords'].replace("'","\\'")):

View file

@ -1,8 +1,6 @@
%include header title=" / settings"
<div id="settings-box">
<form action="set" method="get">
<b>Prefix</b> <small class="gray">(location of documents on local drive)</small>
<input name="prefix" value={{prefix}}><br><br>
<b>Find similar</b> <small class="gray">(1 or 0, show "squats" and "squatter")</small>
<input name="stem" value={{stem}}><br><br>
<hr>
@ -15,6 +13,11 @@
<b>Folder depth</b> <small class="gray">(number of levels of the folder dropdown)</small>
<input name="dirdepth" value={{dirdepth}}><br><br>
<hr>
<b>Locations</b><br>
%for d in dirs:
<small>{{d}}</small><input name="mount_{{d}}" value={{mounts[d]}}>
%end
<br><br><hr>
<input type="submit" value="Save">
<a href=".."><input type="button" value="Cancel"></a>
</form>

View file

@ -13,6 +13,7 @@ import StringIO
import ConfigParser
import string
import shlex
import urllib
from pprint import pprint
#}}}
#{{{ settings
@ -111,6 +112,11 @@ def get_config():
# get config from cookies or defaults
for k, v in DEFAULTS.items():
config[k] = select([bottle.request.get_cookie(k), v])
# get mountpoints
config['mounts'] = {}
for d in config['dirs']:
name = 'mount_%s' % urllib.quote(d,'')
config['mounts'][d] = select([bottle.request.get_cookie(name), 'file://%s' % d], [None, ''])
return config
#}}}
#{{{ get_dirs
@ -237,8 +243,12 @@ def settings():
@bottle.route('/set')
def set():
config = get_config()
for k, v in DEFAULTS.items():
bottle.response.set_cookie(k, str(bottle.request.query.get(k)), max_age=3153600000)
for d in config['dirs']:
cookie_name = 'mount_%s' % urllib.quote(d, '')
bottle.response.set_cookie(cookie_name, str(bottle.request.query.get('mount_%s' % d)), max_age=3153600000)
bottle.redirect('..')
#}}}
#}}}