Archived
- Backend: Django 5 + DRF with accounts, documents, collections, and reading apps - Custom User model with email-based auth, JWT via SimpleJWT - Full CRUD viewsets with ModelSerializer + DRF routers - pytest, Ruff, drf-spectacular (OpenAPI), whitenoise - Dockerfile for production deployment - Frontend: React 18 + TypeScript + Vite - Lazy-loaded routes with ProtectedRoute/PublicRoute guards - Auth context with useReducer, token refresh interceptor - Pages: Login, Register, Library, Document Detail, Reader, Collections, Settings - Dark theme, responsive grid layout, Vite proxy to Django backend - Mobile: Expo SDK 51 + React Native + Expo Router - File-based routing with login, register, and library screens - AsyncStorage for token persistence, token refresh interceptor - Shared API types via @cloud-reader/shared workspace package - Shared: TypeScript types (API responses, auth, documents, etc.) - CI/CD: 3 independent GitHub Actions pipelines (backend, frontend, mobile)
84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
from django.conf import settings
|
|
from django.db import models
|
|
|
|
|
|
class Bookmark(models.Model):
|
|
"""A user bookmark at a specific page in a document."""
|
|
document = models.ForeignKey(
|
|
"documents.Document",
|
|
on_delete=models.CASCADE,
|
|
related_name="bookmarks",
|
|
)
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
related_name="bookmarks",
|
|
)
|
|
page = models.PositiveIntegerField()
|
|
label = models.CharField(max_length=300, blank=True, default="")
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
db_table = "reading_bookmark"
|
|
ordering = ["page"]
|
|
unique_together = [["document", "user", "page"]]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.document.title} p.{self.page}"
|
|
|
|
|
|
class Highlight(models.Model):
|
|
"""A highlighted passage in a document."""
|
|
document = models.ForeignKey(
|
|
"documents.Document",
|
|
on_delete=models.CASCADE,
|
|
related_name="highlights",
|
|
)
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
related_name="highlights",
|
|
)
|
|
page = models.PositiveIntegerField()
|
|
color = models.CharField(max_length=20, default="yellow")
|
|
text = models.TextField()
|
|
note = models.TextField(blank=True, null=True)
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
db_table = "reading_highlight"
|
|
ordering = ["-created_at"]
|
|
|
|
def __str__(self) -> str:
|
|
return f"Highlight on {self.document.title} p.{self.page}"
|
|
|
|
|
|
class ReadingProgress(models.Model):
|
|
"""Tracks the user's reading progress through a document."""
|
|
document = models.ForeignKey(
|
|
"documents.Document",
|
|
on_delete=models.CASCADE,
|
|
related_name="reading_progress",
|
|
)
|
|
user = models.ForeignKey(
|
|
settings.AUTH_USER_MODEL,
|
|
on_delete=models.CASCADE,
|
|
related_name="reading_progress",
|
|
)
|
|
current_page = models.PositiveIntegerField(default=1)
|
|
total_pages = models.PositiveIntegerField(default=0)
|
|
percentage = models.FloatField(default=0.0)
|
|
last_read_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
db_table = "reading_progress"
|
|
unique_together = [["document", "user"]]
|
|
verbose_name_plural = "Reading progress"
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.document.title} — {self.percentage:.0f}%"
|
|
|
|
def save(self, *args, **kwargs):
|
|
if self.total_pages > 0:
|
|
self.percentage = round((self.current_page / self.total_pages) * 100, 1)
|
|
super().save(*args, **kwargs) |