Files
J621/backend/apps/accounts/models.py
T
JakeBreath bb87f563a9 Per-user browse preferences
Adds a preferences JSON field on the user plus GET/POST
/api/auth/preferences/ (merge semantics, validated keys), surfaced in
/auth/me/ and typed on the frontend.

The Account page gains a Browsing preferences card: landing page,
default rating filter, default sort, items per page and thumbnail size.
Signed-in users also sync these while browsing (the Library sidebar's
rating/sort/per-page controls and the new thumbnail slider), debounced;
on load the account's values seed the local UI state, so settings follow
the user across browsers. Guests keep the existing localStorage
behaviour. The thumbnail size drives the media grids (Library, Online,
pool detail) between 140 and 320px columns.

Verified the API against the dev server: merge keeps untouched keys,
invalid values 400, values round-trip through /auth/me/.
2026-09-17 22:34:38 -05:00

38 lines
1.2 KiB
Python

from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
"""Project user with optional e621 API credentials and an app role."""
ROLE_USER = "user"
ROLE_UPLOADER = "uploader"
ROLE_STAFF = "staff"
ROLE_CHOICES = [
(ROLE_USER, "User"),
(ROLE_UPLOADER, "Uploader"),
(ROLE_STAFF, "Staff"),
]
role = models.CharField(max_length=20, choices=ROLE_CHOICES, default=ROLE_USER)
avatar = models.ForeignKey(
"library.MediaItem",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
e621_username = models.CharField(max_length=100, blank=True, default="")
e621_api_key = models.CharField(max_length=100, blank=True, default="")
e621_base_url = models.CharField(max_length=200, default="https://e621.net")
# Per-user browse preferences (landing page, default filters, grid size).
preferences = models.JSONField(default=dict, blank=True)
@property
def e621_configured(self):
return bool(self.e621_username and self.e621_api_key)
@property
def can_upload(self):
return self.is_superuser or self.role in {self.ROLE_UPLOADER, self.ROLE_STAFF}