Пример #1
0
 def _send_clean_signals(self):
     clean_location.send(
         self.__class__.__name__,
         domain=self.domain,
         request_user=self.request_user,
         location=self.location,
         forms={
             self.location_form.__class__.__name__:
             self.location_form,
             self.custom_location_data.__class__.__name__:
             self.custom_location_data
         },
     )
     if self.include_user_forms:
         clean_commcare_user.send(
             'LocationFormSet',
             domain=self.domain,
             request_user=self.request_user,
             user=self.user,
             forms={
                 self.user_form.__class__.__name__:
                 self.user_form,
                 self.custom_user_data.__class__.__name__:
                 self.custom_user_data,
             })
Пример #2
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)
Пример #3
0
 def post(self, request, *args, **kwargs):
     saved = False
     if self.request.POST['form_type'] == "commtrack":
         if self.commtrack_form.is_valid():
             clean_commcare_user.send(
                 'BaseEditUserView.commtrack',
                 domain=self.domain,
                 request_user=self.request.couch_user,
                 user=self.editable_user,
                 forms={
                     self.commtrack_form.__class__.__name__:
                     self.commtrack_form
                 })
             if self.commtrack_form.is_valid():
                 self.commtrack_form.save(self.editable_user)
                 saved = True
     elif self.request.POST['form_type'] == "update-user":
         self.form_user_update.is_valid()
         forms = {
             self.form_user_update.__class__.__name__: self.form_user_update
         }
         if hasattr(self, 'custom_data'):
             self.custom_data.is_valid()
             forms[self.custom_data.__class__.__name__] = self.custom_data
         clean_commcare_user.send('BaseEditUserView.update_user',
                                  domain=self.domain,
                                  request_user=self.request.couch_user,
                                  user=self.editable_user,
                                  forms=forms)
         if all([self.update_user(), self.custom_user_is_valid()]):
             messages.success(
                 self.request,
                 _('Changes saved for user "%s"') %
                 self.editable_user.raw_username)
             saved = True
     if saved:
         return HttpResponseRedirect(self.page_url)
     else:
         return self.get(request, *args, **kwargs)