Ejemplo n.º 1
0
def clean_user_callback(sender, domain, request_user, user, forms, **kwargs):
    if skip_custom_setup(domain, request_user):
        return

    new_user_form = forms.get('NewMobileWorkerForm')
    update_user_form = forms.get('UpdateCommCareUserInfoForm')
    custom_data = forms.get('CustomDataEditor')
    location_form = forms.get('CommtrackUserForm')

    if update_user_form or new_user_form:
        if not custom_data:
            raise AssertionError("Expected user form and custom data form to be submitted together")

        if sender == 'LocationFormSet':
            location_type = new_user_form.data['location_type']
        elif new_user_form:
            location_type = validate_location(domain, new_user_form).location_type.code
        else:
            location = user.get_sql_location(domain)
            if not location:
                return
            location_type = user.get_sql_location(domain).location_type.code

        if 'usertype' not in custom_data.form.cleaned_data:
            return  # There was probably a validation error
        usertype = custom_data.form.cleaned_data['usertype']
        validate_usertype(location_type, usertype, custom_data)
        if new_user_form:
            pass
        else:
            validate_role_unchanged(domain, user, update_user_form)

    if location_form:
        location_form.add_error('assigned_locations', _("You cannot edit the location of existing users."))
Ejemplo n.º 2
0
 def _process_individual_form(self, form_name, form_classes):
     forms = self.get_forms(form_classes, (form_name, ))
     form = forms.get(form_name)
     if not form:
         return HttpResponseForbidden()
     elif form.is_valid():
         return self.forms_valid(forms, form_name)
     else:
         return self.forms_invalid(forms)
Ejemplo n.º 3
0
def get_form_class(forms, form_id, default_form):
    print('Utils_get_form_class :', forms)

    form_class = forms.get(form_id, default_form)
    print('Utils_get_form_class :', form_class)
    if isinstance(form_class, six.string_types):
        print('Utils_get_form_class :', import_attribute(form_class))
        form_class = import_attribute(form_class)
    return form_class
Ejemplo n.º 4
0
 def _process_grouped_forms(self, group_name, form_classes):
     form_names = self.grouped_forms[group_name]
     forms = self.get_forms(form_classes, form_names)
     if all([
             forms.get(form_name).is_valid()
             for form_name in form_names.values()
     ]):
         return self.forms_valid(forms)
     else:
         return self.forms_invalid(forms)