Mostly progress on user config page
This commit is contained in:
parent
debee4864a
commit
01ee684113
@ -40,6 +40,7 @@ function bloonsa_update_data(level_id) {
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.timeout = 5000;
|
||||
xhr.send(JSON.stringify({
|
||||
level_id: level_id
|
||||
}));
|
||||
|
||||
@ -2,4 +2,7 @@ django==5.1.*
|
||||
django-crispy-forms
|
||||
crispy-bulma
|
||||
django-extensions
|
||||
tqdm
|
||||
tqdm
|
||||
Pillow
|
||||
django-resized
|
||||
django-cleanup
|
||||
@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/3.2/ref/settings/
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
||||
"crispy_forms",
|
||||
"crispy_bulma",
|
||||
"django_extensions",
|
||||
"django_cleanup.apps.CleanupConfig",
|
||||
|
||||
# Global
|
||||
"users",
|
||||
@ -130,7 +131,10 @@ USE_TZ = True
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# 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
|
||||
# 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'
|
||||
|
||||
CRISPY_ALLOWED_TEMPLATE_PACKS = ("bulma",)
|
||||
CRISPY_TEMPLATE_PACK = 'bulma'
|
||||
CRISPY_TEMPLATE_PACK = "bulma"
|
||||
|
||||
|
||||
|
||||
@ -13,10 +13,11 @@ Including another URLconf
|
||||
1. Import the include() function: from django.urls import include, path
|
||||
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.urls import path, include, re_path
|
||||
from django.views.generic.base import RedirectView
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
urlpatterns = [
|
||||
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("users/", include("users.urls", namespace="users")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
@ -68,4 +68,7 @@ class UserLoginForm(AuthenticationForm):
|
||||
model = User
|
||||
fields = [
|
||||
"username",
|
||||
]
|
||||
]
|
||||
|
||||
class UserConfigForm():
|
||||
raise NotImplementedError()
|
||||
@ -1,9 +1,20 @@
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import User
|
||||
from django_resized import ResizedImageField
|
||||
|
||||
|
||||
class Player(models.Model):
|
||||
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
|
||||
creation_ip = models.GenericIPAddressField()
|
||||
latest_ip = models.GenericIPAddressField()
|
||||
|
||||
11
app/users/templates/users/config.html
Normal file
11
app/users/templates/users/config.html
Normal 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 %}
|
||||
@ -1,11 +1,13 @@
|
||||
from django.urls import path, include
|
||||
|
||||
from users.views import LoginView, RegisterView, LogoutView
|
||||
from users.views import (LoginView, RegisterView,
|
||||
LogoutView, ConfigView)
|
||||
|
||||
app_name = "users"
|
||||
|
||||
urlpatterns = [
|
||||
path("login", LoginView.as_view(), name="login"),
|
||||
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"),
|
||||
]
|
||||
|
||||
@ -3,7 +3,7 @@ from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
|
||||
from django.shortcuts import render, redirect
|
||||
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.util import bloonsa_util, actions
|
||||
|
||||
@ -46,7 +46,6 @@ class RegisterView(TemplateView):
|
||||
|
||||
|
||||
class LogoutView(TemplateView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if request.user.is_authenticated:
|
||||
bloonsa_util.tag_player(request=request)
|
||||
@ -56,3 +55,25 @@ class LogoutView(TemplateView):
|
||||
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})
|
||||
Loading…
Reference in New Issue
Block a user