-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Added raw id filter #248 #253
Conversation
b963943
to
a40903e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niteshsinha17 could you write a test that covers these 2 lines please?
https://coveralls.io/builds/42860654/source?filename=openwisp_utils%2Fadmin_theme%2Ffilter.py#L16
So we can avoid the build failure for coverage decreasing, albeit is small but it's nice to cover all new lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @niteshsinha17 👍🏼
I tested this on my local machine and the input filter works perfectly.
I noticed some minor issues with code formatting. We can merge this one those are addressed.
inputFilters.forEach(function (filter){ | ||
var href = filter.getAttribute('href'); | ||
var [key, val] = href.substring(1).split('='); | ||
if(val.length === 0 && key in qs){ | ||
|
||
delete qs[key]; | ||
}else if(val.length !== 0) { | ||
qs[key] = val; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code formatting can be improved here
inputFilters.forEach(function (filter){ | |
var href = filter.getAttribute('href'); | |
var [key, val] = href.substring(1).split('='); | |
if(val.length === 0 && key in qs){ | |
delete qs[key]; | |
}else if(val.length !== 0) { | |
qs[key] = val; | |
} | |
}); | |
inputFilters.forEach(function (filter) { | |
var href = filter.getAttribute('href'); | |
var [key, val] = href.substring(1).split('='); | |
if (val.length === 0 && key in qs) { | |
delete qs[key]; | |
} else if (val.length !== 0) { | |
qs[key] = val; | |
} | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we have style checks for JS code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It checks only basic formatting.
def queryset(self, request, queryset): | ||
if self.value() is not None: | ||
return queryset.filter(name__icontains=self.value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved to the InputFilter
class? Will this be required to be overridden in derived classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes need to be overridden,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we don't need to override this, right? We can just update the class variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @niteshsinha17 @pandafy!
See my comments below for some minor code improvements.
Definitely let's add a mention of this in the README, like at the end of this section: https://github.com/openwisp/openwisp-utils#admin-utilities, a screenshot in the media branch would be highly appreciated: https://github.com/openwisp/openwisp-utils/tree/media/docs.
{% for key, value in all_choice.query_parts %} | ||
<input type="hidden" name="{{ key }}" value="{{ value }}" /> | ||
{% endfor %} | ||
<input type="text" class="ow-input-filter-field" title="{{ spec.value | default_if_none:'' }}"value="{{ spec.value | default_if_none:'' }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space is missing here before value
.
I recommend breaking the attributes over new lines, eg:
<input type="text"
class="...."
title="..."
value="..."
/>
<input type="text" class="ow-input-filter-field" title="{{ spec.value | default_if_none:'' }}"value="{{ spec.value | default_if_none:'' }}" | ||
name="{{ spec.parameter_name }}" /> | ||
{% if not all_choice.selected %} | ||
<a class='field-clear' title="{% trans 'Clear' %}" href="{{ all_choice.query_string }}">✖ </a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, I would break this line
c225b78
to
3d50c85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have done some basic testing. I will testing it with openwisp-controller and check if there are any issues.
The main goal of the filter is done. I have few queries regarding implementation @niteshsinha17.
@@ -422,7 +422,6 @@ function initToolTipHandlers() { | |||
}); | |||
}); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change intentional?
def queryset(self, request, queryset): | ||
if self.value() is not None: | ||
return queryset.filter(name__icontains=self.value()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we don't need to override this, right? We can just update the class variable.
3d50c85
to
9783b19
Compare
9783b19
to
b102173
Compare
7d65c88
to
cf98fa6
Compare
<div class="ow-filter ow-input-filter"> | ||
<div class="filter-title" title="{{ choice.display }}"> | ||
{% with choices.0 as all_choice %} | ||
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3> | |
<h3>{% blocktrans with filter_title=title %}By {{ filter_title }}{% endblocktrans %}</h3> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing and looked at the code, it's good to merge except a few minor whitespace issues, see below.
delete qs[key]; | ||
} | ||
|
||
}else if(val.length !== 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a space after the }
? Isn't the JS linter complaining about this? I thought this would be something to complain about.
<div id="{{title|join_string}}" aria-label="by {{title}}" tabindex="0" | ||
<div id="{{title|join_string}}" | ||
aria-label="by {{title}}" | ||
tabindex="0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a few extra white spaces here and in several other HTML files, see my next comments.
{{ selected_choice | default_if_none:'------' }} | ||
</div> | ||
</div> | ||
<div id="choices-{{title|join_string}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
<a {% if choice.selected %} class="selected"{% endif %} title="{{ choice.display }}" | ||
href="{{ choice.query_string|iriencode }}"> | ||
{{ choice.display }}</a> | ||
<a {% if choice.selected %} class="selected"{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
{% for key, value in all_choice.query_parts %} | ||
<input type="hidden" name="{{ key }}" value="{{ value }}" /> | ||
{% endfor %} | ||
<input type="text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too
be5e3c5
to
14159be
Compare
This filter can be used in other modules to add a raw id filter
Checklist
closes #248