Skip to content

Commit

Permalink
Merge branch 'release/v1.0.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdejoode committed Jul 6, 2015
2 parents 8d145bf + 4591962 commit efae30f
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 87 deletions.
8 changes: 5 additions & 3 deletions clic/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ def concordances():
def fetchKeywords(args):
keyworder = Keywords()
args = processArgs(args, 'keywords')
keywords = keyworder.list_keywords(args[0], args[1], args[2], args[3], args[4])
return {'keywords' : keywords}
keywordlist = keyworder.list_keywords(args[0], args[1], args[2], args[3], args[4])
return keywordlist
# return {'keywords' : keywords}

@cache.cache('clusters')
def fetchClusters(args):
cluster = Clusters()
args = processArgs(args, 'clusters')
clusterlist = cluster.list_clusters(args[0], args[1])
return {'clusters' : clusterlist}
return clusterlist
# return {'clusters' : clusterlist}

@cache.cache('concordances')
def fetchConcordance(args):
Expand Down
71 changes: 54 additions & 17 deletions clic/web/index.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
from __future__ import absolute_import ## help python find modules within clic package (see John H email 09.04.2014)
from flask import Flask, render_template, url_for, redirect, request
from clic.web.api import api

from clic.web.api import api, fetchClusters, fetchKeywords
from clic.chapter_repository import ChapterRepository

app = Flask(__name__, static_url_path='')
app.register_blueprint(api, url_prefix='/api')

from clic.chapter_repository import ChapterRepository
#TODO delete:
# from flask_debugtoolbar import DebugToolbarExtension
# app.debug = True
# app.config["SECRET_KEY"] = "jadajajada"
# toolbar = DebugToolbarExtension(app)

'''
Application routes
'''

#==============================================================================
# Home, about, docs, 404
#==============================================================================
@app.route('/', methods=['GET'])
def index():
return redirect(url_for('concordances')) # current home page. may change

@app.route('/about/', methods=['GET'])
def about():
return render_template("about.html")

@app.route('/documentation/', methods=['GET'])
def documentation():
return render_template("documentation.html")

@app.errorhandler(404)
def page_not_found(error):
return render_template('page-not-found.html'), 404

#==============================================================================
# Concordances
#==============================================================================
@app.route('/concordances/', methods=['GET'])
def concordances():
if 'terms' in request.args.keys(): # form was submitted
return render_template("concordance-results.html")
else:
return render_template("concordance-form.html")

#==============================================================================
# Keywords
#==============================================================================
@app.route('/keywords/', methods=['GET'])
def keywords():
if 'testIdxGroup' in request.args.keys(): # form was submitted
Expand All @@ -31,41 +59,51 @@ def keywords():
testIdxMod = request.args.get('testIdxMod')
selectWords = "whole"

args = request.args
keywords_result = fetchKeywords(args)

return render_template("keywords-results.html",
IdxGroup=IdxGroup,
testCollection=testCollection,
testIdxMod=testIdxMod,
selectWords=selectWords)
selectWords=selectWords,
keywords=keywords_result)

else:
return render_template("keywords-form.html")

#==============================================================================
# Clusters
#==============================================================================
@app.route('/clusters/', methods=['GET'])
def clusters():
if 'testIdxGroup' in request.args.keys(): # form was submitted

# get parameters for redirecting to the concordance page
IdxGroup = request.args.get('testIdxGroup')
# FIXME this might not work when dealing with only a few books,
# rather than an entire subcorpus, in that case better use:
# collection = args.getlist('testCollection') ## args is a
## multiDictionary: use .getlist() to access individual books
testCollection = request.args.get('testCollection')
testIdxMod = request.args.get('testIdxMod')
selectWords = "whole"

args = request.args
clusters_result = fetchClusters(args)

return render_template("clusters-results.html",
IdxGroup=IdxGroup,
testCollection=testCollection,
testIdxMod=testIdxMod,
selectWords=selectWords)
selectWords=selectWords,
clusters=clusters_result)

else:
return render_template("clusters-form.html")

@app.route('/about/', methods=['GET'])
def about():
return render_template("about.html")

@app.route('/documentation/', methods=['GET'])
def documentation():
return render_template("documentation.html")

#==============================================================================
# Chapters
#==============================================================================
@app.route('/chapter/<book>/<int:number>/')
@app.route('/chapter/<book>/<int:number>/<int:word_index>/<search_term>/')
def chapterView(number, book, word_index = None, search_term = None):
Expand All @@ -78,7 +116,6 @@ def chapterView(number, book, word_index = None, search_term = None):

return render_template("chapter-view.html", content=chapter, book_title=book_title)


@app.errorhandler(404)
def page_not_found(error):
return render_template('page-not-found.html'), 404
# TODO delete?
#if __name__ == '__main__':
# app.run()
Binary file added clic/web/static/img/AHRC10th_horiz_RGB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added clic/web/static/img/AHRC10th_horiz_small_RGB.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 27 additions & 33 deletions clic/web/templates/clusters-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@
{% endblock %}

{% block title %}
Concordance Search {{ super() }}
Clusters {{ super() }}
{% endblock %}

{% block body %}
<h2 class="without-pills">Clusters Results</h2>

<div id="resultsWrap">
<div id="tableContainer"></div>
<div id="tableContainer">
<table style="width: 0px; cursor:pointer" aria-describedby="dataTableClusters_info" class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableClusters">
<thead>
<tr role="row">
<th aria-label="No" style="width: 0px;" colspan="1" rowspan="1" class="sorting_asc">No</th>
<th aria-label="n-gram: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableClusters" tabindex="0" class="sorting">n-gram</th>
<th aria-label="Freq: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableClusters" tabindex="0" class="sorting">Freq</th>
<th aria-label="%: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableClusters" tabindex="0" class="sorting">%</th>
</tr>
</thead>
<tbody>
{% for cluster in clusters %}
<tr class="{{ loop.cycle('odd', 'even') }}"><td class="sorting_1">{{ loop.index }}</td><td>{{ cluster[1] }}</td><td>{{ cluster[2] }}</td><td>{{ cluster[3] }}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

Expand All @@ -30,54 +46,31 @@ <h2 class="without-pills">Clusters Results</h2>
<script src="/js/thirdparty/DataTables1.10.0-beta.2/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<!-- datatables bootstrap js (css is above) see http://next.datatables.net/manual/styling/bootstrap -->
<script src="/js/thirdparty/DataTables1.10.0-beta.2/media/js/dataTables.bootstrap.js"></script>

