Mostly progress on user config page

This commit is contained in:
Walter 2025-02-18 13:59:12 +01:00
parent debee4864a
commit 01ee684113
9 changed files with 70 additions and 10 deletions

View File

@ -40,6 +40,7 @@ function bloonsa_update_data(level_id) {
} }
} }
}; };
xhr.timeout = 5000;
xhr.send(JSON.stringify({ xhr.send(JSON.stringify({
level_id: level_id level_id: level_id
})); }));

View File

@ -3,3 +3,6 @@ django-crispy-forms
crispy-bulma crispy-bulma
django-extensions django-extensions
tqdm tqdm
Pillow
django-resized
django-cleanup

View File

@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/ https://docs.djangoproject.com/en/3.2/ref/settings/
""" """
import os
from pathlib import Path from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -41,6 +41,7 @@ INSTALLED_APPS = [
"crispy_forms", "crispy_forms",
"crispy_bulma", "crispy_bulma",
"django_extensions", "django_extensions",
"django_cleanup.apps.CleanupConfig",
# Global # Global
"users", "users",
@ -130,7 +131,10 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/ # https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = "/static/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
@ -138,6 +142,6 @@ STATIC_URL = '/static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",) CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
CRISPY_TEMPLATE_PACK = 'bulma' CRISPY_TEMPLATE_PACK = "bulma"

View File

@ -13,10 +13,11 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.urls import path, include, re_path from django.urls import path, include, re_path
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.conf import settings
urlpatterns = [ urlpatterns = [
path("", RedirectView.as_view(pattern_name="bloonsa_game:game", permanent=False), name="index"), path("", RedirectView.as_view(pattern_name="bloonsa_game:game", permanent=False), name="index"),
@ -25,3 +26,6 @@ urlpatterns = [
path("a/", include("bloonsa_game.urls", namespace="bloonsa_game")), path("a/", include("bloonsa_game.urls", namespace="bloonsa_game")),
path("users/", include("users.urls", namespace="users")), path("users/", include("users.urls", namespace="users")),
] ]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

View File

@ -69,3 +69,6 @@ class UserLoginForm(AuthenticationForm):
fields = [ fields = [
"username", "username",
] ]
class UserConfigForm():
raise NotImplementedError()

View File

@ -1,9 +1,20 @@
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django_resized import ResizedImageField
class Player(models.Model): class Player(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="player") user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="player")
# Profile
bio = models.TextField(max_length=128, null=True)
avatar = ResizedImageField(default="default.jpg",
size=[256, 256],
upload_to="avatars",
keep_meta=False,
force_format="JPEG",
quality=75)
# Logging # Logging
creation_ip = models.GenericIPAddressField() creation_ip = models.GenericIPAddressField()
latest_ip = models.GenericIPAddressField() latest_ip = models.GenericIPAddressField()

View File

@ -0,0 +1,11 @@
{% extends "bloonsa_game/base.html" %}
{% load crispy_forms_tags %}
{% block title %}
My Profile
{% endblock title %}
{% block content %}
<h1>Profile settings</h1>
{% crispy form %}
{% endblock %}

View File

@ -1,11 +1,13 @@
from django.urls import path, include from django.urls import path, include
from users.views import LoginView, RegisterView, LogoutView from users.views import (LoginView, RegisterView,
LogoutView, ConfigView)
app_name = "users" app_name = "users"
urlpatterns = [ urlpatterns = [
path("login", LoginView.as_view(), name="login"), path("login", LoginView.as_view(), name="login"),
path("register", RegisterView.as_view(), name="register"), path("register", RegisterView.as_view(), name="register"),
path("logout", LogoutView.as_view(), name="logout") path("logout", LogoutView.as_view(), name="logout"),
path("config", ConfigView.as_view(), name="config"),
] ]

View File

@ -3,7 +3,7 @@ from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.views.generic import TemplateView from django.views.generic import TemplateView
from users.forms import UserRegisterForm, UserLoginForm from users.forms import UserRegisterForm, UserLoginForm, UserConfigForm
from users.models import Player from users.models import Player
from users.util import bloonsa_util, actions from users.util import bloonsa_util, actions
@ -46,7 +46,6 @@ class RegisterView(TemplateView):
class LogoutView(TemplateView): class LogoutView(TemplateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if request.user.is_authenticated: if request.user.is_authenticated:
bloonsa_util.tag_player(request=request) bloonsa_util.tag_player(request=request)
@ -56,3 +55,25 @@ class LogoutView(TemplateView):
return redirect("bloonsa_game:game") return redirect("bloonsa_game:game")
class ConfigView(TemplateView):
def get(self, request, *args, **kwargs):
form = UserConfigForm()
return render(request=request,
template_name="users/config.html",
context={"form": form})
def post(self, request, *args, **kwargs):
form = UserConfigForm(request.POST)
if not form.is_valid():
return render(request=request,
template_name="users/config.html",
context={"form": form})
user = form.save()
player = bloonsa_util.init_player(request=request)
login(request=request, user=user)
#bloonsa_util.log(player=player,
# action=actions.login)
return render(request=request,
template_name="users/config.html",
context={"form": form})