mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Merge pull request #2180 from bookwyrm-social/set-access-level-user
Fixes setting access level to "user"
This commit is contained in:
commit
97b53d4998
4 changed files with 19 additions and 9 deletions
|
@ -10,3 +10,4 @@ from .landing import *
|
||||||
from .links import *
|
from .links import *
|
||||||
from .lists import *
|
from .lists import *
|
||||||
from .status import *
|
from .status import *
|
||||||
|
from .user_admin import *
|
||||||
|
|
|
@ -4,12 +4,6 @@ from .custom_form import CustomForm
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=missing-class-docstring
|
# pylint: disable=missing-class-docstring
|
||||||
class UserGroupForm(CustomForm):
|
|
||||||
class Meta:
|
|
||||||
model = models.User
|
|
||||||
fields = ["groups"]
|
|
||||||
|
|
||||||
|
|
||||||
class GroupForm(CustomForm):
|
class GroupForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Group
|
model = models.Group
|
||||||
|
|
10
bookwyrm/forms/user_admin.py
Normal file
10
bookwyrm/forms/user_admin.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
""" using django model forms """
|
||||||
|
from bookwyrm import models
|
||||||
|
from .custom_form import CustomForm
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=missing-class-docstring
|
||||||
|
class UserGroupForm(CustomForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.User
|
||||||
|
fields = ["groups"]
|
|
@ -77,8 +77,13 @@ class UserAdmin(View):
|
||||||
def post(self, request, user):
|
def post(self, request, user):
|
||||||
"""update user group"""
|
"""update user group"""
|
||||||
user = get_object_or_404(models.User, id=user)
|
user = get_object_or_404(models.User, id=user)
|
||||||
form = forms.UserGroupForm(request.POST, instance=user)
|
|
||||||
if form.is_valid():
|
if request.POST.get("groups") == "":
|
||||||
form.save()
|
user.groups.set([])
|
||||||
|
form = forms.UserGroupForm(instance=user)
|
||||||
|
else:
|
||||||
|
form = forms.UserGroupForm(request.POST, instance=user)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
data = {"user": user, "group_form": form}
|
data = {"user": user, "group_form": form}
|
||||||
return TemplateResponse(request, "settings/users/user.html", data)
|
return TemplateResponse(request, "settings/users/user.html", data)
|
||||||
|
|
Loading…
Reference in a new issue