Skip to content

Commit

Permalink
adding save display settigs button to search results page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark MacGillivray committed Dec 3, 2011
1 parent 766ec72 commit 949c564
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
1 change: 1 addition & 0 deletions bibserver/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def upload_from_web(self, request):
raise ValueError('You must provide a collection label')
collection = {
'label': request.values['collection'],
'description': request.values.get('description',""),
'source': source,
'format': format
}
Expand Down
13 changes: 11 additions & 2 deletions bibserver/iomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def get_safe_terms_object(self):
terms[term.replace(self.config.facet_field,'')] = theterm
return terms

def get_path_params(self,myargs):
def get_path_params(self,myargs={}):
if not myargs:
myargs = self.args
param = '/' + self.path + '?' if (self.path != '') else self.config.base_url + '?'
if 'q' in myargs:
param += 'q=' + myargs['q'] + '&'
Expand Down Expand Up @@ -139,7 +141,7 @@ def get_keys(self):
if isinstance(record[key],basestring):
self.keys.append({"key":key,"sortable":True})
else:
self.keys.append({"key":key,"sortable":False})
#self.keys.append({"key":key,"sortable":False})
if not isinstance(record[key],list):
record[key] = [record[key]]
for each in record[key]:
Expand Down Expand Up @@ -252,6 +254,13 @@ def get_meta(self):
else:
return ""

def get_coll_recordcount(self,collid):
coll = bibserver.dao.Collection.get(collid)
if coll:
return len(coll)
else:
return ''

def get_record_version(self,recordid):
record = bibserver.dao.Record.get(recordid)
if not record:
Expand Down
1 change: 1 addition & 0 deletions bibserver/templates/account/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h4><a href="/{{current_user['id']}}/{{coll.id}}">{{coll['label']}}</a></h4>
</td>
<td>
<p>{{coll['records']}} records.<br />
{{coll['description']}}<br />
<a href="/collections/{{coll.id}}?display_settings=edit">Customise the display</a> of this collection</a>.<br />
<a href="/collections/{{coll.id}}">Edit the metadata</a> of this collection</a>.<br />
{% if 'source' in coll and coll['source'] %}
Expand Down
3 changes: 2 additions & 1 deletion bibserver/templates/collections/list-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
{% for i in range(io.set()|length) %}
<div class="list_result_{{'odd' if i % 2 == 0 else 'even'}}">
<h3><a href="/{{io.get_str(io.set()[i], 'owner')|safe}}/{{io.get_str(io.set()[i], 'id')|safe}}">{{io.get_str(io.set()[i], 'label')|safe}}</a></h3>
<p>{{io.get_str(io.set()[i], 'description')|safe}}</p>
<ul>
<li>id: {{io.get_str(io.set()[i], 'id')|safe}}</li>
<li>owner: {{io.get_str(io.set()[i], 'owner')|safe}}</li>
<li>records: {{io.get_str(io.set()[i], 'records')|safe}}</li>
<li>records: {{io.get_coll_recordcount(io.set()[i]['id'])}}</li>
<li>created: {{io.get_str(io.set()[i], 'created')|safe}}</li>
<li>modified: {{io.get_str(io.set()[i], 'modified')|safe}}</li>
<li>source: <a href="{{io.get_str(io.set()[i], 'source')|safe}}">{{io.get_str(io.set()[i], 'source')|safe}}</a></li>
Expand Down
30 changes: 17 additions & 13 deletions bibserver/templates/home/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
<div class="hero-unit">
<h1>Welcome to BibSoup!</h1>
<p>BibSoup makes it easy to find, manage and share bibliographies.</p>
<p><a class="btn primary large" href="/content/howto">Learn more &raquo;</a></p>
</div>

