Skip to content
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

Merged
merged 7 commits into from
Nov 29, 2021
Merged

Conversation

niteshsinha17
Copy link
Member

This filter can be used in other modules to add a raw id filter

Checklist

  • I have read the contributing guidelines.
  • I have manually tested the proposed changes.
  • I have written new test cases to avoid regressions. (if necessary)
  • I have updated the documentation. (e.g. README.rst)
  • I have added [change!] to commit title to indicate a backward incompatible change. (if required)
  • I have checked the links added / modified in the documentation.

closes #248

@niteshsinha17 niteshsinha17 force-pushed the issues/248-add-raw-id-filter branch 2 times, most recently from b963943 to a40903e Compare September 14, 2021 13:39
@coveralls
Copy link

coveralls commented Sep 14, 2021

Coverage Status

Coverage increased (+0.1%) to 98.582% when pulling 14159be on issues/248-add-raw-id-filter into 497af83 on master.

Copy link
Member

@nemesifier nemesifier left a 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.

Copy link
Member

@pandafy pandafy left a 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.

Comment on lines 269 to 289
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;
}
});
Copy link
Member

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

Suggested change
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;
}
});

Copy link
Member

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?

Copy link
Member Author

@niteshsinha17 niteshsinha17 Sep 23, 2021

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.

openwisp_utils/admin_theme/static/admin/js/ow-filter.js Outdated Show resolved Hide resolved
openwisp_utils/admin_theme/static/admin/css/ow-filters.css Outdated Show resolved Hide resolved
Comment on lines +65 to +67
def queryset(self, request, queryset):
if self.value() is not None:
return queryset.filter(name__icontains=self.value())
Copy link
Member

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?

Copy link
Member Author

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,

Copy link
Member

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.

Copy link
Member

@nemesifier nemesifier left a 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:'' }}"
Copy link
Member

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 }}">&#x2716; </a>
Copy link
Member

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

@nemesifier nemesifier changed the title [enhancement] Added raw id filter #248 [feature] Added raw id filter #248 Oct 8, 2021
@niteshsinha17 niteshsinha17 force-pushed the issues/248-add-raw-id-filter branch 2 times, most recently from c225b78 to 3d50c85 Compare October 9, 2021 15:49
Copy link
Member

@pandafy pandafy left a 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() {
});
});
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change intentional?

Comment on lines +65 to +67
def queryset(self, request, queryset):
if self.value() is not None:
return queryset.filter(name__icontains=self.value())
Copy link
Member

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.

tests/test_project/tests/test_admin.py Outdated Show resolved Hide resolved
tests/test_project/tests/test_admin.py Outdated Show resolved Hide resolved
openwisp_utils/admin_theme/filter.py Outdated Show resolved Hide resolved
openwisp_utils/admin_theme/filter.py Outdated Show resolved Hide resolved
README.rst Outdated Show resolved Hide resolved
openwisp_utils/admin_theme/filter.py Outdated Show resolved Hide resolved
openwisp_utils/admin_theme/filter.py Outdated Show resolved Hide resolved
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<h3>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
<h3>{% blocktrans with filter_title=title %}By {{ filter_title }}{% endblocktrans %}</h3>

Copy link
Member

@nemesifier nemesifier left a 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.

openwisp_utils/admin_theme/static/admin/js/ow-filter.js Outdated Show resolved Hide resolved
delete qs[key];
}

}else if(val.length !== 0) {
Copy link
Member

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"
Copy link
Member

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}}"
Copy link
Member

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 %}
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

@nemesifier nemesifier merged commit 6ecb0be into master Nov 29, 2021
@nemesifier nemesifier deleted the issues/248-add-raw-id-filter branch November 29, 2021 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[feature] Add custom raw ID filter
4 participants