def clean_workgroup(self): # raise a permission denied before cleaning if possible. # This gives us a 'clearer' error # cleaning before checking gives a "invalid selection" even if a user isn't allowed to change workgroups. if self.instance.pk is not None: if 'workgroup' in self.data.keys() and str( self.data['workgroup']) is not None: old_wg_pk = None if self.instance.workgroup: old_wg_pk = str(self.instance.workgroup.pk) if str(self.data['workgroup']) != str(old_wg_pk) and not (str( self.data['workgroup']) == "" and old_wg_pk is None): if not user_can_move_any_workgroup(self.user): raise forms.ValidationError( WorkgroupVerificationMixin. cant_move_any_permission_error) if not user_can_remove_from_workgroup( self.user, self.instance.workgroup): raise forms.ValidationError( WorkgroupVerificationMixin. cant_move_from_permission_error) new_workgroup = self.cleaned_data['workgroup'] if self.instance.pk is not None: if 'workgroup' in self.cleaned_data.keys( ) and self.instance.workgroup != new_workgroup: if not user_can_move_between_workgroups( self.user, self.instance.workgroup, new_workgroup): self.data = self.data.copy( ) # need to make a mutable version of the POST querydict. self.data['workgroup'] = self.instance.workgroup.pk raise forms.ValidationError(WorkgroupVerificationMixin. cant_move_to_permission_error) return new_workgroup
def clean_workgroup(self): # raise a permission denied before cleaning if possible. # This gives us a 'clearer' error # cleaning before checking gives a "invalid selection" even if a user isn't allowed to change workgroups. if self.instance.pk is not None: if 'workgroup' in self.data.keys() and str(self.data['workgroup']) is not None: if str(self.data['workgroup']) != str(self.instance.workgroup.pk): if not user_can_move_any_workgroup(self.user): raise forms.ValidationError(WorkgroupVerificationMixin.cant_move_any_permission_error) if not user_can_remove_from_workgroup(self.user, self.instance.workgroup): raise forms.ValidationError(WorkgroupVerificationMixin.cant_move_from_permission_error) new_workgroup = self.cleaned_data['workgroup'] if self.instance.pk is not None: if 'workgroup' in self.cleaned_data.keys() and self.instance.workgroup != new_workgroup: if not user_can_move_between_workgroups(self.user, self.instance.workgroup, new_workgroup): self.data = self.data.copy() # need to make a mutable version of the POST querydict. self.data['workgroup'] = self.instance.workgroup.pk raise forms.ValidationError(WorkgroupVerificationMixin.cant_move_to_permission_error) return new_workgroup