Skip to content

fix: char set validators#154

Merged
SKairinos merged 16 commits into
mainfrom
package-javascript-80
Mar 25, 2025
Merged

fix: char set validators#154
SKairinos merged 16 commits into
mainfrom
package-javascript-80

Conversation

@SKairinos

@SKairinos SKairinos commented Mar 14, 2025

Copy link
Copy Markdown
Contributor

This change is Reviewable

@SKairinos SKairinos linked an issue Mar 14, 2025 that may be closed by this pull request

@faucomte97 faucomte97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 18 of 20 files at r1, all commit messages.
Reviewable status: 18 of 20 files reviewed, 3 unresolved discussions


codeforlife/user/serializers/klass.py line 25 at r1 (raw file):

    # TODO: add to model validators in new schema.
    name = serializers.CharField(
        validators=[AlphaCharSetValidator(spaces=True)],

Update to AlphaNumeric char set, allow spaces, dashes and underscores.

image.png


codeforlife/user/serializers/school.py line 20 at r1 (raw file):

    # TODO: add to model validators in new schema.
    name = serializers.CharField(
        validators=[AlphaCharSetValidator(spaces=True)],

Update to AlphaNumeric char set, allow spaces, full stops and apostrophes.
A lot schools are called after someone and might be called "St. John's" etc.
Also, if the school name already exists, teachers will instinctively try to add a 2 at the end.


codeforlife/validators/char_set.py line 49 at r1 (raw file):

    def __init__(self, spaces: bool = False, special_chars: str = ""):
        super().__init__(
            "a-zA-Z",

Does this allow for languages that do not use the roman alphabet?
Since we have users all around the world, we'd need these validators to allow for the use of other alphabets.

@faucomte97 faucomte97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 18 of 18 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @SKairinos)


codeforlife/user/serializers/klass.py line 25 at r1 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…

Update to AlphaNumeric char set, allow spaces, dashes and underscores.

image.png

Use UnicodeAlphanumericCharSetValidator and allow spaces, dashes and underscores please.

@faucomte97 faucomte97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @SKairinos)


codeforlife/user/serializers/user.py line 37 at r2 (raw file):

        max_length=150,
        read_only=True,
    )

For these, please also use UnicodeAlphaNumericCharSetValidator, and allow for spaces, dashes and apostrophes.

Mainly because there are a good amount of names (especially in the countries where cfl is used a lot) where - and ' are common in names, as well and multiple names so spaces are needed.

I'm not 100% convinced about the need for numbers so we could stick to the Alpha char set, the only argument I can think of is that teachers can sometimes test the creation of students by entering "Student 1" etc.

Code quote:

    # TODO: add to model validators in new schema.
    first_name = serializers.CharField(
        validators=[UnicodeAlphaCharSetValidator()],
        max_length=150,
        read_only=True,
    )

    # TODO: add to model validators in new schema.
    last_name = serializers.CharField(
        validators=[UnicodeAlphaCharSetValidator()],
        max_length=150,
        read_only=True,
    )

@SKairinos SKairinos left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @faucomte97)


codeforlife/user/serializers/klass.py line 25 at r1 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…

Use UnicodeAlphanumericCharSetValidator and allow spaces, dashes and underscores please.

Done.


codeforlife/user/serializers/school.py line 20 at r1 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…

Update to AlphaNumeric char set, allow spaces, full stops and apostrophes.
A lot schools are called after someone and might be called "St. John's" etc.
Also, if the school name already exists, teachers will instinctively try to add a 2 at the end.

Done.


codeforlife/user/serializers/user.py line 37 at r2 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…

For these, please also use UnicodeAlphaNumericCharSetValidator, and allow for spaces, dashes and apostrophes.

Mainly because there are a good amount of names (especially in the countries where cfl is used a lot) where - and ' are common in names, as well and multiple names so spaces are needed.

I'm not 100% convinced about the need for numbers so we could stick to the Alpha char set, the only argument I can think of is that teachers can sometimes test the creation of students by entering "Student 1" etc.

Done.


codeforlife/validators/char_set.py line 49 at r1 (raw file):

Previously, faucomte97 (Florian Aucomte) wrote…

Does this allow for languages that do not use the roman alphabet?
Since we have users all around the world, we'd need these validators to allow for the use of other alphabets.

Yes, for example, in this PR I tested against Greek

@faucomte97 faucomte97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 12 of 12 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @SKairinos)

@SKairinos SKairinos merged commit ed7b3f7 into main Mar 25, 2025
@SKairinos SKairinos deleted the package-javascript-80 branch March 25, 2025 11:10
@codecov

codecov Bot commented Mar 25, 2025

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sanitise all text fields

2 participants