support createsuperuser command
This commit is contained in:
parent
9aed05a560
commit
a578953149
4 changed files with 25 additions and 6 deletions
|
@ -25,7 +25,7 @@ RUN apt-get purge -y --auto-remove \
|
||||||
RUN python3 manage.py compilescss \
|
RUN python3 manage.py compilescss \
|
||||||
&& python3 manage.py collectstatic --noinput
|
&& python3 manage.py collectstatic --noinput
|
||||||
RUN cp -R misc/www /www
|
RUN cp -R misc/www /www
|
||||||
RUN mv static /www/static
|
RUN mv static /www/s
|
||||||
|
|
||||||
# invoke check by default
|
# invoke check by default
|
||||||
CMD [ "python3", "/neodb/manage.py", "check" ]
|
CMD [ "python3", "/neodb/manage.py", "check" ]
|
||||||
|
|
|
@ -201,7 +201,7 @@ if os.getenv("NEODB_SSL", "") != "":
|
||||||
# Static files (CSS, JavaScript, Images)
|
# Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||||
|
|
||||||
STATIC_URL = "/static/"
|
STATIC_URL = "/s/"
|
||||||
STATIC_ROOT = os.environ.get("NEODB_STATIC_ROOT", os.path.join(BASE_DIR, "static/"))
|
STATIC_ROOT = os.environ.get("NEODB_STATIC_ROOT", os.path.join(BASE_DIR, "static/"))
|
||||||
|
|
||||||
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
||||||
|
@ -219,7 +219,7 @@ SILENCED_SYSTEM_CHECKS = [
|
||||||
"fields.W344", # Required by takahe: identical table name in different database
|
"fields.W344", # Required by takahe: identical table name in different database
|
||||||
]
|
]
|
||||||
|
|
||||||
MEDIA_URL = "/media/"
|
MEDIA_URL = "/m/"
|
||||||
MEDIA_ROOT = os.environ.get("NEODB_MEDIA_ROOT", os.path.join(BASE_DIR, "media/"))
|
MEDIA_ROOT = os.environ.get("NEODB_MEDIA_ROOT", os.path.join(BASE_DIR, "media/"))
|
||||||
|
|
||||||
SITE_DOMAIN = os.environ.get("NEODB_SITE_DOMAIN", "nicedb.org")
|
SITE_DOMAIN = os.environ.get("NEODB_SITE_DOMAIN", "nicedb.org")
|
||||||
|
|
|
@ -12,11 +12,11 @@ server {
|
||||||
proxy_pass http://neodb-web:8000;
|
proxy_pass http://neodb-web:8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /static/ {
|
location /s/ {
|
||||||
root /www;
|
root /www;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /media/ {
|
location /m/ {
|
||||||
root /www;
|
root /www;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import re
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser, BaseUserManager
|
||||||
from django.contrib.auth.validators import UnicodeUsernameValidator
|
from django.contrib.auth.validators import UnicodeUsernameValidator
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -48,6 +48,24 @@ class UsernameValidator(UnicodeUsernameValidator):
|
||||||
return super().__call__(value)
|
return super().__call__(value)
|
||||||
|
|
||||||
|
|
||||||
|
class UserManager(BaseUserManager):
|
||||||
|
def create_user(self, username, email, password=None):
|
||||||
|
Takahe.get_domain() # ensure configuration is complete
|
||||||
|
user = User.register(username=username, email=email)
|
||||||
|
return user
|
||||||
|
|
||||||
|
def create_superuser(self, username, email, password=None):
|
||||||
|
from takahe.models import User as TakaheUser
|
||||||
|
|
||||||
|
Takahe.get_domain() # ensure configuration is complete
|
||||||
|
user = User.register(username=username, email=email, is_superuser=True)
|
||||||
|
tu = TakaheUser.objects.get(pk=user.pk, email="@" + username)
|
||||||
|
tu.admin = True
|
||||||
|
tu.set_password(password)
|
||||||
|
tu.save()
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
identity: "APIdentity"
|
identity: "APIdentity"
|
||||||
preference: "Preference"
|
preference: "Preference"
|
||||||
|
@ -113,6 +131,7 @@ class User(AbstractUser):
|
||||||
# store the latest read announcement id,
|
# store the latest read announcement id,
|
||||||
# every time user read the announcement update this field
|
# every time user read the announcement update this field
|
||||||
read_announcement_index = models.PositiveIntegerField(default=0)
|
read_announcement_index = models.PositiveIntegerField(default=0)
|
||||||
|
objects = UserManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
|
|
Loading…
Add table
Reference in a new issue