mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Allow new users to create character using admin
This commit is contained in:
parent
cdb7d1c27e
commit
ccd4b7f1e2
3 changed files with 27 additions and 1 deletions
|
@ -21,7 +21,7 @@ from django.urls import include, path
|
||||||
from django_registration.backends.activation.views import RegistrationView
|
from django_registration.backends.activation.views import RegistrationView
|
||||||
|
|
||||||
from common.forms import RegistrationForm
|
from common.forms import RegistrationForm
|
||||||
from common.views import hello_world
|
from common.views import ActivationView, hello_world
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
|
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
|
||||||
|
@ -30,6 +30,11 @@ urlpatterns = [
|
||||||
RegistrationView.as_view(form_class=RegistrationForm),
|
RegistrationView.as_view(form_class=RegistrationForm),
|
||||||
name="django_registration_register",
|
name="django_registration_register",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"accounts/activate/<str:activation_key>/",
|
||||||
|
ActivationView.as_view(),
|
||||||
|
name="django_registration_activate",
|
||||||
|
),
|
||||||
path("accounts/", include("django_registration.backends.activation.urls")),
|
path("accounts/", include("django_registration.backends.activation.urls")),
|
||||||
path("accounts/", include("django.contrib.auth.urls")),
|
path("accounts/", include("django.contrib.auth.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<a href="{% url "logout" %}">Déconnexion</a>
|
||||||
|
{% endif %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% include "common/hello-random.html" %}
|
{% include "common/hello-random.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,7 +1,25 @@
|
||||||
|
from django.contrib.auth.models import Permission
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
|
from django_registration.backends.activation.views import (
|
||||||
|
ActivationView as BaseActivationView,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def hello_world(request: WSGIRequest) -> HttpResponse:
|
def hello_world(request: WSGIRequest) -> HttpResponse:
|
||||||
return redirect("character:list")
|
return redirect("character:list")
|
||||||
|
|
||||||
|
|
||||||
|
class ActivationView(BaseActivationView):
|
||||||
|
def activate(self, *args, **kwargs):
|
||||||
|
user = super().activate(*args, **kwargs)
|
||||||
|
perm = Permission.objects.get(
|
||||||
|
content_type__app_label="character",
|
||||||
|
content_type__model="character",
|
||||||
|
codename="add_character",
|
||||||
|
)
|
||||||
|
user.user_permissions.add(perm)
|
||||||
|
user.is_staff = True
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
Loading…
Reference in a new issue