dj-tinyuser 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. dj_tinyuser/__init__.py +0 -0
  2. dj_tinyuser/account_adapter.py +90 -0
  3. dj_tinyuser/admin.py +31 -0
  4. dj_tinyuser/api/__init__.py +1 -0
  5. dj_tinyuser/api/apps.py +9 -0
  6. dj_tinyuser/api/locale/de/LC_MESSAGES/django.po +43 -0
  7. dj_tinyuser/api/permissions.py +24 -0
  8. dj_tinyuser/api/serializers.py +208 -0
  9. dj_tinyuser/api/tests/__init__.py +1 -0
  10. dj_tinyuser/api/tests/test_invitations_api.py +182 -0
  11. dj_tinyuser/api/tests/test_profile_api.py +1 -0
  12. dj_tinyuser/api/tests/test_user_api.py +261 -0
  13. dj_tinyuser/api/urls.py +19 -0
  14. dj_tinyuser/api/views.py +65 -0
  15. dj_tinyuser/apps.py +7 -0
  16. dj_tinyuser/context_processors.py +31 -0
  17. dj_tinyuser/exceptions.py +6 -0
  18. dj_tinyuser/forms.py +96 -0
  19. dj_tinyuser/global_templates/__init__.py +3 -0
  20. dj_tinyuser/global_templates/account/login.html +1 -0
  21. dj_tinyuser/global_templates/account/password_reset.html +1 -0
  22. dj_tinyuser/global_templates/account/signup.html +1 -0
  23. dj_tinyuser/global_templates/allauth/layouts/base.html +1 -0
  24. dj_tinyuser/input_files/style.scss +27 -0
  25. dj_tinyuser/locale/de/LC_MESSAGES/django.po +880 -0
  26. dj_tinyuser/logging.py +11 -0
  27. dj_tinyuser/managers.py +64 -0
  28. dj_tinyuser/migrations/0001_initial.py +331 -0
  29. dj_tinyuser/migrations/__init__.py +0 -0
  30. dj_tinyuser/mixins/htmx.py +20 -0
  31. dj_tinyuser/models/__init__.py +11 -0
  32. dj_tinyuser/models/fields.py +58 -0
  33. dj_tinyuser/models/tinyuser.py +125 -0
  34. dj_tinyuser/models/userprofile.py +216 -0
  35. dj_tinyuser/settings.py +72 -0
  36. dj_tinyuser/sidebar.py +55 -0
  37. dj_tinyuser/static/tinyuser/css/html.css +28 -0
  38. dj_tinyuser/templates/tinyuser/bootstrap5/account/login.dj.html +68 -0
  39. dj_tinyuser/templates/tinyuser/bootstrap5/account/password_reset.dj.html +19 -0
  40. dj_tinyuser/templates/tinyuser/bootstrap5/account/signup.dj.html +24 -0
  41. dj_tinyuser/templates/tinyuser/bootstrap5/base.dj.html +31 -0
  42. dj_tinyuser/templates/tinyuser/bootstrap5/index.html +10 -0
  43. dj_tinyuser/templates/tinyuser/bootstrap5/invite/failed.html +9 -0
  44. dj_tinyuser/templates/tinyuser/bootstrap5/invite/hx/failed.html +14 -0
  45. dj_tinyuser/templates/tinyuser/bootstrap5/invite/hx/invite.html +26 -0
  46. dj_tinyuser/templates/tinyuser/bootstrap5/invite/hx/success.html +14 -0
  47. dj_tinyuser/templates/tinyuser/bootstrap5/invite/invite.html +23 -0
  48. dj_tinyuser/templates/tinyuser/bootstrap5/invite/success.html +9 -0
  49. dj_tinyuser/templates/tinyuser/bootstrap5/profile/edit.html +10 -0
  50. dj_tinyuser/templates/tinyuser/bootstrap5/profile/hx/edit.html +151 -0
  51. dj_tinyuser/templates/tinyuser/bootstrap5/profile/hx/profile.html +120 -0
  52. dj_tinyuser/templates/tinyuser/bootstrap5/profile/hx/settings.html +27 -0
  53. dj_tinyuser/templates/tinyuser/bootstrap5/profile/profile.html +46 -0
  54. dj_tinyuser/templates/tinyuser/bootstrap5/profile/settings.html +18 -0
  55. dj_tinyuser/templates/tinyuser/bootstrap5/snippets/account/form +9 -0
  56. dj_tinyuser/templates/tinyuser/bs5docs/account/login.dj.html +66 -0
  57. dj_tinyuser/templates/tinyuser/bs5docs/account/signup.dj.html +26 -0
  58. dj_tinyuser/templates/tinyuser/html/account/login.dj.html +58 -0
  59. dj_tinyuser/templates/tinyuser/html/account/password_reset.dj.html +20 -0
  60. dj_tinyuser/templates/tinyuser/html/account/signup.dj.html +22 -0
  61. dj_tinyuser/templates/tinyuser/html/base.dj.html +27 -0
  62. dj_tinyuser/templates/tinyuser/html/index.html +7 -0
  63. dj_tinyuser/templates/tinyuser/html/invite/failed.html +9 -0
  64. dj_tinyuser/templates/tinyuser/html/invite/hx/failed.html +0 -0
  65. dj_tinyuser/templates/tinyuser/html/invite/hx/invite.html +0 -0
  66. dj_tinyuser/templates/tinyuser/html/invite/hx/success.html +0 -0
  67. dj_tinyuser/templates/tinyuser/html/invite/invite.html +0 -0
  68. dj_tinyuser/templates/tinyuser/html/invite/success.html +0 -0
  69. dj_tinyuser/templates/tinyuser/html/logout/navbar.dj.html +5 -0
  70. dj_tinyuser/templates/tinyuser/html/profile/edit.html +0 -0
  71. dj_tinyuser/templates/tinyuser/html/profile/hx/edit.html +0 -0
  72. dj_tinyuser/templates/tinyuser/html/profile/hx/profile.html +0 -0
  73. dj_tinyuser/templates/tinyuser/html/profile/hx/settings.html +0 -0
  74. dj_tinyuser/templates/tinyuser/html/profile/profile.html +0 -0
  75. dj_tinyuser/templates/tinyuser/html/profile/settings.html +0 -0
  76. dj_tinyuser/templates/tinyuser/html/theme/nav.dj.html +20 -0
  77. dj_tinyuser/templates.json +39 -0
  78. dj_tinyuser/templates.yml +23 -0
  79. dj_tinyuser/templatetags/__init__.py +0 -0
  80. dj_tinyuser/templatetags/tinyuser.py +14 -0
  81. dj_tinyuser/tests/__init__.py +0 -0
  82. dj_tinyuser/tests/test_tinyuser_model.py +46 -0
  83. dj_tinyuser/tests/test_userprofile_model.py +56 -0
  84. dj_tinyuser/urls.py +22 -0
  85. dj_tinyuser/utils.py +18 -0
  86. dj_tinyuser/views/__init__.py +12 -0
  87. dj_tinyuser/views/dashboard.py +0 -0
  88. dj_tinyuser/views/index.py +15 -0
  89. dj_tinyuser/views/invite.py +141 -0
  90. dj_tinyuser/views/profile.py +470 -0
  91. dj_tinyuser-0.0.1.dist-info/METADATA +194 -0
  92. dj_tinyuser-0.0.1.dist-info/RECORD +97 -0
  93. dj_tinyuser-0.0.1.dist-info/WHEEL +4 -0
  94. dj_tinyuser-0.0.1.dist-info/licenses/LICENSE +12 -0
  95. dj_tinyuser-0.0.1.dist-info/licenses/LICENSE.django-project +12 -0
  96. dj_tinyuser-0.0.1.dist-info/licenses/LICENSE.django-project.md +15 -0
  97. dj_tinyuser-0.0.1.dist-info/licenses/LICENSE.md +15 -0
dj_tinyuser/logging.py ADDED
@@ -0,0 +1,11 @@
1
+ from dj_templates.utils.logging import get_logger
2
+ from django.conf import settings
3
+
4
+
5
+ def get_tinyuser_logger(name: str):
6
+ prefix = getattr(
7
+ settings,
8
+ "TINYUSER_LOGGER_PREFIX",
9
+ getattr(settings, "LOGGER_PREFIX", "django"),
10
+ )
11
+ return get_logger(name, prefix=prefix)
@@ -0,0 +1,64 @@
1
+ from logging import getLogger
2
+
3
+ from django.contrib.auth.models import BaseUserManager
4
+ from django.utils.translation import gettext as _
5
+
6
+ logger = getLogger("django." + __name__)
7
+
8
+
9
+ class TinyUserManager(BaseUserManager):
10
+ """
11
+ Custom user manager for TinyUser model.
12
+
13
+ Provides methods to create regular users and superusers.
14
+ """
15
+
16
+ def create_user(self, email, username, password=None, **extra_fields):
17
+ """
18
+ Create and save a regular user with the given email, username, and password.
19
+
20
+ :param email: The email address of the user.
21
+ :type email: str
22
+ :param username: The username of the user.
23
+ :type username: str
24
+ :param password: The password for the user, defaults to None
25
+ :type password: str, optional
26
+ :raises ValueError: If the email is not provided.
27
+ :raises ValueError: If the username is not provided.
28
+ :return: The created user instance.
29
+ :rtype: TinyUser
30
+ """
31
+ if not email:
32
+ raise ValueError(_("The Email field must be set"))
33
+ email = self.normalize_email(email)
34
+ if not username:
35
+ raise ValueError(_("The Username field must be set"))
36
+ user = self.model(email=email, username=username, **extra_fields)
37
+ user.set_password(password)
38
+ user.save(using=self._db)
39
+ return user
40
+
41
+ def create_superuser(self, email, username, password=None, **extra_fields):
42
+ """
43
+ Create and save a superuser with the given email, username, and password.
44
+
45
+ :param email: The email address of the superuser.
46
+ :type email: str
47
+ :param username: The username of the superuser.
48
+ :type username: str
49
+ :param password: The password for the superuser, defaults to None
50
+ :type password: str, optional
51
+ :raises ValueError: If is_staff is not True.
52
+ :raises ValueError: If is_superuser is not True.
53
+ :return: The created superuser instance.
54
+ :rtype: TinyUser
55
+ """
56
+ extra_fields.setdefault("is_staff", True)
57
+ extra_fields.setdefault("is_superuser", True)
58
+
59
+ if extra_fields.get("is_staff") is not True:
60
+ raise ValueError(_("Superuser must have is_staff=True."))
61
+ if extra_fields.get("is_superuser") is not True:
62
+ raise ValueError(_("Superuser must have is_superuser=True."))
63
+
64
+ return self.create_user(email, username, password, **extra_fields)
@@ -0,0 +1,331 @@
1
+ # Generated by Django 6.1 on 2026-08-09 19:22
2
+
3
+ import django.db.models.deletion
4
+ import django.utils.timezone
5
+ from django.conf import settings
6
+ from django.db import migrations, models
7
+
8
+ import dj_tinyuser.models.fields
9
+
10
+
11
+ class Migration(migrations.Migration):
12
+
13
+ initial = True
14
+
15
+ dependencies = [
16
+ ("auth", "0012_alter_user_first_name_max_length"),
17
+ ]
18
+
19
+ operations = [
20
+ migrations.CreateModel(
21
+ name="TinyUser",
22
+ fields=[
23
+ (
24
+ "id",
25
+ models.BigAutoField(
26
+ auto_created=True,
27
+ primary_key=True,
28
+ serialize=False,
29
+ verbose_name="ID",
30
+ ),
31
+ ),
32
+ ("password", models.CharField(max_length=128, verbose_name="password")),
33
+ (
34
+ "last_login",
35
+ models.DateTimeField(blank=True, null=True, verbose_name="last login"),
36
+ ),
37
+ (
38
+ "email",
39
+ models.EmailField(
40
+ blank=True,
41
+ db_column="email",
42
+ max_length=254,
43
+ null=True,
44
+ unique=True,
45
+ verbose_name="email address",
46
+ ),
47
+ ),
48
+ (
49
+ "username",
50
+ models.CharField(
51
+ db_column="username",
52
+ max_length=127,
53
+ unique=True,
54
+ verbose_name="username",
55
+ ),
56
+ ),
57
+ (
58
+ "is_active",
59
+ models.BooleanField(db_column="is_active", default=True, verbose_name="active"),
60
+ ),
61
+ (
62
+ "is_staff",
63
+ models.BooleanField(db_column="is_staff", default=False, verbose_name="staff status"),
64
+ ),
65
+ (
66
+ "is_superuser",
67
+ models.BooleanField(
68
+ db_column="is_superuser",
69
+ default=False,
70
+ verbose_name="superuser status",
71
+ ),
72
+ ),
73
+ (
74
+ "is_system_user",
75
+ models.BooleanField(
76
+ db_column="is_system_user",
77
+ default=False,
78
+ verbose_name="system user",
79
+ ),
80
+ ),
81
+ (
82
+ "is_verified",
83
+ models.BooleanField(db_column="is_verified", default=False, verbose_name="verified"),
84
+ ),
85
+ (
86
+ "joined_at",
87
+ models.DateTimeField(
88
+ db_column="joined_at",
89
+ default=django.utils.timezone.now,
90
+ verbose_name="joined at",
91
+ ),
92
+ ),
93
+ (
94
+ "groups",
95
+ models.ManyToManyField(
96
+ blank=True,
97
+ help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.",
98
+ related_name="user_set",
99
+ related_query_name="user",
100
+ to="auth.group",
101
+ verbose_name="groups",
102
+ ),
103
+ ),
104
+ (
105
+ "user_permissions",
106
+ models.ManyToManyField(
107
+ blank=True,
108
+ help_text="Specific permissions for this user.",
109
+ related_name="user_set",
110
+ related_query_name="user",
111
+ to="auth.permission",
112
+ verbose_name="user permissions",
113
+ ),
114
+ ),
115
+ ],
116
+ options={
117
+ "verbose_name": "user",
118
+ "verbose_name_plural": "users",
119
+ "db_table": "tinyuser_user",
120
+ },
121
+ ),
122
+ migrations.CreateModel(
123
+ name="UserProfile",
124
+ fields=[
125
+ (
126
+ "id",
127
+ models.BigAutoField(
128
+ auto_created=True,
129
+ primary_key=True,
130
+ serialize=False,
131
+ verbose_name="ID",
132
+ ),
133
+ ),
134
+ ("first_name", models.CharField(blank=True, max_length=30)),
135
+ ("last_name", models.CharField(blank=True, max_length=30)),
136
+ (
137
+ "bio",
138
+ models.TextField(blank=True, verbose_name="biography (Markdown supported)"),
139
+ ),
140
+ (
141
+ "location",
142
+ models.CharField(blank=True, max_length=255, verbose_name="location"),
143
+ ),
144
+ ("website", models.URLField(blank=True, verbose_name="website")),
145
+ (
146
+ "mastodon_url",
147
+ models.URLField(blank=True, verbose_name="Mastodon profile URL"),
148
+ ),
149
+ (
150
+ "birth_date",
151
+ models.DateField(blank=True, null=True, verbose_name="birth date"),
152
+ ),
153
+ (
154
+ "avatar_small",
155
+ dj_tinyuser.models.fields.RestrictedImageField(
156
+ blank=True,
157
+ null=True,
158
+ upload_to="user/avatars/",
159
+ verbose_name="small profile picture",
160
+ ),
161
+ ),
162
+ (
163
+ "avatar_medium",
164
+ dj_tinyuser.models.fields.RestrictedImageField(
165
+ blank=True,
166
+ null=True,
167
+ upload_to="user/avatars/",
168
+ verbose_name="medium profile picture",
169
+ ),
170
+ ),
171
+ (
172
+ "avatar_large",
173
+ dj_tinyuser.models.fields.RestrictedImageField(
174
+ blank=True,
175
+ null=True,
176
+ upload_to="user/avatars/",
177
+ verbose_name="large profile picture",
178
+ ),
179
+ ),
180
+ (
181
+ "avatar_full",
182
+ dj_tinyuser.models.fields.RestrictedImageField(
183
+ blank=True,
184
+ null=True,
185
+ upload_to="user/avatars/",
186
+ verbose_name="full size profile picture",
187
+ ),
188
+ ),
189
+ (
190
+ "theme",
191
+ models.CharField(choices=[], default="html", max_length=255, verbose_name="Theme"),
192
+ ),
193
+ (
194
+ "user",
195
+ models.OneToOneField(
196
+ on_delete=django.db.models.deletion.CASCADE,
197
+ related_name="tinyuser_profile",
198
+ to=settings.AUTH_USER_MODEL,
199
+ ),
200
+ ),
201
+ ],
202
+ options={
203
+ "verbose_name": "user profile",
204
+ "verbose_name_plural": "user profiles",
205
+ "db_table": "tinyuser_profile",
206
+ "managed": True,
207
+ },
208
+ ),
209
+ migrations.CreateModel(
210
+ name="UserProfileSettings",
211
+ fields=[
212
+ (
213
+ "id",
214
+ models.BigAutoField(
215
+ auto_created=True,
216
+ primary_key=True,
217
+ serialize=False,
218
+ verbose_name="ID",
219
+ ),
220
+ ),
221
+ (
222
+ "name",
223
+ models.CharField(default="public", max_length=255, verbose_name="Profile name"),
224
+ ),
225
+ (
226
+ "key",
227
+ models.SlugField(default="public", max_length=255, verbose_name="settings type"),
228
+ ),
229
+ (
230
+ "is_enabled",
231
+ models.BooleanField(default=True, verbose_name="forbid to view my profile"),
232
+ ),
233
+ (
234
+ "show_avatar",
235
+ models.BooleanField(default=True, verbose_name="show avatar"),
236
+ ),
237
+ (
238
+ "show_email",
239
+ models.BooleanField(default=False, verbose_name="show email"),
240
+ ),
241
+ (
242
+ "show_full_name",
243
+ models.BooleanField(default=False, verbose_name="show full name"),
244
+ ),
245
+ (
246
+ "show_birth_date",
247
+ models.CharField(
248
+ choices=[
249
+ ("date", "date"),
250
+ ("birthday", "birthday"),
251
+ ("no", "no"),
252
+ ],
253
+ default="no",
254
+ max_length=31,
255
+ ),
256
+ ),
257
+ (
258
+ "show_website",
259
+ models.BooleanField(default=True, verbose_name="show website"),
260
+ ),
261
+ (
262
+ "show_mastodon_url",
263
+ models.BooleanField(default=True, verbose_name="show mastodon url"),
264
+ ),
265
+ (
266
+ "show_bio",
267
+ models.BooleanField(default=True, verbose_name="show bigraphy"),
268
+ ),
269
+ (
270
+ "show_location",
271
+ models.BooleanField(default=False, verbose_name="show location"),
272
+ ),
273
+ (
274
+ "profile",
275
+ models.ForeignKey(
276
+ on_delete=django.db.models.deletion.CASCADE,
277
+ to="dj_tinyuser.userprofile",
278
+ verbose_name="user's profile",
279
+ ),
280
+ ),
281
+ ],
282
+ options={
283
+ "verbose_name": "profile settings",
284
+ "verbose_name_plural": "profile settings",
285
+ "db_table": "tinyuser_profile_settings",
286
+ },
287
+ ),
288
+ migrations.AddIndex(
289
+ model_name="tinyuser",
290
+ index=models.Index(fields=["email"], name="email_idx"),
291
+ ),
292
+ migrations.AddIndex(
293
+ model_name="tinyuser",
294
+ index=models.Index(fields=["username"], name="username_idx"),
295
+ ),
296
+ migrations.AddConstraint(
297
+ model_name="tinyuser",
298
+ constraint=models.UniqueConstraint(
299
+ condition=models.Q(("email__isnull", False)),
300
+ fields=("email",),
301
+ name="unique_email",
302
+ ),
303
+ ),
304
+ migrations.AddConstraint(
305
+ model_name="tinyuser",
306
+ constraint=models.CheckConstraint(
307
+ condition=models.Q(("email__isnull", True), ("is_system_user", False), _connector="OR"),
308
+ name="email_not_system_user",
309
+ ),
310
+ ),
311
+ migrations.AddIndex(
312
+ model_name="userprofile",
313
+ index=models.Index(fields=["user"], name="user_idx"),
314
+ ),
315
+ migrations.AddIndex(
316
+ model_name="userprofilesettings",
317
+ index=models.Index(fields=["profile"], name="tinyuser_pr_profile_9242c2_idx"),
318
+ ),
319
+ migrations.AddIndex(
320
+ model_name="userprofilesettings",
321
+ index=models.Index(fields=["key"], name="tinyuser_pr_key_52bc84_idx"),
322
+ ),
323
+ migrations.AddIndex(
324
+ model_name="userprofilesettings",
325
+ index=models.Index(fields=["profile", "key"], name="tinyuser_pr_profile_5b15a8_idx"),
326
+ ),
327
+ migrations.AlterUniqueTogether(
328
+ name="userprofilesettings",
329
+ unique_together={("profile", "key")},
330
+ ),
331
+ ]
File without changes
@@ -0,0 +1,20 @@
1
+ from abc import ABC
2
+
3
+
4
+ class HtmxMixin(ABC):
5
+ """
6
+ Mixin to provide HTMX support for views.
7
+ """
8
+
9
+ @property
10
+ def is_htmx_request(self):
11
+ """
12
+ Checks if the current request is an HTMX request.
13
+
14
+ :return: True if the current request is an HTMX request, False otherwise
15
+ :rtype: bool
16
+ """
17
+ request = getattr(self, "request", None)
18
+ if request is None:
19
+ return False
20
+ return self.request.headers.get("Hx-Request") == "true"
@@ -0,0 +1,11 @@
1
+ from .fields import RestrictedImageField, RestrictedSvgImageFileField
2
+ from .tinyuser import TinyUser
3
+ from .userprofile import UserProfile, UserProfileSettings
4
+
5
+ __all__ = [
6
+ "TinyUser",
7
+ "UserProfile",
8
+ "UserProfileSettings",
9
+ "RestrictedImageField",
10
+ "RestrictedSvgImageFileField",
11
+ ]
@@ -0,0 +1,58 @@
1
+ from django.core.exceptions import ValidationError
2
+ from django.db import models
3
+ from django.utils.translation import gettext as _
4
+
5
+
6
+ class RestrictedImageField(models.ImageField):
7
+ """
8
+ A custom ImageField that restricts the allowed file types to common image formats.
9
+ """
10
+
11
+ def __init__(self, *args, max_file_size=None, **kwargs):
12
+ super().__init__(*args, **kwargs)
13
+ self.allowed_content_types = [
14
+ "image/jpeg",
15
+ "image/png",
16
+ "image/gif",
17
+ "image/webp",
18
+ ]
19
+ self.max_file_size = max_file_size
20
+
21
+ def clean(self, value, model_instance):
22
+ file = super().clean(value, model_instance)
23
+
24
+ if file:
25
+ content_type = file.file.content_type
26
+ if content_type not in self.allowed_content_types:
27
+ raise ValidationError(
28
+ _("Unsupported file type. Allowed types are: %(types)s."),
29
+ params={"types": ", ".join(self.allowed_content_types)},
30
+ )
31
+
32
+ return file
33
+
34
+
35
+ class RestrictedSvgImageFileField(RestrictedImageField):
36
+ """
37
+ A custom FileField that restricts the allowed file type to SVG images.
38
+ """
39
+
40
+ def __init__(self, *args, **kwargs):
41
+ super().__init__(*args, **kwargs)
42
+ self.allowed_content_types.append("image/svg+xml")
43
+
44
+ def clean(self, value, model_instance):
45
+ file = super().clean(value, model_instance)
46
+
47
+ if file:
48
+ content_type = file.file.content_type
49
+ if content_type not in self.allowed_content_types:
50
+ raise ValidationError(_("Unsupported file type. Only SVG images are allowed."))
51
+
52
+ if self.max_file_size and file.size > self.max_file_size:
53
+ raise ValidationError(
54
+ _("File size exceeds the maximum limit of %(max_file_size)s bytes."),
55
+ params={"max_file_size": self.max_file_size},
56
+ )
57
+
58
+ return file
@@ -0,0 +1,125 @@
1
+ from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
2
+ from django.db import models
3
+ from django.utils import timezone
4
+ from django.utils.translation import gettext_lazy as _
5
+
6
+ from dj_tinyuser.managers import TinyUserManager
7
+ from dj_tinyuser.models.userprofile import UserProfile
8
+
9
+
10
+ class TinyUser(AbstractBaseUser, PermissionsMixin):
11
+ """
12
+ Custom user model for the TinyUser application.
13
+
14
+ :param AbstractBaseUser: Base class for custom user models.
15
+ :type AbstractBaseUser: django.contrib.auth.models.AbstractBaseUser
16
+ :param PermissionsMixin: Mixin class to add permission fields and methods.
17
+ :type PermissionsMixin: django.contrib.auth.models.PermissionsMixin
18
+ :return: The created user instance.
19
+ :rtype: TinyUser
20
+ """
21
+
22
+ class Meta:
23
+ verbose_name = _("user")
24
+ verbose_name_plural = _("users")
25
+
26
+ db_table = "tinyuser_user"
27
+
28
+ indexes = [
29
+ models.Index(fields=["email"], name="email_idx"),
30
+ models.Index(fields=["username"], name="username_idx"),
31
+ ]
32
+
33
+ constraints = [
34
+ models.UniqueConstraint(
35
+ fields=["email"],
36
+ condition=(models.Q(email__isnull=False)),
37
+ name="unique_email",
38
+ ),
39
+ models.CheckConstraint(
40
+ condition=(models.Q(email__isnull=True) | models.Q(is_system_user=False)),
41
+ name="email_not_system_user",
42
+ ),
43
+ ]
44
+
45
+ #: The email field is used as the unique identifier for authentication
46
+ #: instead of the default username field.
47
+ #:
48
+ #: It is required and must be unique.
49
+ email = models.EmailField(
50
+ unique=True,
51
+ db_column="email",
52
+ verbose_name=_("email address"),
53
+ blank=True,
54
+ null=True,
55
+ )
56
+
57
+ #: The username field is a unique identifier for the user, used for display
58
+ #: purposes and as an additional identifier.
59
+ #: It is required and must be unique.
60
+
61
+ #: It is required and must be unique.
62
+ username = models.CharField(max_length=127, unique=True, db_column="username", verbose_name=_("username"))
63
+
64
+ #: The is_active field indicates whether the user's account is active.
65
+ #: Inactive accounts may not be able to log in.
66
+ #:
67
+ #: It is a boolean field that defaults to True.
68
+ is_active = models.BooleanField(default=True, db_column="is_active", verbose_name=_("active"))
69
+
70
+ #: The is_staff field indicates whether the user has staff status, which
71
+ #: allows access to the admin site.
72
+ #:
73
+ #: It is a boolean field that defaults to False.
74
+ is_staff = models.BooleanField(default=False, db_column="is_staff", verbose_name=_("staff status"))
75
+
76
+ #: The is_superuser field indicates whether the user has superuser status,
77
+ #: which grants all permissions.
78
+ #:
79
+ #: It is a boolean field that defaults to False.
80
+ is_superuser = models.BooleanField(default=False, db_column="is_superuser", verbose_name=_("superuser status"))
81
+
82
+ is_system_user = models.BooleanField(default=False, db_column="is_system_user", verbose_name=_("system user"))
83
+
84
+ #: The is_verified field indicates whether the user's email address has
85
+ #: been verified. This can be used to restrict access to certain features
86
+ #: until the email is verified.
87
+ #:
88
+ #: It is a boolean field that defaults to False.
89
+ is_verified = models.BooleanField(default=False, db_column="is_verified", verbose_name=_("verified"))
90
+
91
+ #: The joined_at field stores the date and time when the user account was created.
92
+ #: It is automatically set to the current date and time when the user is created.
93
+ joined_at = models.DateTimeField(default=timezone.now, db_column="joined_at", verbose_name=_("joined at"))
94
+
95
+ objects = TinyUserManager()
96
+
97
+ USERNAME_FIELD = "email"
98
+ REQUIRED_FIELDS = ["username"]
99
+
100
+ @property
101
+ def display_name(self):
102
+ """
103
+ Returns the display name of the user.
104
+
105
+ :return: The display name of the user.
106
+ :rtype: str
107
+ """
108
+ self.profile = getattr(self, "profile", None)
109
+ if not self.profile and self.id:
110
+ try:
111
+ self.profile = UserProfile.objects.filter(user_id=self.id).first()
112
+ except UserProfile.DoesNotExist:
113
+ self.profile = UserProfile.objects.create(user=self, first_name="", last_name="", bio="")
114
+
115
+ if self.profile:
116
+ if self.profile.first_name or self.profile.last_name:
117
+ return f"{self.profile.first_name} {self.profile.last_name}".strip()
118
+ elif self.profile.first_name:
119
+ return self.profile.first_name
120
+ elif self.profile.last_name:
121
+ return self.profile.last_name
122
+ return self.username
123
+
124
+ def __str__(self):
125
+ return self.username