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

Location select widget - filter by whether the location "has users" #34912

Merged
merged 10 commits into from
Aug 2, 2024
4 changes: 2 additions & 2 deletions corehq/apps/registration/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from corehq.apps.domain.models import Domain
from corehq.apps.hqwebapp import crispy as hqcrispy
from corehq.apps.programs.models import Program
from corehq.apps.users.forms import BaseLocationForm, BaseTableauUserForm
from corehq.apps.users.forms import SelectUserLocationForm, BaseTableauUserForm
from corehq.apps.users.models import CouchUser


Expand Down Expand Up @@ -483,7 +483,7 @@ def clean_email(self):
return ""


class AdminInvitesUserForm(BaseLocationForm):
class AdminInvitesUserForm(SelectUserLocationForm):
email = forms.EmailField(label="Email Address",
max_length=User._meta.get_field('email').max_length)
role = forms.ChoiceField(choices=(), label="Project Role")
Expand Down
8 changes: 4 additions & 4 deletions corehq/apps/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def render(self, name, value, attrs=None, renderer=None):
})


class BaseLocationForm(forms.Form):
class SelectUserLocationForm(forms.Form):
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

assigned_locations = forms.CharField(
label=gettext_noop("Locations"),
required=False,
Expand All @@ -1156,7 +1156,7 @@ class BaseLocationForm(forms.Form):
def __init__(self, domain: str, *args, **kwargs):
from corehq.apps.locations.forms import LocationSelectWidget
self.request = kwargs.pop('request')
super(BaseLocationForm, self).__init__(*args, **kwargs)
super(SelectUserLocationForm, self).__init__(*args, **kwargs)
self.domain = domain
self.fields['assigned_locations'].widget = LocationSelectWidget(
self.domain, multiselect=True, id='id_assigned_locations',
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def _user_has_permission_to_access_locations(self, new_location_ids):
self.domain, self.request.couch_user))

def clean(self):
self.cleaned_data = super(BaseLocationForm, self).clean()
self.cleaned_data = super(SelectUserLocationForm, self).clean()

primary_location_id = self.cleaned_data['primary_location']
assigned_location_ids = self.cleaned_data.get('assigned_locations', [])
Expand All @@ -1210,7 +1210,7 @@ def clean(self):
return self.cleaned_data


class CommtrackUserForm(BaseLocationForm):
class CommtrackUserForm(SelectUserLocationForm):
program_id = forms.ChoiceField(
label=gettext_noop("Program"),
choices=(),
Expand Down