Created
September 5, 2018 13:33
-
-
Save jerinisready/dbeeaab2d41da2a25f8d97de00bd6dd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CenterRegistrationCreateForm(BootstrapMPNodeForm): | |
| """ | |
| This form is used by super admin for first time creation. | |
| """ | |
| description = forms.CharField(max_length=500) | |
| governed_by = forms.ModelChoiceField(GoverningBody.super_manager, empty_label=settings.EMPTY_LABEL, required=True) | |
| # TODO: district foreign key dropdown (should depend on the state selected ?) | |
| class Meta: | |
| model = GoverningBody | |
| fields = ( 'governed_by', 'description' ) | |
| def __init__(self, **kwargs): | |
| request = kwargs.pop('request', None) | |
| super(CenterRegistrationCreateForm, self).__init__(**kwargs) | |
| queryset = GoverningBody.objects.filter(type__level_id=UserType.STATE_LEVEL) | |
| if request: | |
| council = request.council | |
| if council: | |
| user_level_id = council.type.level_id | |
| if user_level_id == UserType.SA_LEVEL: | |
| """Superadmin must get all states""" | |
| pass | |
| elif user_level_id == UserType.GC_LEVEL: | |
| """General_councel must get states with governed_by = request.user""" | |
| queryset = queryset.filter(governed_by=council) | |
| elif user_level_id == UserType.STATE_LEVEL: | |
| """State must get states with that state itesef""" | |
| queryset = queryset.filter(id=council.id) | |
| self.fields['governed_by'].queryset = queryset | |
| self.fields['governed_by'].choices = [option for option in self.fields['governed_by'].choices if option[0]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment