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 language dropdown at registration #1660

Merged
merged 5 commits into from
Jul 26, 2017

Conversation

laura-barluzzi
Copy link
Contributor

@laura-barluzzi laura-barluzzi commented Jul 18, 2017

Proposed changes in this pull request

Address issue #1654 for applying existing feature at the registration. Part of User Dashboard #1491 epic.

  • Add dropdown language menu option by adding the language field both in the signup.html template and in the RegisterForm.
  • Add language item in data used in testing a valid signup
  • Simplify existing language and measurement fields by deleting respective form.fields, custom messages and tests

When should this PR be merged

  • As soon as it has been reviewed

Risks

  • None

Follow-up actions

  • None

Checklist (for reviewing)

General

  • Is this PR explained thoroughly? All code changes must be accounted for in the PR description.
    • Review 1
    • Review 2
  • Is the PR labeled correctly? It should have the migration label if a new migration is added.
    • Review 1
    • Review 2
  • Is the risk level assessment sufficient? The risks section should contain all risks that might be introduced with the PR and which actions we need to take to mitigate these risks. Possible risks are database migrations, new libraries that need to be installed or changes to deployment scripts.
    • Review 1
    • Review 2

Functionality

  • Are all requirements met? Compare implemented functionality with the requirements specification.
    • Review 1
    • Review 2
  • Does the UI work as expected? There should be no Javascript errors in the console; all resources should load. There should be no unexpected errors. Deliberately try to break the feature to find out if there are corner cases that are not handled.
    • Review 1
    • Review 2

Code

  • Do you fully understand the introduced changes to the code? If not ask for clarification, it might uncover ways to solve a problem in a more elegant and efficient way.
    • Review 1
    • Review 2
  • Does the PR introduce any inefficient database requests? Use the debug server to check for duplicate requests.
    • Review 1
    • Review 2
  • Are all necessary strings marked for translation? All strings that are exposed to users via the UI must be marked for translation.
    • Review 1
    • Review 2
  • Is the code documented sufficiently? Large and complex classes, functions or methods must be annotated with comments following our code-style guidelines.
    • Review 1
    • Review 2
  • Has the scalability of this change been evaluated?
    • Review 1
    • Review 2
  • Is there a maintenance plan in place?
    • Review 1
    • Review 2

Tests

  • Are there sufficient test cases? Ensure that all components are tested individually; models, forms, and serializers should be tested in isolation even if a test for a view covers these components.
    • Review 1
    • Review 2
  • If this is a bug fix, are tests for the issue in place? There must be a test case for the bug to ensure the issue won’t regress. Make sure that the tests break without the new code to fix the issue.
    • Review 1
    • Review 2
  • If this is a new feature or a significant change to an existing feature? has the manual testing spreadsheet been updated with instructions for manual testing?
    • Review 1
    • Review 2

Security

  • Confirm this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.
    • Review 1
    • Review 2
  • Are all UI and API inputs run through forms or serializers?
    • Review 1
    • Review 2
  • Are all external inputs validated and sanitized appropriately?
    • Review 1
    • Review 2
  • Does all branching logic have a default case?
    • Review 1
    • Review 2
  • Does this solution handle outliers and edge cases gracefully?
    • Review 1
    • Review 2
  • Are all external communications secured and restricted to SSL?
    • Review 1
    • Review 2

Documentation

  • Are changes to the UI documented in the platform docs? If this PR introduces new platform site functionality or changes existing ones, the changes must be documented in the Cadasta Platform Documentation.
    • Review 1
    • Review 2
  • Are changes to the API documented in the API docs? If this PR introduces new API functionality or changes existing ones, the changes must be documented in the API docs.
    • Review 1
    • Review 2
  • Are reusable components documented? If this PR introduces components that are relevant to other developers (for instance a mixin for a view or a generic form) they should be documented in the Wiki.
    • Review 1
    • Review 2

@oliverroick oliverroick requested review from oliverroick and seav July 19, 2017 10:48
@seav
Copy link
Contributor

seav commented Jul 19, 2017

