Commit 91a68fd6 authored by okhin's avatar okhin 🚴

Moar jedis

parent a85b9a07
......@@ -5,14 +5,18 @@ groups = ["droid", "jedi", "padawan"]
permissions = {
"droid": [],
"jedi": [
"can_change_status", "can_change_priority", "can_vote", "can_edit", "can_edit_users", "can_delete_users", "can_create_user",
"can_change_status", "can_change_priority", "can_vote", "can_edit",
"can_edit_users", "can_delete_users", "can_create_user",
],
"padawan": ["can_vote", "add_article"]
}
class Command(BaseCommand):
help = "Adds initial groups for the application (jedis and padawans). Existing user are promoted as padawans."
help = """
Adds initial groups for the application (jedis, droids and padawans).
Existing user are promoted as padawans and Superuser are promoted to jedi.
"""
def handle(self, *args, **options):
......@@ -24,4 +28,7 @@ class Command(BaseCommand):
users = User.objects.all()
for user in users:
user.groups.add(Group.objects.get(name="padawan"))
if user.is_superuser():
user.group.adds(Group.objects.get(name='jedi'))
else:
user.groups.add(Group.objects.get(name="padawan"))
......@@ -23,7 +23,8 @@ class UserProfileInline(admin.StackedInline):
class UserProfileAdmin(UserAdmin):
inlines = [UserProfileInline]
list_display = ("username", "email", "first_name", "last_name", "is_staff", "get_groups")
list_display = ("username", "email", "first_name", "last_name",
"is_staff", "get_groups")
fieldsets = (
(None, {"fields": ("username", "password")}),
......@@ -36,5 +37,6 @@ class UserProfileAdmin(UserAdmin):
return ", ".join(sorted([g.name for g in obj.groups.all()]))
get_groups.short_description = _("Groups")
admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)
......@@ -6,6 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix
from django.views.generic.list import ListView
from django.views.generic.edit import DeleteView, UpdateView
class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
model = User
paginate_by = 20
......@@ -22,6 +23,7 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
return context
class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = User
permission_required = 'userprofile.can_edit_users'
......@@ -31,6 +33,7 @@ class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
fields = ['groups']
success_url = reverse_lazy("users:list")
class UserDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
model = User
permission_required = 'userprofile.can_delete_users'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment