Пример #1
0
 def custom_data(self):
     return CustomDataEditor(
         field_view=UserFieldsView,
         domain=self.domain,
         post_dict=self.request.POST if self.request.method == "POST" else None,
         required_only=True,
         angular_model="mobileWorker.customFields",
     )
Пример #2
0
 def custom_data(self):
     return CustomDataEditor(
         field_view=ProductFieldsView,
         domain=self.domain,
         required_only=True,
         post_dict=self.request.POST
         if self.request.method == "POST" else None,
     )
Пример #3
0
 def custom_data(self):
     from corehq.apps.users.views.mobile.custom_data_fields import UserFieldsView
     return CustomDataEditor(
         domain=self.domain,
         field_view=UserFieldsView,
         existing_custom_data=self.editable_user.user_data,
         post_dict=self.data,
     )
Пример #4
0
 def custom_data(self):
     is_custom_data_post = self.request.method == "POST" and self.request.POST['form_type'] == "update-user"
     return CustomDataEditor(
         field_view=UserFieldsView,
         domain=self.domain,
         existing_custom_data=self.editable_user.user_data,
         post_dict=self.request.POST if is_custom_data_post else None,
     )
Пример #5
0
 def _get_custom_user_data(self, bound_data):
     from corehq.apps.users.views.mobile.custom_data_fields import UserFieldsView
     user_data = CustomDataEditor(
         field_view=UserFieldsView,
         domain=self.domain,
         post_dict=bound_data,
         required_only=True,
         # Set a different prefix so it's not confused with custom location data
         prefix='user_data',
     )
     return user_data
Пример #6
0
    def test_validate_usertype(self):
        user = self.make_user('jon-snow@website', 'DTO')
        loc_type = self.location_types['dto'].code

        # Try submitting an invalid usertype
        custom_data = CustomDataEditor(
            field_view=UserFieldsView,
            domain=self.domain,
            existing_custom_data=user.user_data,
            post_dict={'data-field-usertype': ['sto']},
        )
        validate_usertype(loc_type, 'sto', custom_data)
        self.assertInvalid(custom_data)

        # Try submitting a valid usertype
        custom_data = CustomDataEditor(
            field_view=UserFieldsView,
            domain=self.domain,
            existing_custom_data=user.user_data,
            post_dict={'data-field-usertype': ['deo']},  # invalid usertype
        )
        validate_usertype(loc_type, 'deo', custom_data)
        self.assertValid(custom_data)
Пример #7
0
    def get_custom_data(self, bound_data, is_new):
        from .views import LocationFieldsView

        existing = self.location.metadata

        # Don't show validation error preemptively on new user creation
        if is_new and bound_data is None:
            existing = None

        return CustomDataEditor(
            field_view=LocationFieldsView,
            domain=self.domain,
            # For new locations, only display required fields
            required_only=is_new,
            existing_custom_data=existing,
            post_dict=bound_data,
        )
Пример #8
0
    def test_signal(self):
        # This test runs the whole callback via a signal as an integration test
        # To verify that it's working, it checks for errors triggered in `validate_usertype`
        user = self.make_user('*****@*****.**', 'DTO')
        data = {
            'first_name': 'Aemon',
            'last_name': 'Targaryon',
            'language': '',
            'loadtest_factor': '',
            'role': '',
            'form_type': 'update-user',
            'email': '*****@*****.**',
            'data-field-usertype': ['tbhv'],  # invalid usertype
        }
        user_form = UpdateCommCareUserInfoForm(
            data=data,
            existing_user=user,
            domain=self.domain,
        )
        custom_data = CustomDataEditor(
            field_view=UserFieldsView,
            domain=self.domain,
            existing_custom_data=user.user_data,
            post_dict=data,
        )
        self.assertValid(user_form)
        self.assertValid(custom_data)
        clean_commcare_user.send('BaseEditUserView.update_user',
                                 domain=self.domain,
                                 request_user=self.web_user,
                                 user=user,
                                 forms={
                                     'UpdateCommCareUserInfoForm': user_form,
                                     'CustomDataEditor': custom_data
                                 })
        self.assertValid(user_form)
        self.assertInvalid(custom_data)  # there should be an error

        data['data-field-usertype'] = 'dto'  # valid usertype
        form = UpdateCommCareUserInfoForm(
            data=data,
            existing_user=user,
            domain=self.domain,
        )
        self.assertValid(form)
Пример #9
0
    def _get_custom_location_data(self, bound_data, is_new):
        from .views import LocationFieldsView

        existing = self.location.metadata

        # Don't show validation error preemptively on new user creation
        if is_new and bound_data is None:
            existing = None

        custom_data = CustomDataEditor(
            field_view=LocationFieldsView,
            domain=self.domain,
            # For new locations, only display required fields
            required_only=is_new,
            existing_custom_data=existing,
            post_dict=bound_data,
        )
        custom_data.form.helper.label_class = 'col-sm-3 col-md-4 col-lg-2'
        custom_data.form.helper.field_class = 'col-sm-4 col-md-5 col-lg-3'
        return custom_data
Пример #10
0
 def custom_data(self):
     return CustomDataEditor(
         field_view=UserFieldsView,
         domain=self.domain,
         post_dict=self.request.POST if self.request.method == "POST" else None,
     )