Hi @laura-barluzzi! Thank you for this PR. I have an initial question. Why didn't you also include the preferred measurement system field as well in this PR?

@laura-barluzzi
Copy link
Contributor Author

Hi @seav, simply because it was not asked in the issue #1654. Further, the user.measurement value is not applied anywhere in the platform yet because I am waiting for the PR Automatic calculation of a polygon area #1534 to be merged for then making a PR with this active branch I called feature/area_calculation_with_user_measurement. But we can change it if it's preferred. @clash99 ?

Copy link
Member

@oliverroick oliverroick left a comment

Choose a reason for hiding this comment

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

Looks good, just one small thing.

We shouldn't add any other fields to the sign-up form after the language field and the profile picture. I think the sign-up process should be quick and easy. Selecting the language is ok because the new user can use the platform using their preferred language from the start. Other settings like measurement can be set later.

@@ -17,11 +17,18 @@ class RegisterForm(SanitizeFieldsForm, forms.ModelForm):
email = forms.EmailField(required=True)
password = forms.CharField(widget=forms.PasswordInput())
MIN_LENGTH = 10
language = forms.ChoiceField(
Copy link
Member

Choose a reason for hiding this comment

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

Like in your previous PR, you don't need to define the field for the form explicitly; unless you want to use a form field different from the form field corresponding to the model field. For example, if you want to make a field that is not required on the model required through the form, or if you want to use a different widget (say the model defines a CharField but you only want to accept numbers in the form).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @oliverroick thanks for the feedback. About adding extra things to the signup, Chandra and I were planning to add only the language. We don't plan to put the measurement either the avatar choice.
About the form field comment, does this mean I should also remove the form field declaration in ProfileForm? We may have added the form.field to override the error message. I'm still not sure how to write a custom error message otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

I think you could remove the declaration in the Profile form as well.

Regarding custom error messages; it's possible like (Example is shamelessly stolen from the Django Docs:

from django.utils.translation import ugettext_lazy as _

class AuthorForm(ModelForm):
    class Meta:
        model = Author
        fields = ('name', 'title', 'birth_date')
        error_messages = {
            'name': {
                'max_length': _("This writer's name is too long."),
            },
        }

Copy link
Contributor

@seav seav left a comment

Choose a reason for hiding this comment

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

Hi @laura-barluzzi. To add to what @oliverroick has already said, I don't think you really need to provide a custom error message for the language field in the registration form. A normal user will never encounter an error because this is a dropdown field with no normal way to select an invalid language. The only way you can force an error is if you manipulate the HTML or mess around with the HTTP communications. These are not something a normal user will do. So there is really no need to provide a custom error message. Besides, the default Django error message ("Select a valid choice. xx is not one of the available choices.") for the abnormal user that does mess things around is already quite good.

@laura-barluzzi
Copy link
Contributor Author

Thank you @seav and @oliverroick for your feedback. I combined all your comments and I finally decided to simplify everything so that:

  1. No form.fields are created for measurement and language. They are directly inherited from User
  2. No custom messages are added for these fields
  3. No tests are necessary since it's all automatic Django now

@@ -310,42 +310,6 @@ def test_update_with_restricted_username(self):
assert serializer2.errors['username'] == [
_("Username cannot be “add” or “new”.")]

def test_update_with_invalid_language(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

As I discussed with @oliverroick: We agreed that we still need tests for the serializers because this goes through the API and the user can provide any manner of input formatted any which way, so error checking is still needed. (The error-checking tests for the forms are OK to be deleted.)

Copy link
Member

@oliverroick oliverroick left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. If you add in the serializer tests, we're good to go.

@laura-barluzzi
Copy link
Contributor Author

@seav I added the serializer tests back, I just removed the assert statement for the error message since now it's the default one provided by the Django REST framework error messages.

@amplifi amplifi force-pushed the feature/add_languange_in_registration branch from ae43b32 to f13a3bb Compare July 26, 2017 18:12
@amplifi amplifi merged commit 8851c00 into master Jul 26, 2017
@amplifi amplifi deleted the feature/add_languange_in_registration branch July 26, 2017 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants