Skip to content

Commit

Permalink
Remove 'Instrument' filter from search
Browse files Browse the repository at this point in the history
  • Loading branch information
nbuonin committed Apr 21, 2020
1 parent dd01d0e commit 169f51a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 29 deletions.
100 changes: 100 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module.exports = {
"env": {
"browser": true,
"amd": true,
"jquery": true,
"cypress/globals": true
},
"parser": "@typescript-eslint/parser",
"plugins": [
"security",
"scanjs-rules",
"no-unsafe-innerhtml",
"cypress",
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:security/recommended"
],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"no-unused-vars": [
"error",
{"vars": "all", "args": "none"}
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"max-len": [2, {"code": 80, "tabWidth": 4, "ignoreUrls": true}],
"space-before-function-paren": ["error", "never"],
"space-in-parens": ["error", "never"],
"no-trailing-spaces": ["error"],
"key-spacing": ["error", { "beforeColon": false }],
"func-call-spacing": ["error", "never"],

/** no-unsafe-innerhtml rule **/
"no-unsafe-innerhtml/no-unsafe-innerhtml" : 2,

/** ScanJS rules **/
"scanjs-rules/assign_to_hostname": 1,
"scanjs-rules/assign_to_href": 1,
"scanjs-rules/assign_to_location": 1,
"scanjs-rules/assign_to_onmessage": 1,
"scanjs-rules/assign_to_pathname": 1,
"scanjs-rules/assign_to_protocol": 1,
"scanjs-rules/assign_to_search": 1,
"scanjs-rules/assign_to_src": 1,
"scanjs-rules/call_Function": 1,
"scanjs-rules/call_addEventListener": 1,
"scanjs-rules/call_addEventListener_deviceproximity": 1,
"scanjs-rules/call_addEventListener_message": 1,
"scanjs-rules/call_connect": 1,
"scanjs-rules/call_eval": 1,
"scanjs-rules/call_execScript": 1,
"scanjs-rules/call_hide": 0, /* hide used often. overly cautious */
"scanjs-rules/call_open_remote=true": 1,
"scanjs-rules/call_parseFromString": 1,
"scanjs-rules/call_setImmediate": 1,
"scanjs-rules/call_setInterval": 1,
"scanjs-rules/call_setTimeout": 1,
"scanjs-rules/identifier_indexedDB": 1,
"scanjs-rules/identifier_localStorage": 1,
"scanjs-rules/identifier_sessionStorage": 1,
"scanjs-rules/new_Function": 1,
"scanjs-rules/property_addIdleObserver": 1,
"scanjs-rules/property_createContextualFragment": 1,
"scanjs-rules/property_geolocation": 1,
"scanjs-rules/property_getUserMedia": 1,
"scanjs-rules/property_indexedDB": 1,
"scanjs-rules/property_localStorage": 1,
"scanjs-rules/property_mgmt": 1,
"scanjs-rules/property_sessionStorage": 1,

'security/detect-buffer-noassert': 1,
'security/detect-child-process': 1,
'security/detect-disable-mustache-escape': 1,
'security/detect-eval-with-expression': 1,
'security/detect-new-buffer': 1,
'security/detect-no-csrf-before-method-override': 1,
'security/detect-non-literal-fs-filename': 1,
'security/detect-non-literal-regexp': 1,
'security/detect-non-literal-require': 0, /* requirejs conflict */
'security/detect-object-injection': 0, /* several false positives */
'security/detect-possible-timing-attacks': 1,
'security/detect-pseudoRandomBytes': 1,
'security/detect-unsafe-regex': 1
}
};
5 changes: 0 additions & 5 deletions decruck/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class CompositionListingForm(Form):
choices=genre_choices,
widget=CheckboxSelectMultiple
)
instrumentation = MultipleChoiceField(
required=False,
choices=instrument_choices,
widget=CheckboxSelectMultiple
)
sort_by = ChoiceField(
required=False,
choices=sort_by_choices,
Expand Down
19 changes: 8 additions & 11 deletions decruck/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,6 @@ def serve(self, request):
compositions = compositions.filter(
genre__in=form.cleaned_data['genre'])

if form.cleaned_data['instrumentation']:
compositions = compositions.filter(
instrumentation__in=form.cleaned_data['instrumentation'])

# Per Wagtail docs, search must come after all filtering
if form.cleaned_data['keyword']:
compositions = backend.search(
form.cleaned_data['keyword'],
compositions
)

# Sort results
sort_by = form.cleaned_data['sort_by']
sort_dir = form.cleaned_data['sort_dir']
Expand All @@ -226,6 +215,14 @@ def serve(self, request):
compositions = compositions.order_by(
'-date__upper_strict')

# Per Wagtail docs, search must come after all filtering
if form.cleaned_data['keyword']:
print('keyword is hit')
compositions = backend.search(
form.cleaned_data['keyword'],
compositions
)

return render(request, "main/composition_listing_page.html", {
'page': self,
'form': form,
Expand Down
2 changes: 1 addition & 1 deletion decruck/static/build/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions decruck/static/build/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -5273,6 +5273,10 @@ h3, .h3 {
.composition-search__fieldset-legend {
color: #FFFFFF; }

@media (min-width: 768px) {
#composition-search-col {
min-height: 700px; } }

.composition-search-table {
margin-top: 1em; }

Expand Down
2 changes: 1 addition & 1 deletion decruck/static/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import "@fortawesome/fontawesome-free/js/all";

$('.composition-search__fieldset-checkbox-label').on('click', function(el){
$('#composition-search__form').submit();
})
});
6 changes: 6 additions & 0 deletions decruck/static/src/scss/pages/composition_listing_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
color: #FFFFFF;
}

@include media-breakpoint-up(md) {
#composition-search-col {
min-height: 700px;
}
}

.composition-search-table {
margin-top: 1em;
@extend .table-borderless;
Expand Down
12 changes: 1 addition & 11 deletions decruck/templates/main/composition_listing_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ <h1>{{ page.title }}</h1>
{% endfor %}
</div>
</fieldset>
<fieldset class="composition-search__fieldset">
<legend class="composition-search__fieldset-legend">{% trans "Instrumentation" %}</legend>
<div class="btn-group-toggle" data-toggle="buttons">
{% for instrument in form.instrumentation %}
<label class="btn composition-search__fieldset-checkbox-label">
{{ instrument.tag }}{{ instrument.choice_label }}
</label>
{% endfor %}
</div>
</fieldset>
</div>
</div>
<div class="col-9">
Expand Down Expand Up @@ -120,7 +110,7 @@ <h1>{{ page.title }}</h1>
<div class="col-3">
{# Use an empty col as a spacer for the Genre and Instrumentation menu#}
</div>
<div class="col-9">
<div id="composition-search-col" class="col-9">
<table class="table composition-search-table">
<thead>
<tr>
Expand Down

0 comments on commit 169f51a

Please sign in to comment.