Turns Daybook into a multi-user tool and reworks the feed UI: - Multi-user: Django session login (username/password + remember-me), per-user personal API tokens (DRF authtoken), whole app gated behind login. Each artifact has an owner; feeds are private per user. - Rename persona -> source (free-text label for whatever posted an artifact: agent-profile, script, or person). source + tags form one unified label system; single label filter matches tags, source has its own filter/column/sidebar. - Settings area (gear/user menu, top-right): Account (view/regenerate token) and Demo Data (in-app button seeding one artifact per kind). User account management via Django admin (superusers only). - Feed rework: rolling 7-day window with sticky inline date separators and infinite scroll; left sidebar is now a Sources list with per-source unread counts; artifact type shown as text after title; source in its own column. - Unread tracking: read_at on Artifact, marked read when previewed, bold titles for unread, sidebar unread badges, old banner removed. - Tag colours: global shared registry, hash-based default with optional per-tag override via tag_colors on POST/PATCH. - Ingest: token resolves owner; same source name under two users' tokens stays isolated. daybook_post.py renamed persona->source, requires a real token, --check accepts a bearer token. Docs updated to match. Migrations 0004-0008 rename persona, add owner (nullable -> backfill to first superuser -> required), and add read_at. Fresh installs no-op the backfill. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
|
|
class Artifact(models.Model):
|
|
HTML_FRAGMENT = "html_fragment"
|
|
HTML_FULL = "html_full"
|
|
MARKDOWN = "markdown"
|
|
DECK = "deck"
|
|
IMAGE = "image"
|
|
PDF = "pdf"
|
|
BINARY = "binary"
|
|
|
|
AGENT = "agent"
|
|
PERSON = "person"
|
|
SYSTEM = "system"
|
|
|
|
KIND_CHOICES = [
|
|
(HTML_FRAGMENT, "HTML fragment"),
|
|
(HTML_FULL, "Full HTML"),
|
|
(MARKDOWN, "Markdown"),
|
|
(DECK, "Deck"),
|
|
(IMAGE, "Image"),
|
|
(PDF, "PDF"),
|
|
(BINARY, "Binary"),
|
|
]
|
|
|
|
SOURCE_TYPE_CHOICES = [
|
|
(AGENT, "Agent"),
|
|
(PERSON, "Person"),
|
|
(SYSTEM, "System"),
|
|
]
|
|
|
|
id = models.CharField(max_length=8, primary_key=True)
|
|
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="artifacts")
|
|
source = models.CharField(max_length=80, db_index=True)
|
|
title = models.CharField(max_length=200)
|
|
kind = models.CharField(max_length=20, choices=KIND_CHOICES)
|
|
theme = models.CharField(max_length=40, blank=True)
|
|
day = models.DateField(db_index=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
path = models.CharField(max_length=500)
|
|
original_kind = models.CharField(max_length=20)
|
|
tags = models.JSONField(default=list, blank=True)
|
|
source_prompt = models.TextField(blank=True)
|
|
source_type = models.CharField(max_length=20, choices=SOURCE_TYPE_CHOICES, default=AGENT)
|
|
source_name = models.CharField(max_length=120, blank=True)
|
|
source_id = models.CharField(max_length=120, blank=True)
|
|
metadata = models.JSONField(default=dict, blank=True)
|
|
read_at = models.DateTimeField(null=True, blank=True)
|
|
|
|
@property
|
|
def is_unread(self):
|
|
return self.read_at is None
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
|
|
def __str__(self):
|
|
return f"{self.title} ({self.source})"
|
|
|
|
|
|
class TagColor(models.Model):
|
|
name = models.CharField(max_length=40, primary_key=True)
|
|
color = models.CharField(max_length=20)
|
|
|
|
def __str__(self):
|
|
return f"{self.name} ({self.color})"
|