Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 286ae3b

Browse files
changing all the variable names to using underscores; loading of search from URL
1 parent 157f3db commit 286ae3b

File tree

6 files changed

+108
-101
lines changed

6 files changed

+108
-101
lines changed

‎mpeds_coder.py‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -571,21 +571,8 @@ def eventCreator(aid):
571571
@login_required
572572
def adj():
573573
"""Initial rendering for adjudication page."""
574-
575-
## TODO: These are placeholders which will be gathered from queries later
576-
filter_field1 = 'start_date'
577-
filter_compare1 = '__eq__'
578-
filter_value1 = '2016年05月24日'
579-
580-
filter_field2 = 'location'
581-
filter_compare2 = 'like'
582-
filter_value2 = 'Chicago'
583-
584-
filter_expr1 = getattr(getattr(EventMetadata, filter_field1), filter_compare1)(filter_value1)
585-
filter_expr2 = getattr(getattr(EventMetadata, filter_field2), filter_compare2)('%{}%'.format(filter_value2))
586-
587-
## perform the query and get the results
588-
search_events = db_session.query(EventMetadata).filter(filter_expr1, filter_expr2).all()
574+
if current_user.authlevel < 2:
575+
return redirect(url_for('index'))
589576

590577
## Get five recent events
591578
recent_events = [x[0] for x in db_session.query(EventMetadata, RecentEvent).\
@@ -604,7 +591,7 @@ def adj():
604591
## TODO: Do some checks in the template which don't force us to enter in empty variables
605592
## which will be initialized by load_adj_grid
606593
return render_template("adj.html",
607-
search_events = search_events,
594+
search_events = [],
608595
filter_fields = filter_fields,
609596
cand_events = {},
610597
grid_vars = adj_grid_order,
@@ -657,14 +644,14 @@ def load_adj_grid():
657644
def do_search():
658645
"""Takes the URL params and searches the candidate events for events
659646
which meet the search criteria."""
660-
filter_field = request.form['adj-filter-field']
661-
filter_value = request.form['adj-filter-value']
662-
filter_compare = request.form['adj-filter-compare']
647+
filter_field = request.form['adj_filter_field']
648+
filter_value = request.form['adj_filter_value']
649+
filter_compare = request.form['adj_filter_compare']
663650

664-
search_str = request.form['adj-search-input']
651+
search_str = request.form['adj_search_input']
665652

666-
sort_field = request.form['adj-sort-field']
667-
sort_order = request.form['adj-sort-order']
653+
sort_field = request.form['adj_sort_field']
654+
sort_order = request.form['adj_sort_order']
668655

669656
## TODO: Need to account for multiple different filters and sorting terms.
670657

@@ -683,7 +670,7 @@ def do_search():
683670
filter_expr = getattr(getattr(EventMetadata, filter_field), '__gt__')(filter_value)
684671
elif filter_compare == 'ge':
685672
filter_expr = getattr(getattr(EventMetadata, filter_field), '__ge__')(filter_value)
686-
elif filter_compare == 'like':
673+
elif filter_compare == 'contains':
687674
filter_expr = getattr(getattr(EventMetadata, filter_field), 'like')(u'%{}%'.format(filter_value))
688675
elif filter_compare == 'startswith':
689676
filter_expr = getattr(getattr(EventMetadata, filter_field), 'like')(u'{}%'.format(filter_value))

‎static/adj.js‎

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ var loadGrid = function(canonical_event_key = null, cand_events_str = null) {
110110
.fail(function() { return makeError(req.responseText); });
111111
}
112112

113-
/**
114-
* Loads the search results for the given query.
115-
* @returns true if successful, false otherwise.
116-
*/
117-
var loadSearch = function() {
118-
initializeSearchListeners();
119-
}
120113

121114
/**
122115
* Removes the block from the canonical record.
@@ -143,12 +136,64 @@ var removeCanonical = function () {
143136
.fail(function() { return makeError(req.responseText); });
144137
}
145138

139+
140+
/**
141+
* Loads the search results for the given query from the existing forms.
142+
* @returns true if successful, false otherwise.
143+
*/
144+
var loadSearch = function(rewrite_url = false) {
145+
var req = $.ajax({
146+
url: $SCRIPT_ROOT + '/do_search',
147+
type: "POST",
148+
data:
149+
$('#adj_search_form, #adj_filter_form, #adj_sort_form').serialize(),
150+
beforeSend: function () {
151+
$('.flash').removeClass('alert-danger');
152+
$('.flash').addClass('alert-info');
153+
$('.flash').text("Loading...");
154+
$('.flash').show();
155+
}
156+
})
157+
.done(function() {
158+
// Update content block.
159+
$('#cand-search_block').html(req.responseText);
160+
161+
// Update the search button text.
162+
n_results = req.getResponseHeader('Search-Results');
163+
$('#cand-search-text').text("Search (" + n_results + " results)");
164+
165+
// Update the candidate button text.
166+
$('#cand_button-link').text("Candidate Events*");
167+
168+
if (rewrite_url == true) {
169+
// Update the URL search params.
170+
let curr_search_params = new URLSearchParams(window.location.search);
171+
var search_params = jQuery.parseJSON(req.getResponseHeader('Query'));
172+
for (var key in search_params) {
173+
curr_search_params.set(key, search_params[key]);
174+
}
175+
176+
var new_url = 'adj?' + curr_search_params.toString();
177+
window.history.pushState({path: new_url}, '', new_url);
178+
}
179+
180+
initializeSearchListeners();
181+
182+
// get rid of loading flash
183+
$('.flash').hide();
184+
$('.flash').removeClass('alert-info');
185+
return true;
186+
})
187+
.fail(function() { return makeError(req.responseText); });
188+
}
189+
190+
146191
/**
147192
* Toggles flags for candidate events.
148193
* @param {Event} e - click event
149194
* @param {str} operation - add or deletion operation. takes values 'add' or 'del'
150195
* @param {str} flag - the flag to add to this event
151-
* @returns true if success, false otherwise
196+
* @returns true if successful, false otherwise.
152197
*/
153198
var toggleFlag = function(e, operation, flag) {
154199
if (operation != 'add' & operation != 'del') {
@@ -179,6 +224,7 @@ var toggleFlag = function(e, operation, flag) {
179224
.fail(function() { return makeError(req.responseText); });
180225
}
181226

227+
182228
/**
183229
*
184230
* @param {str} mode - add or edit
@@ -544,79 +590,48 @@ $(function () {
544590
});
545591

546592
// Listener for filters and sorting
547-
$('#adj-filter-button').click(function() {
593+
$('#adj_filter_button').click(function() {
548594
var req = $.ajax({
549595
url: $SCRIPT_ROOT + '/adj_search/filter',
550596
type: "POST",
551597
data: {
552598
is_addition: true
553599
}
554600
})
555-
.done(function() {$('#adj-filter-form').append(req.responseText); })
601+
.done(function() {$('#adj_filter_form').append(req.responseText); })
556602
.fail(function() { return makeError(req.responseText); });
557603
});
558604

559-
$('#adj-sort-button').click(function() {
605+
$('#adj_sort_button').click(function() {
560606
var req = $.ajax({
561607
url: $SCRIPT_ROOT + '/adj_search/sort',
562608
type: "POST",
563609
data: {
564610
is_addition: true
565611
}
566612
})
567-
.done(function() {$('#adj-sort-form').append(req.responseText); })
613+
.done(function() {$('#adj_sort_form').append(req.responseText); })
568614
.fail(function() { return makeError(req.responseText); });
569615
});
570616

571617
// Listener for search button.
572-
$('#adj-search-button').click(function() {
573-
var req = $.ajax({
574-
url: $SCRIPT_ROOT + '/do_search',
575-
type: "POST",
576-
data:
577-
$('#adj-search-form, #adj-filter-form, #adj-sort-form').serialize(),
578-
beforeSend: function () {
579-
$('.flash').removeClass('alert-danger');
580-
$('.flash').addClass('alert-info');
581-
$('.flash').text("Loading...");
582-
$('.flash').show();
583-
}
584-
})
585-
.done(function() {
586-
// Update content block.
587-
$('#cand-search_block').html(req.responseText);
588-
589-
// Update the search button text.
590-
n_results = req.getResponseHeader('Search-Results');
591-
$('#cand-search-text').text("Search (" + n_results + " results)");
618+
$('#adj_search_button').click(loadSearch);
592619

593-
// Update the candidate button text.
594-
$('#cand_button-link').text("Candidate Events*");
595-
596-
// Update the URL search params.
597-
let curr_search_params = new URLSearchParams(window.location.search);
598-
var search_params = jQuery.parseJSON(req.getResponseHeader('Query'));
599-
for (var key in search_params) {
600-
curr_search_params.set(key, search_params[key]);
601-
}
602-
603-
var new_url = 'adj?' + curr_search_params.toString();
604-
window.history.pushState({path: new_url}, '', new_url);
605-
606-
initializeSearchListeners();
607-
608-
// get rid of loading flash
609-
$('.flash').hide();
610-
$('.flash').removeClass('alert-info');
611-
return true;
612-
})
613-
.fail(function() { return makeError(req.responseText); });
614-
});
615-
616-
loadSearch();
617-
618-
// initialize the grid
620+
// initialize the grid and search
619621
let search_params = new URLSearchParams(window.location.search);
622+
var search_ids = [
623+
'adj_search_input',
624+
'adj_filter_compare',
625+
'adj_filter_value',
626+
'adj_filter_field',
627+
'adj_sort_field',
628+
'adj_sort_order'
629+
]
630+
for(var i = 0; i < search_ids.length; i++) {
631+
$('#' + search_ids[i]).val(search_params.get(search_ids[i]));
632+
}
633+
loadSearch();
634+
620635
loadGrid(
621636
search_params.get('canonical_event_key'),
622637
search_params.get('cand_events')

‎templates/adj-filter.html‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="row form-row">
22
<div class="col-sm-4">
33
<select class="form-control"
4-
name="adj-filter-field"
5-
id="adj-filter-field">
4+
name="adj_filter_field"
5+
id="adj_filter_field">
66
<option value="">---</option>
77
{% for field in filter_fields %}
88
<option>{{ field }}</option>
@@ -11,27 +11,27 @@
1111
</div>
1212
<div class="col-sm-4">
1313
<select class="form-control"
14-
name="adj-filter-compare"
15-
id="adj-filter-compare">
14+
name="adj_filter_compare"
15+
id="adj_filter_compare">
1616
<option value="">---</option>
1717
<option value="eq">equals</option>
1818
<option value="gt">is greater than</option>
1919
<option value="gte">is greater than or equal to</option>
2020
<option value="lt">is less than</option>
2121
<option value="lte">is less than or equal to</option>
22-
<option value="like">contains</option>
22+
<option value="contains">contains</option>
2323
<option value="starts">starts with</option>
2424
<option value="ends">ends with</option>
2525
</select>
2626
</div>
2727
<div class="col-sm-3">
2828
<input class="form-control"
29-
name="adj-filter-value"
30-
id="adj-filter-value"
29+
name="adj_filter_value"
30+
id="adj_filter_value"
3131
type="text"
3232
placeholder = "Value..."/>
3333
</div>
3434
<div class="col-sm-1">
35-
<a id="adj-filter-button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
35+
<a id="adj_filter_button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
3636
</div>
3737
</div>

‎templates/adj-search.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="row form-row">
22
<div class="col-sm-11">
33
<input class="form-control"
4-
name="adj-search-input"
5-
id="adj-search-input"
4+
name="adj_search_input"
5+
id="adj_search_input"
66
type="text"
77
placeholder = "Example: Mizzou OR Missouri, Quebec AND students"/>
88
</div>

‎templates/adj-sort.html‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="row form-row">
22
<div class="col-sm-4">
33
<select class="form-control"
4-
name="adj-sort-field"
5-
id="adj-sort-field">
4+
name="adj_sort_field"
5+
id="adj_sort_field">
66
<option value="">---</option>
77
{% for field in filter_fields %}
88
<option>{{ field }}</option>
@@ -11,13 +11,14 @@
1111
</div>
1212
<div class="col-sm-4">
1313
<select class="form-control"
14-
name="adj-sort-order"
15-
id="adj-sort-order">
14+
name="adj_sort_order"
15+
id="adj_sort_order">
16+
<option value="">---</option>
1617
<option value="asc">ascending</option>
1718
<option value="desc">descending</option>
1819
</select>
1920
</div>
2021
<div class="col-sm-1">
21-
<a id="adj-sort-button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
22+
<a id="adj_sort_button" class="btn btm-primary glyphicon glyphicon-{{ 'minus' if is_addition else 'plus' }}"></a>
2223
</div>
2324
</div>

‎templates/adj.html‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
<div class="col-sm-5 adj-pane" id="adj-pane-cand-events">
2020
<a href="{{ url_for('adj',
2121
cand_events = '6031,6032,21644,21646',
22-
canonical_event_key = 'Milo_Chicago_2016') }}">
22+
canonical_event_key = 'Milo_Chicago_2016',
23+
adj_search_input = 'Milo',
24+
adj_filter_field = 'location',
25+
adj_filter_compare = 'contains',
26+
adj_filter_value = 'Chicago') }}">
2327
Example page
2428
</a><br/>
2529
<a id="cand-events-hide" href="#">&laquo; Hide Pane</a>
@@ -42,26 +46,26 @@ <h4>Event Selection</h4>
4246
<div class="tab-pane" id="search_block">
4347
<div class="adj-variable-group">
4448
<h5>Search</h5>
45-
<form id="adj-search-form">
49+
<form id="adj_search_form">
4650
{% include 'adj-search.html' %}
4751
</form>
4852
</div>
4953
<hr/>
5054
<div class="adj-variable-group">
5155
<h5>Filter</h5>
52-
<form id="adj-filter-form">
56+
<form id="adj_filter_form">
5357
{% include 'adj-filter.html' %}
5458
</form>
5559
</div>
5660
<hr/>
5761
<div class="adj-variable-group">
5862
<h5>Sort</h5>
59-
<form id="adj-sort-form">
63+
<form id="adj_sort_form">
6064
{% include 'adj-sort.html' %}
6165
</form>
6266
</div>
6367
<hr/>
64-
<button id="adj-search-button" class="btn btn-primary">Search</button>
68+
<button id="adj_search_button" class="btn btn-primary">Search</button>
6569
</div>
6670
<div class="tab-pane" id="cand_block">
6771
<ul class="nav nav-pills nav-justified" id="adj-subtabselecter">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /