Configure shop app, admin sidebar, media routing, and Stripe dependencies
This commit is contained in:
commit
93d83a0d63
188 files changed
+9220
No files matched your search
@@ -0,0 +1,677 @@
|
||||
from decimal import Decimal
|
||||
from uuid import uuid4
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MaxValueValidator, URLValidator, MinValueValidator, RegexValidator
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from PIL import Image
|
||||
|
||||
from .backgrounds import validate_background_path
|
||||
from .sharing import validate_share_path
|
||||
|
||||
https_url = URLValidator(schemes=['https'])
|
||||
|
||||
|
||||
def image_path(instance, filename):
|
||||
return f'images/{uuid4()}'
|
||||
|
||||
|
||||
def validate_image(file):
|
||||
if file.size > 12 * 1024 * 1024:
|
||||
raise ValidationError('Keep images under 12 MB.')
|
||||
try:
|
||||
with Image.open(file) as img:
|
||||
if (img.format not in {'JPEG', 'PNG', 'WEBP'}
|
||||
or img.width * img.height > 30_000_000
|
||||
or getattr(img, 'is_animated', False)):
|
||||
raise ValidationError('Use a still JPG, PNG, or WebP under 30 megapixels.')
|
||||
img.verify()
|
||||
except (OSError, SyntaxError, Image.DecompressionBombError) as exc:
|
||||
raise ValidationError('This image could not be read.') from exc
|
||||
finally:
|
||||
file.seek(0)
|
||||
|
||||
|
||||
class StudioImageField(models.ImageField):
|
||||
def formfield(self, **kwargs):
|
||||
from .uploads import WebPUploadField
|
||||
return super().formfield(form_class=WebPUploadField, **kwargs)
|
||||
|
||||
|
||||
def art_field(**kwargs):
|
||||
return StudioImageField(upload_to=image_path, validators=[validate_image], **kwargs)
|
||||
|
||||
|
||||
class PageBackground(models.Model):
|
||||
path = models.CharField('Page path', max_length=200, unique=True, validators=[validate_background_path],
|
||||
help_text='Choose a page or enter its exact path, such as /chapters/9/ or /blog/your-post/.')
|
||||
art = art_field(verbose_name='Background artwork', blank=True,
|
||||
help_text='Optional, publicly visible backdrop. Use an image you intend to publish.')
|
||||
color = models.CharField('Background color / tint', max_length=7, default='#0c0e15',
|
||||
validators=[RegexValidator(r'\A#[0-9a-fA-F]{6}\Z', 'Enter a six-digit hex color.')])
|
||||
tint_strength = models.PositiveSmallIntegerField('Tint strength (%)', default=40,
|
||||
validators=[MaxValueValidator(100)], help_text='With artwork: 0 shows the original image, 100 shows only the color.')
|
||||
enabled = models.BooleanField('Enabled', default=True,
|
||||
help_text='Uncheck to return to the normal site background without losing these settings.')
|
||||
|
||||
class Meta:
|
||||
ordering = ['path']
|
||||
|
||||
def __str__(self):
|
||||
return self.path
|
||||
|
||||
|
||||
class FloatingArtwork(models.Model):
|
||||
class Placement(models.TextChoices):
|
||||
TOP = 'top', 'Near the top'
|
||||
BOTTOM = 'bottom', 'Below the page content'
|
||||
|
||||
class Alignment(models.TextChoices):
|
||||
LEFT = 'left', 'Left'
|
||||
CENTER = 'center', 'Center'
|
||||
RIGHT = 'right', 'Right'
|
||||
|
||||
name = models.CharField('Studio label', max_length=100, help_text='A name to help you identify this image in Studio.')
|
||||
path = models.CharField('Page path', max_length=200, default='/', validators=[validate_background_path],
|
||||
help_text='Choose a page or enter its exact path, such as /chapters/9/.')
|
||||
art = art_field(verbose_name='Image', help_text='Upload JPG, PNG, or WebP. A transparent PNG works well for character cutouts.')
|
||||
alt = models.CharField('Image description', max_length=180, blank=True,
|
||||
help_text='Describe the image if it adds meaning. Leave blank if it is decorative.')
|
||||
placement = models.CharField(max_length=6, choices=Placement, default=Placement.TOP,
|
||||
help_text='On the homepage, top artwork appears immediately below the released chapters.')
|
||||
alignment = models.CharField(max_length=6, choices=Alignment, default=Alignment.CENTER)
|
||||
width = models.PositiveSmallIntegerField('Maximum width (px)', default=280,
|
||||
validators=[MinValueValidator(48), MaxValueValidator(480)])
|
||||
cycle_seconds = models.PositiveSmallIntegerField('Float cycle (seconds)', default=12,
|
||||
validators=[MinValueValidator(6), MaxValueValidator(40)], help_text='Time to drift up and back down. Higher is slower.')
|
||||
lift = models.PositiveSmallIntegerField('Lift height (px)', default=16,
|
||||
validators=[MaxValueValidator(40)], help_text='How far the artwork floats up. Set to zero for a stationary image.')
|
||||
order = models.PositiveSmallIntegerField('Display order', default=0, help_text='Lower numbers appear first in the same column.')
|
||||
enabled = models.BooleanField(default=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'pk']
|
||||
verbose_name_plural = 'floating artwork'
|
||||
indexes = [models.Index(fields=['path', 'enabled'], name='slx_float_path_enabled')]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class PageSharePreview(models.Model):
|
||||
path = models.CharField('Page path', max_length=200, unique=True, validators=[validate_share_path],
|
||||
help_text='Choose a page or paste its path, such as /chapters/9/. Include the trailing slash.')
|
||||
title = models.CharField('Share title', max_length=120, blank=True,
|
||||
help_text='Optional. Leave blank to use the page’s normal preview title.')
|
||||
excerpt = models.CharField('Share excerpt', max_length=220, blank=True,
|
||||
help_text='A short description for the link card. Leave blank to use the page’s default excerpt.')
|
||||
art = art_field(verbose_name='Share image', blank=True,
|
||||
help_text='Public artwork for link cards. A 1200 × 630 JPG, PNG or WebP is a good starting point.')
|
||||
|
||||
class Meta:
|
||||
ordering = ['path']
|
||||
verbose_name = 'link preview'
|
||||
verbose_name_plural = 'link previews'
|
||||
|
||||
def __str__(self):
|
||||
return self.path
|
||||
|
||||
|
||||
class SiteSettings(models.Model):
|
||||
name = models.CharField(max_length=100, default='SLUMP X LAND', editable=False)
|
||||
site_palette = models.JSONField(default=dict, blank=True)
|
||||
hidden_menu = models.JSONField(default=list, blank=True)
|
||||
support_url = models.URLField('Subscription or support page', blank=True, validators=[https_url],
|
||||
help_text='An HTTPS link to your membership or support checkout. Leave blank if you are not accepting signups.')
|
||||
caster_threshold = models.DecimalField('Sol-Caster minimum (USD)', max_digits=9, decimal_places=2,
|
||||
default=Decimal('100.01'), validators=[MinValueValidator(Decimal('0.01'))])
|
||||
striker_threshold = models.DecimalField('Sol-Striker minimum (USD)', max_digits=9, decimal_places=2,
|
||||
default=Decimal('500.00'), validators=[MinValueValidator(Decimal('0.01'))])
|
||||
seat_threshold = models.DecimalField('Sol Seat minimum (USD)', max_digits=9, decimal_places=2,
|
||||
null=True, blank=True, validators=[MinValueValidator(Decimal('0.01'))],
|
||||
help_text='Leave blank for staff assignment only. Must exceed the Sol-Striker minimum.')
|
||||
|
||||
tagline = models.CharField(max_length=140, default='The official ManaA series hub')
|
||||
credit = models.CharField(max_length=140, default='Story and Art by Receo Thomas Gibson')
|
||||
intro = models.TextField(blank=True, max_length=4000)
|
||||
hero_art = art_field(blank=True)
|
||||
blur_hero = models.BooleanField(default=False)
|
||||
publisher_url = models.URLField(blank=True, validators=[https_url])
|
||||
shop_url = models.URLField(blank=True, validators=[https_url])
|
||||
next_release_at = models.DateTimeField(blank=True, null=True)
|
||||
next_release_title = models.CharField(max_length=120, blank=True)
|
||||
homepage_countdown_enabled = models.BooleanField('Show on homepage', default=False)
|
||||
homepage_countdown_title = models.CharField('Countdown title', max_length=120, blank=True)
|
||||
homepage_countdown_at = models.DateTimeField('Countdown ends', blank=True, null=True)
|
||||
homepage_countdown_start_at = models.DateTimeField('Progress starts', blank=True, null=True,
|
||||
help_text='Chicago time. Leave blank to start when you save an active countdown.')
|
||||
homepage_countdown_bar_color = models.CharField('Progress bar color', max_length=7, blank=True, default='#4395de',
|
||||
validators=[RegexValidator(r'\A#[0-9a-fA-F]{6}\Z', 'Enter a six-digit hex color, such as #4395de.')],
|
||||
help_text='Choose a color or enter a hex value. Blank uses SLUMP blue.')
|
||||
homepage_countdown_landing = models.BooleanField('Use a full landing page', default=False,
|
||||
help_text='Replaces the homepage while the countdown is active. The regular homepage returns at zero.')
|
||||
homepage_countdown_cover = art_field(
|
||||
verbose_name='Chapter cover', blank=True, help_text='Upload a cover specifically for this public countdown.')
|
||||
homepage_countdown_background = art_field(verbose_name='Landing background art', blank=True,
|
||||
help_text='A landscape image works best. Leave blank to use the default landing background.')
|
||||
homepage_countdown_tint = models.CharField('Background tint', max_length=7, default='#0c1020', blank=True,
|
||||
validators=[RegexValidator(r'\A#[0-9a-fA-F]{6}\Z', 'Enter a six-digit hex color, such as #0c1020.')])
|
||||
homepage_countdown_tint_strength = models.PositiveSmallIntegerField('Tint strength', default=65,
|
||||
validators=[MaxValueValidator(100)], help_text='0 shows the original art. 100 uses only the tint color.')
|
||||
homepage_countdown_note = models.TextField('Author’s comment', max_length=1500, blank=True)
|
||||
homepage_countdown_cta_label = models.CharField('Button label', max_length=60, blank=True)
|
||||
homepage_countdown_cta_url = models.URLField('Button URL', blank=True, validators=[https_url],
|
||||
help_text='Paste the HTTPS link to your mailing-list signup or other destination.')
|
||||
homepage_social_color = models.CharField('Social icon color', max_length=7, blank=True, default='#ffdd00',
|
||||
validators=[RegexValidator(r'\A#[0-9a-fA-F]{6}\Z', 'Enter a six-digit hex color, such as #ffdd00.')])
|
||||
homepage_social_instagram = models.URLField('Instagram URL', blank=True, validators=[https_url])
|
||||
homepage_social_facebook = models.URLField('Facebook URL', blank=True, validators=[https_url])
|
||||
homepage_social_youtube = models.URLField('YouTube URL', blank=True, validators=[https_url])
|
||||
homepage_social_tiktok = models.URLField('TikTok URL', blank=True, validators=[https_url])
|
||||
homepage_social_x = models.URLField('X URL', blank=True, validators=[https_url])
|
||||
homepage_social_twitch = models.URLField('Twitch URL', blank=True, validators=[https_url])
|
||||
show_chapter_countdowns = models.BooleanField(default=True)
|
||||
author_comment_name = models.CharField('Author display name', max_length=100, blank=True,
|
||||
help_text='Leave blank to use Receo Thomas Gibson.')
|
||||
author_comment_avatar = art_field(verbose_name='Author avatar', blank=True,
|
||||
help_text='Use your own art or photo. Square images work best in the circular crop.')
|
||||
author_comment_signature = art_field(verbose_name='Author signature', blank=True,
|
||||
help_text='Upload your own handwritten signature. A tightly cropped transparent PNG or WebP works best.')
|
||||
countdown_creator_note = models.TextField(blank=True, max_length=1500)
|
||||
countdown_art = art_field(blank=True, help_text='Optional separate backdrop for the Coming Soon page.')
|
||||
blur_countdown = models.BooleanField(default=False)
|
||||
stream_title = models.CharField(max_length=140, blank=True)
|
||||
stream_description = models.TextField('Broadcast description', max_length=1800, blank=True)
|
||||
stream_cover = art_field(verbose_name='Stream poster', blank=True)
|
||||
stream_comments_open = models.BooleanField('Allow stream comments', default=True,
|
||||
help_text='Close posting without hiding approved comments.')
|
||||
stream_discussion_slug = models.SlugField('Discussion key', max_length=60, default='main',
|
||||
help_text='Use a new key for a fresh thread on the same Twitch channel. Keep it the same for the replay.')
|
||||
stream_provider = models.CharField(max_length=7, blank=True,
|
||||
choices=[('youtube', 'YouTube'), ('twitch', 'Twitch')])
|
||||
stream_public_id = models.CharField('Public video ID or channel name', max_length=25, blank=True,
|
||||
help_text='YouTube video ID or Twitch channel name. Never enter your private OBS stream key.')
|
||||
stream_status = models.CharField(max_length=8, default='offline',
|
||||
choices=[('offline', 'Offline'), ('upcoming', 'Upcoming'), ('live', 'Live'), ('replay', 'Replay')])
|
||||
stream_starts_at = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.striker_threshold is not None and self.caster_threshold is not None and self.striker_threshold <= self.caster_threshold:
|
||||
raise ValidationError({'striker_threshold': 'Enter a minimum above the Sol-Caster threshold.'})
|
||||
if self.seat_threshold is not None and self.striker_threshold is not None and self.seat_threshold <= self.striker_threshold:
|
||||
raise ValidationError({'seat_threshold': 'Enter a minimum above the Sol-Striker threshold.'})
|
||||
patterns = {'youtube': r'\A[A-Za-z0-9_-]{11}\Z', 'twitch': r'\A[A-Za-z0-9_]{4,25}\Z'}
|
||||
if self.stream_provider and not self.stream_public_id:
|
||||
raise ValidationError({'stream_public_id': 'Enter the public video ID or channel name.'})
|
||||
if self.stream_public_id:
|
||||
if self.stream_provider not in patterns:
|
||||
raise ValidationError({'stream_provider': 'Choose YouTube or Twitch.'})
|
||||
RegexValidator(patterns[self.stream_provider], 'Enter a valid public video ID or channel name.')(self.stream_public_id)
|
||||
if self.stream_status != 'offline' and not self.stream_provider:
|
||||
raise ValidationError({'stream_status': 'Configure a provider before changing stream status.'})
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'Site settings'
|
||||
|
||||
def __str__(self):
|
||||
return 'SLUMP X LAND'
|
||||
|
||||
|
||||
class Chapter(models.Model):
|
||||
number = models.PositiveIntegerField(unique=True, validators=[MinValueValidator(1)])
|
||||
title = models.CharField(max_length=180)
|
||||
cover = art_field(blank=True)
|
||||
price_usd = models.DecimalField('Chapter price (USD)', max_digits=7, decimal_places=2, null=True, blank=True,
|
||||
validators=[MinValueValidator(0)], help_text='Leave blank or set to zero for a free chapter.')
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.publisher_url and self.price_usd:
|
||||
raise ValidationError({'price_usd': 'You can only sell chapters hosted in this Studio.'})
|
||||
summary = models.TextField(blank=True, max_length=3000)
|
||||
publisher_url = models.URLField(blank=True, validators=[https_url],
|
||||
help_text='Optional: point to the official chapter on ONSOL-GO! instead of hosting pages here.')
|
||||
publish_at = models.DateTimeField(help_text='Chicago time. A draft stays private even after this date.')
|
||||
announce_countdown = models.BooleanField(default=False,
|
||||
help_text='Show the cover, title, and countdown before release. Only scheduled chapters can be announced.')
|
||||
first_upload_is_cover = models.BooleanField('First uploaded page is the cover', default=True,
|
||||
help_text='Applies only when the chapter has no separate cover image. Turn this off for a chapter with no cover.')
|
||||
reader_direction = models.CharField(max_length=3, default='rtl', choices=[('rtl','Right to left'),('ltr','Left to right')])
|
||||
published = models.BooleanField(default=False, verbose_name='Publish when scheduled')
|
||||
|
||||
class Meta:
|
||||
ordering = ['-number']
|
||||
|
||||
def __str__(self):
|
||||
return f'#{self.number:03d} · {self.title}'
|
||||
|
||||
|
||||
class Page(models.Model):
|
||||
class Layout(models.TextChoices):
|
||||
AUTO = 'auto', 'Pair automatically'
|
||||
PAIR_START = 'pair_start', 'Start a new pair'
|
||||
SINGLE = 'single', 'Show alone'
|
||||
SPREAD = 'spread', 'Double spread (one wide image)'
|
||||
|
||||
chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE, related_name='pages')
|
||||
number = models.PositiveIntegerField(validators=[MinValueValidator(1)])
|
||||
art = art_field()
|
||||
layout = models.CharField(max_length=10, choices=Layout.choices, default=Layout.AUTO,
|
||||
help_text='For a joined spread, upload one wide image. For separate halves, start a new pair on the first half and leave the second on Auto.')
|
||||
|
||||
class Meta:
|
||||
ordering = ['number']
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['chapter', 'number'], name='unique_page_in_chapter'),
|
||||
]
|
||||
|
||||
|
||||
class Entry(models.Model):
|
||||
class Kind(models.TextChoices):
|
||||
NEWS = 'news', 'News'
|
||||
CAST = 'cast', 'Cast'
|
||||
WORLD = 'world', 'World archive'
|
||||
|
||||
kind = models.CharField(choices=Kind.choices, max_length=10)
|
||||
title = models.CharField(max_length=150)
|
||||
slug = models.SlugField(max_length=170, unique=True)
|
||||
summary = models.CharField(max_length=240, blank=True)
|
||||
byline = models.CharField(max_length=100, blank=True)
|
||||
category = models.CharField(max_length=60, blank=True,
|
||||
help_text='For example: Creator Notes, Announcements, or Behind the Pages.')
|
||||
allow_comments = models.BooleanField(default=True)
|
||||
body = models.TextField(max_length=12000)
|
||||
art = art_field(blank=True)
|
||||
publish_at = models.DateTimeField()
|
||||
published = models.BooleanField(default=False, verbose_name='Publish when scheduled')
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = 'Editorial entries'
|
||||
ordering = ['-publish_at', '-pk']
|
||||
|
||||
def get_absolute_url(self):
|
||||
if self.kind == self.Kind.NEWS:
|
||||
return reverse('blog-post', args=[self.slug])
|
||||
return reverse('entry', args=[self.kind, self.slug])
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class DiscussionComment(models.Model):
|
||||
class Status(models.TextChoices):
|
||||
PENDING = 'pending', 'Pending'
|
||||
APPROVED = 'approved', 'Approved'
|
||||
HIDDEN = 'hidden', 'Hidden'
|
||||
|
||||
chapter = models.ForeignKey(Chapter, null=True, blank=True, on_delete=models.CASCADE)
|
||||
entry = models.ForeignKey(Entry, null=True, blank=True, on_delete=models.CASCADE)
|
||||
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, related_name='replies')
|
||||
body = models.CharField(max_length=1800)
|
||||
status = models.CharField(max_length=8, choices=Status.choices, default=Status.PENDING, db_index=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['created_at', 'pk']
|
||||
constraints = [models.CheckConstraint(
|
||||
condition=(models.Q(chapter__isnull=False, entry__isnull=True) |
|
||||
models.Q(chapter__isnull=True, entry__isnull=False)),
|
||||
name='slx_comment_one_target',
|
||||
)]
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.author}: {self.body[:65]}'
|
||||
|
||||
|
||||
class FanReaction(models.Model):
|
||||
class Value(models.IntegerChoices):
|
||||
LIKE = 1, 'Like'
|
||||
LOVE = 2, 'Love'
|
||||
DISLIKE = -1, 'Dislike'
|
||||
WOW = 3, 'Wow'
|
||||
SAD = 4, 'Sad'
|
||||
LAUGH = 5, 'Laugh'
|
||||
|
||||
TARGETS = ('chapter', 'entry', 'comment', 'page', 'entry_cover', 'chapter_cover')
|
||||
chapter = models.ForeignKey(Chapter, null=True, blank=True, on_delete=models.CASCADE)
|
||||
entry = models.ForeignKey(Entry, null=True, blank=True, on_delete=models.CASCADE)
|
||||
comment = models.ForeignKey(DiscussionComment, null=True, blank=True, on_delete=models.CASCADE)
|
||||
page = models.ForeignKey(Page, null=True, blank=True, on_delete=models.CASCADE)
|
||||
entry_cover = models.ForeignKey(Entry, null=True, blank=True, on_delete=models.CASCADE, related_name='cover_reactions')
|
||||
chapter_cover = models.ForeignKey(Chapter, null=True, blank=True, on_delete=models.CASCADE, related_name='cover_reactions')
|
||||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
value = models.SmallIntegerField(choices=Value.choices, default=Value.LIKE)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.CheckConstraint(condition=models.Q(
|
||||
models.Q(chapter__isnull=False, entry__isnull=True, comment__isnull=True, page__isnull=True, entry_cover__isnull=True, chapter_cover__isnull=True),
|
||||
models.Q(chapter__isnull=True, entry__isnull=False, comment__isnull=True, page__isnull=True, entry_cover__isnull=True, chapter_cover__isnull=True),
|
||||
models.Q(chapter__isnull=True, entry__isnull=True, comment__isnull=False, page__isnull=True, entry_cover__isnull=True, chapter_cover__isnull=True),
|
||||
models.Q(chapter__isnull=True, entry__isnull=True, comment__isnull=True, page__isnull=False, entry_cover__isnull=True, chapter_cover__isnull=True),
|
||||
models.Q(chapter__isnull=True, entry__isnull=True, comment__isnull=True, page__isnull=True, entry_cover__isnull=False, chapter_cover__isnull=True),
|
||||
models.Q(chapter__isnull=True, entry__isnull=True, comment__isnull=True, page__isnull=True, entry_cover__isnull=True, chapter_cover__isnull=False),
|
||||
_connector=models.Q.OR,
|
||||
) & models.Q(value__in=[-1, 1, 2, 3, 4, 5]), name='slx_reaction_one_target'),
|
||||
models.UniqueConstraint(fields=['user', 'chapter'], name='slx_one_chapter_reaction'),
|
||||
models.UniqueConstraint(fields=['user', 'entry'], name='slx_one_entry_reaction'),
|
||||
models.UniqueConstraint(fields=['user', 'comment'], name='slx_one_comment_reaction'),
|
||||
models.UniqueConstraint(fields=['user', 'page'], name='slx_one_page_reaction'),
|
||||
models.UniqueConstraint(fields=['user', 'entry_cover'], name='slx_one_entry_cover_reaction'),
|
||||
models.UniqueConstraint(fields=['user', 'chapter_cover'], name='slx_one_chapter_cover_reaction'),
|
||||
]
|
||||
|
||||
|
||||
class ReaderShelf(models.Model):
|
||||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE)
|
||||
saved = models.BooleanField(default=False)
|
||||
favorite = models.BooleanField(default=False)
|
||||
finished = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=['user', 'chapter'], name='slx_one_shelf_record')]
|
||||
|
||||
|
||||
class ReaderRating(models.Model):
|
||||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE)
|
||||
score = models.PositiveSmallIntegerField(choices=[(n, str(n)) for n in range(1, 6)])
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['user', 'chapter'], name='slx_one_rating'),
|
||||
models.CheckConstraint(condition=models.Q(score__gte=1, score__lte=5), name='slx_rating_range'),
|
||||
]
|
||||
|
||||
|
||||
class FanNotice(models.Model):
|
||||
class Kind(models.TextChoices):
|
||||
REPLY = 'reply', 'replied to your comment'
|
||||
LIKE = 'like', 'liked your comment'
|
||||
|
||||
recipient = models.ForeignKey('auth.User', on_delete=models.CASCADE, related_name='slx_notices')
|
||||
actor = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
comment = models.ForeignKey(DiscussionComment, on_delete=models.CASCADE)
|
||||
kind = models.CharField(choices=Kind.choices, max_length=8)
|
||||
seen = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=['actor', 'comment', 'kind'], name='slx_single_notice')]
|
||||
ordering = ['-created_at', '-pk']
|
||||
|
||||
|
||||
class TitleFollow(models.Model):
|
||||
user = models.OneToOneField('auth.User', on_delete=models.CASCADE)
|
||||
followed_at = models.DateTimeField(auto_now_add=True)
|
||||
checked_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
|
||||
|
||||
class ChapterReview(models.Model):
|
||||
chapter = models.ForeignKey(Chapter, on_delete=models.CASCADE, related_name='reviews')
|
||||
author = models.ForeignKey('auth.User', on_delete=models.CASCADE, related_name='chapter_reviews')
|
||||
image_page = models.ForeignKey(Page, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
|
||||
headline = models.CharField(max_length=120)
|
||||
body = models.TextField(max_length=3000)
|
||||
score = models.PositiveSmallIntegerField(choices=[(n, f'{n} / 5') for n in range(1, 6)])
|
||||
contains_spoilers = models.BooleanField(default=False)
|
||||
status = models.CharField(max_length=8, default=DiscussionComment.Status.PENDING, choices=DiscussionComment.Status.choices)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-updated_at', '-pk']
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['author', 'chapter'], name='slx_one_chapter_review'),
|
||||
models.CheckConstraint(condition=models.Q(score__gte=1, score__lte=5), name='slx_review_score_range'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.headline
|
||||
|
||||
|
||||
class SeriesReview(models.Model):
|
||||
author = models.OneToOneField('auth.User', on_delete=models.CASCADE, related_name='series_review')
|
||||
favorite_chapter = models.ForeignKey(Chapter, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
image_page = models.ForeignKey(Page, on_delete=models.SET_NULL, null=True, blank=True, related_name='+')
|
||||
headline = models.CharField(max_length=120)
|
||||
body = models.TextField(max_length=3000)
|
||||
score = models.PositiveSmallIntegerField(choices=[(n, f'{n} / 5') for n in range(1, 6)])
|
||||
contains_spoilers = models.BooleanField(default=False)
|
||||
status = models.CharField(max_length=8, default=DiscussionComment.Status.PENDING, choices=DiscussionComment.Status.choices)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-updated_at', '-pk']
|
||||
constraints = [models.CheckConstraint(condition=models.Q(score__gte=1, score__lte=5),
|
||||
name='slx_series_review_score_range')]
|
||||
|
||||
def __str__(self):
|
||||
return self.headline
|
||||
|
||||
|
||||
def validate_book_checkout(value):
|
||||
from urllib.parse import urlsplit
|
||||
https_url(value)
|
||||
url = urlsplit(value)
|
||||
if (url.netloc.lower() not in {'www.paypal.com', 'paypal.com', 'www.sandbox.paypal.com', 'sandbox.paypal.com', 'py.pl'}
|
||||
or url.path in {'', '/'}):
|
||||
raise ValidationError('Enter the PayPal Payment Link for this product or variant.')
|
||||
|
||||
|
||||
class BookListing(models.Model):
|
||||
class Category(models.TextChoices):
|
||||
COMICS = 'comics', 'Comics & books'
|
||||
MUSIC = 'music', 'Music'
|
||||
APPAREL = 'apparel', 'Clothing & apparel'
|
||||
MERCH = 'merch', 'Other merchandise'
|
||||
|
||||
category = models.CharField(max_length=12, choices=Category, default=Category.COMICS)
|
||||
title = models.CharField(max_length=160)
|
||||
description = models.TextField(max_length=1500, blank=True)
|
||||
cover = art_field(verbose_name='Product image', blank=True)
|
||||
paypal_url = models.URLField('PayPal Payment Link', blank=True, validators=[validate_book_checkout],
|
||||
help_text='Use for a product with no variants. When variants exist, each uses its own link.')
|
||||
visible = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ['title', 'pk']
|
||||
verbose_name = 'product'
|
||||
verbose_name_plural = 'products'
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
|
||||
class ProductVariant(models.Model):
|
||||
class Format(models.TextChoices):
|
||||
DIGITAL = 'digital', 'Digital'
|
||||
FLOPPY = 'floppy', 'Floppy'
|
||||
GRAPHIC_NOVEL = 'graphic_novel', 'Graphic Novel'
|
||||
CD = 'cd', 'CD'
|
||||
VINYL = 'vinyl', 'Vinyl'
|
||||
CASSETTE = 'cassette', 'Cassette'
|
||||
T_SHIRT = 'tshirt', 'T-shirt'
|
||||
HOODIE = 'hoodie', 'Hoodie'
|
||||
SWEATSHIRT = 'sweatshirt', 'Sweatshirt'
|
||||
HAT = 'hat', 'Hat'
|
||||
OTHER_APPAREL = 'other_apparel', 'Other apparel'
|
||||
OTHER_MERCH = 'other_merch', 'Other merchandise'
|
||||
|
||||
product = models.ForeignKey(BookListing, on_delete=models.CASCADE, related_name='variants')
|
||||
format = models.CharField(max_length=20, choices=Format)
|
||||
option = models.CharField('Edition / size / color', max_length=90, blank=True,
|
||||
help_text='Optional. For example: XL / Black, Signed copy, or Blue pressing.')
|
||||
art = art_field(verbose_name='Variant image', blank=True, help_text='Leave blank to use the main product image.')
|
||||
price_usd = models.DecimalField('Display price (USD)', max_digits=8, decimal_places=2, null=True, blank=True,
|
||||
validators=[MinValueValidator(Decimal('0.01'))],
|
||||
help_text='Optional. Enter the same price you set in PayPal; this field does not change the checkout price.')
|
||||
paypal_url = models.URLField('PayPal Payment Link', validators=[validate_book_checkout])
|
||||
visible = models.BooleanField(default=True)
|
||||
order = models.PositiveSmallIntegerField('Display order', default=0, help_text='Lower numbers appear first.')
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'pk']
|
||||
|
||||
def __str__(self):
|
||||
label = self.get_format_display()
|
||||
return f'{label} · {self.option}' if self.option else label
|
||||
|
||||
|
||||
class ChapterPurchase(models.Model):
|
||||
user = models.ForeignKey('auth.User', on_delete=models.PROTECT)
|
||||
chapter = models.ForeignKey(Chapter, on_delete=models.PROTECT, related_name='purchases')
|
||||
mode = models.CharField(max_length=7, choices=[('sandbox', 'Sandbox'), ('live', 'Live')])
|
||||
amount = models.DecimalField(max_digits=7, decimal_places=2)
|
||||
checkout_id = models.UUIDField(default=uuid4, unique=True, editable=False)
|
||||
paypal_order_id = models.CharField(max_length=64, blank=True)
|
||||
approval_url = models.URLField(max_length=500, blank=True)
|
||||
capture_id = models.CharField(max_length=64, null=True, blank=True, unique=True)
|
||||
paid_at = models.DateTimeField(null=True, blank=True)
|
||||
revoked = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=['user', 'chapter', 'mode'],
|
||||
name='slx_unique_chapter_purchase')]
|
||||
|
||||
|
||||
class StreamComment(models.Model):
|
||||
thread_key = models.CharField(max_length=64)
|
||||
broadcast_title = models.CharField(max_length=140)
|
||||
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
|
||||
body = models.TextField(max_length=1800)
|
||||
status = models.CharField(max_length=8, choices=DiscussionComment.Status.choices,
|
||||
default=DiscussionComment.Status.PENDING)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at', '-pk']
|
||||
indexes = [models.Index(fields=['thread_key', 'status', '-created_at'], name='slx_stream_public_idx')]
|
||||
permissions = [('watch_slx_live', 'Can watch SLX Live')]
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.author}: {self.body[:60]}'
|
||||
|
||||
class FanMembership(models.Model):
|
||||
user = models.OneToOneField('auth.User', on_delete=models.CASCADE, related_name='slx_membership')
|
||||
subscriber_until = models.DateTimeField('Subscription active through', null=True, blank=True)
|
||||
sol_seat = models.BooleanField('Assign Sol Seat', default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'fan membership'
|
||||
|
||||
def __str__(self):
|
||||
return str(self.user)
|
||||
|
||||
|
||||
class SupportCredit(models.Model):
|
||||
user = models.ForeignKey('auth.User', on_delete=models.CASCADE, related_name='slx_support_credits')
|
||||
reference = models.CharField('Unique receipt or credit reference', max_length=140, unique=True)
|
||||
amount = models.DecimalField('Verified support (USD)', max_digits=9, decimal_places=2,
|
||||
validators=[MinValueValidator(Decimal('0.01'))])
|
||||
voided = models.BooleanField('Voided or refunded', default=False)
|
||||
recorded_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-recorded_at', '-pk']
|
||||
|
||||
def __str__(self):
|
||||
return self.reference
|
||||
|
||||
|
||||
class TrafficDaily(models.Model):
|
||||
day = models.DateField()
|
||||
kind = models.CharField(max_length=12)
|
||||
target_id = models.PositiveBigIntegerField(default=0)
|
||||
route = models.CharField(max_length=64)
|
||||
country = models.CharField(max_length=2, blank=True, default='')
|
||||
source = models.CharField(max_length=255, blank=True, default='')
|
||||
views = models.PositiveBigIntegerField(default=1)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=['day', 'kind', 'target_id', 'route', 'country', 'source'],
|
||||
name='slx_traffic_daily_key')]
|
||||
indexes = [models.Index(fields=['kind', 'target_id'], name='slx_traffic_item_idx')]
|
||||
|
||||
|
||||
class AIChapterReview(models.Model):
|
||||
chapter = models.OneToOneField(Chapter, on_delete=models.CASCADE, related_name='ai_editorial_review')
|
||||
result = models.JSONField(default=dict, blank=True)
|
||||
updated_at = models.DateTimeField(null=True, blank=True)
|
||||
started_at = models.DateTimeField(null=True, blank=True)
|
||||
version = models.CharField(max_length=64, blank=True)
|
||||
model_name = models.CharField(max_length=80, blank=True)
|
||||
|
||||
|
||||
class NewsletterSubscriber(models.Model):
|
||||
class Status(models.TextChoices):
|
||||
PENDING = 'pending', 'Awaiting confirmation'
|
||||
ACTIVE = 'active', 'Subscribed'
|
||||
OUT = 'out', 'Unsubscribed'
|
||||
|
||||
email = models.EmailField(unique=True)
|
||||
name = models.CharField('Name', max_length=120, blank=True)
|
||||
status = models.CharField(max_length=12, choices=Status.choices, default=Status.PENDING, db_index=True)
|
||||
requested_at = models.DateTimeField(null=True, blank=True)
|
||||
opted_in_at = models.DateTimeField(null=True, blank=True)
|
||||
opted_out_at = models.DateTimeField(null=True, blank=True)
|
||||
confirm_token = models.UUIDField(default=uuid4, unique=True, editable=False)
|
||||
unsubscribe_token = models.UUIDField(default=uuid4, unique=True, editable=False)
|
||||
confirm_queued = models.BooleanField(default=False, db_index=True)
|
||||
confirmation_issued_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
|
||||
class NewsletterGate(models.Model):
|
||||
window = models.DateTimeField()
|
||||
requests = models.PositiveIntegerField(default=0)
|
||||
|
||||
|
||||
class NewsletterCampaign(models.Model):
|
||||
subject = models.CharField(max_length=160)
|
||||
preheader = models.CharField(max_length=160, blank=True)
|
||||
body = models.TextField(max_length=20000, help_text='Use blank lines between paragraphs. The newsletter layout and unsubscribe link are added automatically.')
|
||||
link_label = models.CharField(max_length=55, blank=True)
|
||||
link_url = models.URLField(max_length=500, blank=True, validators=[https_url])
|
||||
queued_at = models.DateTimeField(null=True, blank=True, editable=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
permissions = [('send_newsletter', 'Can send newsletters and test emails')]
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if bool(self.link_label) != bool(self.link_url):
|
||||
raise ValidationError({'link_url': 'Enter both a button label and an HTTPS URL, or leave both blank.'})
|
||||
if '\r' in self.subject or '\n' in self.subject:
|
||||
raise ValidationError({'subject': 'Use a single line for the subject.'})
|
||||
|
||||
def __str__(self):
|
||||
return self.subject
|
||||
|
||||
|
||||
class NewsletterDelivery(models.Model):
|
||||
class Status(models.TextChoices):
|
||||
QUEUED = 'queued', 'Waiting'
|
||||
SENDING = 'sending', 'Sending'
|
||||
SENT = 'sent', 'Accepted by SMTP'
|
||||
FAILED = 'failed', 'Delivery error'
|
||||
SKIPPED = 'skipped', 'No longer subscribed'
|
||||
UNCERTAIN = 'uncertain', 'Outcome unknown'
|
||||
|
||||
campaign = models.ForeignKey(NewsletterCampaign, on_delete=models.PROTECT, related_name='deliveries')
|
||||
subscriber = models.ForeignKey(NewsletterSubscriber, on_delete=models.PROTECT)
|
||||
status = models.CharField(max_length=12, choices=Status.choices, default=Status.QUEUED, db_index=True)
|
||||
attempted_at = models.DateTimeField(null=True)
|
||||
error = models.CharField(max_length=100, blank=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=['campaign', 'subscriber'], name='slx_unique_newsletter_delivery')]
|
||||
Reference in new issue
Block a user