<script>
$(function () {

$('#resultsWrap').hide();

// Get URL params
var params = location.search;
var host = window.location.hostname;

jsonUrl = '/api/clusters/' + params; // from the app

$('#tableContainer').html('<table class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableClusters"></table>');
var oTable = $('#dataTableClusters').dataTable({

"ajax": {
"url": jsonUrl,
"dataSrc": "clusters",
"error": function (xhr, error, thrown) {
alert( 'Sorry. Failed to load data. Please try again.' );
}
},

"aoColumns": [
{ "sTitle": "No" },
{ "sTitle": "n-gram" },
{ "sTitle": "Freq" },
{ "sTitle": "%" }
],

"fnDrawCallback": function ( oSettings ) {
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
{
$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
}
}
},

"fnInitComplete": function () {
$('#resultsWrap').show();
Pace.stop();
},

"bDeferRender": true,
"bPaginate": false,
"bPaginate": false,
<!-- I think it makes more sense to use pseudo-pagination: -->
<!-- "bPaginate": true, -->
<!-- "aLengthMenu": [[5, 10, 15, 25, 50, 100, -1], [5, 10, 15, 25, 50, 100, "All"]], -->
<!-- "iDisplayLength" : 50, -->

"bLengthChange": false,
"bFilter": true,
"bSort": true,
Expand Down Expand Up @@ -119,4 +112,5 @@ <h2 class="without-pills">Clusters Results</h2>
});

</script>
{% endblock %}

{% endblock %}
64 changes: 33 additions & 31 deletions clic/web/templates/keywords-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,43 @@
{% endblock %}

{% block title %}
Keywords Search {{ super() }}
Keywords {{ super() }}
{% endblock %}

{% block body %}
<h2 class="without-pills">Keywords Results</h2>

<div id="resultsWrap">
<div id="tableContainer"></div>
<div id="tableContainer">
<table style="width: 0px; cursor:pointer;" aria-describedby="dataTableKeywords_info" class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableKeywords">
<thead>
<tr role="row">
<th aria-label="No" style="width: 0px;" colspan="1" rowspan="1" class="sorting_asc">No</th>
<th aria-label="n-gram: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">n-gram</th>
<th aria-label="Test Freq: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">Test Freq</th>
<th aria-label="%: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">%</th>
<th aria-label="Ref Freq: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">Ref Freq</th>
<th aria-label="%: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">%</th>
<th aria-label="K: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">K</th>
<th aria-label="P: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">P</th>
</tr>
</thead>
<tbody>
{% for keyword in keywords %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td class="sorting_1">{{ loop.index }}</td>
<td>{{ keyword[1] }}</td>
<td>{{ keyword[2] }}</td>
<td>{{ keyword[3] }}</td>
<td>{{ keyword[4] }}</td>
<td>{{ keyword[5] }}</td>
<td>{{ keyword[6] }}</td>
<td>{{ keyword[7] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

Expand All @@ -33,36 +62,9 @@ <h2 class="without-pills">Keywords Results</h2>

<script>
$(function () {
$('#resultsWrap').hide();

// Get URL params
var params = location.search;
var host = window.location.hostname;

jsonUrl = '/api/keywords/' + params; // from the app

$('#tableContainer').html('<table class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableKeywords"></table>');
var oTable = $('#dataTableKeywords').dataTable({

"ajax": {
"url": jsonUrl,
"dataSrc": "keywords",
"error": function (xhr, error, thrown) {
alert( 'Sorry. Failed to load data. Please try again.' );
}
},

"fnDrawCallback": function ( oSettings ) {
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
{
$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
}
}
},

"fnInitComplete": function () {
$('#resultsWrap').show();
Pace.stop();
Expand Down Expand Up @@ -120,7 +122,7 @@ <h2 class="without-pills">Keywords Results</h2>
var slug = slugify(term)
window.location.href = '/concordances/?terms=' + slug + "&testCollection={{testCollection}}&testIdxMod={{testIdxMod}}&selectWords={{selectWords}}";
});

});
});
</script>

{% endblock %}
4 changes: 2 additions & 2 deletions clic/web/templates/layout/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<body>

<div class="container">
<img class="pull-right" src="{{ url_for('static', filename='img/uonlogo.png') }}" />
<img class="pull-right" src="{{ url_for('static', filename='img/AHRC10th_vert_RGB.png') }}" />
<img class="pull-right hidden-xs" src="{{ url_for('static', filename='img/uonlogo.png') }}" />
<img style="padding-top: 1em" class="pull-right hidden-xs" src="{{ url_for('static', filename='img/AHRC10th_horiz_small_RGB.png') }}" />

<div class="header">
<h1 class="uonHeaderh1">CLiC</h1>
Expand Down
2 changes: 1 addition & 1 deletion deploy/uwsgi/apps-include.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ logfile-chown = true

# Process Management
master = true
processes = 2
processes = 5
1 change: 1 addition & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r testing.txt

flask-debug-toolbar==0.10.0
ipython==2.4.1
lxml==3.4.1

0 comments on commit efae30f

Please sign in to comment.