<!-- Example row of columns -->
<div class="row">
<div class="span-one-third column">
<h2>Search records</h3>
<p>Search shared collections and records. Find material relevant to your interests.</p>
<p><a href="/search" class="btn">Search now &raquo;</a></p>
</div>
{% if upload == "YES" %}
<div class="span-one-third column">
<h2>Upload your collection</h2>
<h2>Upload a collection</h2>
<p>Build collections for your group, for your research, for your students; share them with everyone. Collections can be created from your own files, such as BibTex, and then be managed online or re-exported.</p>
<p><a href="/upload" class="btn">Upload now &raquo;</a></p>
</div>
{% endif %}
<div class="span-one-third column">
<h2>Recent Collections</h2>
<h2>Search all records</h3>
<p>Search shared collections and records. Find material relevant to your interests.</p>
<p><a href="/search" class="btn">Search now &raquo;</a></p>
<h2>Create a new collection</h3>
<p>(coming soon) Search available records, select your favourites to creat a new collection - or, combine two or more collections to make a super-collection.</p>
<h2>Share collection admin</h3>
<p>(coming soon) Collaboratively create and edit a collection by giving other users admin rights.</p>
</div>
<div class="span-two-thirds column">
<h2>Browse recent Collections</h2>
{% if colls %}
<ul id="collections">
<table class="zebra-striped">
{% for i in range(colls|length) %}
<li><a href="/{{colls[i]['owner']}}/{{colls[i]['id']}}">{{colls[i]['id']}}</a> ({{colls[i]['records']}})</li>
<tr><td>
<h3><a href="/{{colls[i]['owner']}}/{{colls[i]['id']}}">{{colls[i]['label']}}</a> <small>({{colls[i]|length}} records)</small></h3>
<p>{{colls[i]['description']}}</p>
</td></tr>
{% endfor %}
</ul>
</table>
{% endif %}
<p><a href="/collections" class="btn">See more &raquo;</a></p>
</div>
Expand Down
3 changes: 1 addition & 2 deletions bibserver/templates/search/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
//if ( facets.indexOf(','+facet, facets.length - facet.length) !== -1 ) {
// jQuery('#showfacets').val(facets.replace(facet+',',''));
//}
alert(facets.indexOf(','+facet, facets.length - facet.length - 1));
if ( facets.indexOf(','+facet, facets.length - facet.length - 1) !== -1 ) {
jQuery('#showfacets').val(facets.replace(','+facet,''));
} else {
Expand Down Expand Up @@ -129,7 +128,7 @@
</div>

{% if edit and True %}
<a class="btn info" id="save_display" href="">save current display settings as the default view for this collection</a>
<a class="btn info" id="save_display" href="{{io.get_path_params()}}&savedisplay=true">save current display settings as the default view for this collection</a>
{% endif %}

</div>
2 changes: 1 addition & 1 deletion bibserver/templates/search/facet-sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
jQuery('ul.facet_value').each(function() {
var sorts = '<div class="facet_alpha">';
var sorted = jQuery(this).children();
sorted.tsort();
sorted = sorted.tsort();
var letters = [];
var count = 0;
sorted.children('a').each(function() {
Expand Down
2 changes: 2 additions & 0 deletions bibserver/templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ <h2>Upload your collection</h2>

<br /><span class="upload_label">name your collection:</span> <input id="collection" type="text" name="collection" />

<br /><br /><span class="upload_label">provide a description:</span> <textarea id="description" name="description"></textarea>

<p>
(or <a class="frompc" href="">upload from your PC</a>)
</p>
Expand Down
29 changes: 22 additions & 7 deletions bibserver/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def standard_authentication():
@app.route('/')
def home():
# get list of available collections
colls = None
try:
result = bibserver.dao.Collection.query(q="*",sort={"created":{"order":"desc"}})
if result["hits"]["total"] != 0:
colls = [i["_source"] for i in result["hits"]["hits"]]
colls = [bibserver.dao.Collection.get(i['_source']['id']) for i in result["hits"]["hits"]]
except:
colls = None
counts = None
pass
return render_template('home/index.html', colls=colls, upload=config["allow_upload"] )

@app.route('/account/<user>')
Expand Down Expand Up @@ -272,7 +272,7 @@ def search(path=''):
return render_template('search/index.html', io=io, edit=edit)

def dosearch(path,searchtype='Record'):
showkeys = request.values.get('showkeys',None)
# set query info
args = {"terms":{}}
if 'from' in request.values:
args['start'] = request.values.get('from')
Expand All @@ -292,8 +292,9 @@ def dosearch(path,searchtype='Record'):
if ' OR ' in request.values['q']:
args['default_operator'] = 'OR'
if ' AND ' in request.values['q']:
args['default_operator'] = 'AND'

args['default_operator'] = 'AND'

# set implicit keys / collections
incollection = {}
implicit_key = False
implicit_value = False
Expand Down Expand Up @@ -335,11 +336,25 @@ def dosearch(path,searchtype='Record'):
if implicit_key:
args['terms'][implicit_key+config["facet_field"]] = [implicit_value]

# save current display settings if requested
if incollection:
if 'savedisplay' in request.values:
if auth.collection.update(current_user, incollection):
if 'display_settings' not in incollection:
incollection['display_settings'] = {}
incollection['display_settings']['facet_fields'] = args['facet_fields']
for item in incollection['display_settings']['facet_fields']:
if item['key'].endswith(config["facet_field"]):
item['key'] = item['key'].replace(config["facet_field"],'')
incollection.save()
flash('Display settings saved.')


if searchtype == 'Record':
results = bibserver.dao.Record.query(**args)
else:
results = bibserver.dao.Collection.query(**args)
return bibserver.iomanager.IOManager(results, args, showkeys, incollection, implicit_key, implicit_value, path, request.values.get('showopts',''))
return bibserver.iomanager.IOManager(results, args, request.values.get('showkeys',None), incollection, implicit_key, implicit_value, path, request.values.get('showopts',''))

def outputJSON(results, coll=None, record=False, collection=False):
'''build a JSON response, with metadata unless specifically asked to suppress'''
Expand Down
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
{
"key":"author",
"order":"term",
"size":1000
"size":1000,
"display_name":"authors"
},
{
"key":"year",
Expand Down

0 comments on commit 949c564

Please sign in to comment.