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

Add regex search option for text searches #107

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

etanttila
Copy link
Contributor

Description

What?

Allow user to select to use regex search for student form contents and teacher response. This is done by checking a checkbox by the field.
Screenshot from 2024-06-03 14-49-24
Screenshot from 2024-06-04 11-36-21

Add also simple validation and error styling (because the default error message appearance breaks layout):
Screenshot from 2024-06-04 11-35-02

The layout and styling should work well responsively on different sizes of screens, e.g.:
Screenshot from 2024-06-04 11-38-15

Why?

Juha Sorva wants support for regex filtering of form contents.

How?

Implement filter, field and widget that allow selecting between default search method and a regex search.
Implement simple validation and error handling (also for exercise identifier, which didn't validate regex) for regex.
Change form styling to use flex, so the checkbox and label can also be positioned well.

Fixes #87

Testing

Remember to add or update unit tests for new features and changes.

What type of test did you run?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Selenium tests.
  • Other test. (Add a description below)
  • Manual testing.

Tested that the normal text search still seems to work, as well as the new regex search. (And that searching works also when the text field is empty). Tested also that there is a error message if the regex search is used but the search string isn't valid regex.

Did you test the changes in

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

Think of what is affected by these changes and could become broken

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Added some documentation strings withing the code.
Perhaps Aplus manual should be updated also towards the end of the summer to provide info about new changes (e.g. this filtering, importing feedback tags, and other possible changes).

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

Clean up your git commit history before submitting the pull request!

@etanttila
Copy link
Contributor Author

@jsorva suggested that the checkbox label would be changed from "Use regex search" to "Regex search" (I suppose the Finnish translation would respectively be changed from "Käytä regex-hakua" to "Regex-haku"). I will do this minor change at some point unless opposing opinions arise, but this can sill be reviewed before that.

@etanttila etanttila requested a review from ihalaij1 June 24, 2024 07:16
Copy link
Contributor

@ihalaij1 ihalaij1 left a comment

Choose a reason for hiding this comment

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

Nice!

I had some small comments.

Comment on lines 21 to 22
msgid "Not a valid regex pattern"
msgstr "Ei ole säännöllinen lauseke"
Copy link
Contributor

Choose a reason for hiding this comment

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

Would "Ei säännöllinen lauseke" be better than "Ei ole säännöllinen lauseke"?

"""
template_name = "feedback/widgets/combo_textsearch_widget.html"

def __init__(self, attrs=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

__init__ should have a return type annotated with -> None:
https://peps.python.org/pep-0484/#the-meaning-of-annotations

class ComboTextSearchField(forms.MultiValueField):
widget = ComboTextSearchWidget

def __init__(self, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

__init__ should have a return type annotated with -> None:
https://peps.python.org/pep-0484/#the-meaning-of-annotations

}
super().__init__(widgets, attrs)

def decompress(self, value) -> tuple[str, bool]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the parameter value have a type annotation?

Copy link
Contributor Author

@etanttila etanttila Jul 2, 2024

Choose a reason for hiding this comment

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

A very good question. It can either be None or a tuple[str, bool], so if a type annotation is added, should it be Optional[tuple[str, bool]]?
Also, should the return value type annotation be actually tuple[Optional[str], Optional[bool]] (or Union[tuple[str, bool], tuple[None, None]], since the return value can either be tuple[str, bool] or (None, None)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I also realized that it probably would be a good idea to change this method slightly to check if value rather than if value is None (and respectively swap the return values) (so if somehow the empty value is something else than None, it still would work).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A very good question. It can either be None or a tuple[str, bool]

Although I guess it could also be a list consisting of a str and bool, but list only accepts one type argument, so that cannot be provided as a type hint. I guess I just have to stick with the Optional[tuple[str, bool]]

"""
field_class = ComboTextSearchField

def __init__(self, *args, lookup_expr=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

__init__ should have a return type annotated with -> None:
https://peps.python.org/pep-0484/#the-meaning-of-annotations

@ihalaij1 ihalaij1 self-assigned this Jul 3, 2024
@ihalaij1 ihalaij1 self-requested a review July 3, 2024 11:51
Copy link
Contributor

@ihalaij1 ihalaij1 left a comment

Choose a reason for hiding this comment

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

Changes look good! You can combine the commits and merge.

Allow user to select to use regex search for student form contents
and teacher response. This is done by checking a checkbox by the field.
Implement filter, field and widget that allow selecting between default
search method and a regex search.
Implement simple validation and error handling (also for exercise identifier,
which didn't validate regex) for regex.
Change form styling to use flex, so the checkbox and label can also be
positioned well.

Fix apluslms#87
@etanttila etanttila merged commit 54c43b7 into apluslms:master Jul 3, 2024
@etanttila etanttila deleted the regex-text-filtering branch July 3, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add regex search for the submitted form contents
2 participants