I feel that the code can be simplified to be more readable here and maybe in other places too. Many branches are to blame imho. For example here we can
```

form = form_class(request.POST or None, instance=group)
if form.is_valid():
 ... valid code ...

context = {....
```