split "models" into separate files

trilby-heavy
Marnanel Thurman 2020-04-04 01:37:26 +01:00
rodzic 5021f60431
commit f918d21c30
6 zmienionych plików z 325 dodań i 269 usunięć

Wyświetl plik

@ -0,0 +1,14 @@
from .person import *
from .status import *
from .notification import *
from .like import *
from .follow import *
__all__ = [
'TrilbyUser',
'Person',
'Status',
'Notification',
'Like',
'Follow',
]

Wyświetl plik

@ -0,0 +1,54 @@
from django.db import models
from django.db.models.constraints import UniqueConstraint
from django.contrib.auth.models import AbstractUser
from django.conf import settings
from kepi.bowler_pub.create import create
import kepi.bowler_pub.crypto as crypto
from kepi.bowler_pub.utils import uri_to_url
from django.utils.timezone import now
from django.core.exceptions import ValidationError
import logging
logger = logging.Logger('kepi')
class Follow(models.Model):
follower = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'following',
)
following = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'followers',
)
requested = models.BooleanField(
default=True,
)
show_reblogs = models.BooleanField(
default=True,
)
class Meta:
constraints = [
UniqueConstraint(
fields = ['follower', 'following'],
name = 'follow_only_once',
),
]
def __str__(self):
if self.requested:
return '[%s requests to follow %s]' % (
follower,
following,
)
else:
return '[%s follows %s]' % (
follower,
following,
)

Wyświetl plik

@ -0,0 +1,35 @@
from django.db import models
from django.db.models.constraints import UniqueConstraint
from django.contrib.auth.models import AbstractUser
from django.conf import settings
from kepi.bowler_pub.create import create
import kepi.bowler_pub.crypto as crypto
from kepi.bowler_pub.utils import uri_to_url
from django.utils.timezone import now
from django.core.exceptions import ValidationError
import logging
logger = logging.Logger('kepi')
class Like(models.Model):
liker = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
)
liked = models.ForeignKey(
'Status',
on_delete = models.DO_NOTHING,
)
class Meta:
constraints = [
UniqueConstraint(
fields = ['liker', 'liked'],
name = 'i_cant_like_this_enough',
),
]
def __str__(self):
return '[%s likes %s]' % (liker, liked)

Wyświetl plik

@ -0,0 +1,74 @@
from django.db import models
from django.db.models.constraints import UniqueConstraint
from django.contrib.auth.models import AbstractUser
from django.conf import settings
from kepi.bowler_pub.create import create
import kepi.bowler_pub.crypto as crypto
from kepi.bowler_pub.utils import uri_to_url
from django.utils.timezone import now
from django.core.exceptions import ValidationError
import logging
logger = logging.Logger('kepi')
class Notification(models.Model):
FOLLOW = 'F'
MENTION = 'M'
REBLOG = 'R'
FAVOURITE = 'L'
TYPE_CHOICES = [
(FOLLOW, 'follow'),
(MENTION, 'mention'),
(REBLOG, 'reblog'),
(FAVOURITE, 'favourite'),
]
notification_type = models.CharField(
max_length = 1,
choices = TYPE_CHOICES,
)
created_at = models.DateTimeField(
default = now,
)
for_account = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'notifications_for',
)
about_account = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'notifications_about',
blank = True,
null = True,
)
status = models.ForeignKey(
'Status',
on_delete = models.DO_NOTHING,
blank = True,
null = True,
)
def __str__(self):
if self.notification_type == self.FOLLOW:
detail = '%s has followed you' % (self.about_account,)
elif self.notification_type == self.MENTION:
detail = '%s has mentioned you' % (self.about_account,)
elif self.notification_type == self.REBLOG:
detail = '%s has reblogged you' % (self.about_account,)
elif self.notification_type == self.FAVOURITE:
detail = '%s has favourited your status' % (self.about_account,)
else:
detail = '(%s?)' % (self.notification_type,)
return '[%s: %s]' % (
self.for_account.id,
detail,
)

Wyświetl plik

@ -243,8 +243,10 @@ class Person(models.Model):
@property
def inbox(self):
import kepi.trilby_api.models as trilby_models
def inbox_generator():
for status in Status.objects.all():
for status in trilby_models.Status.objects.all():
yield status
return inbox_generator()
@ -258,271 +260,3 @@ class Person(models.Model):
return self.remote_url
else:
return self.local_user
###################
class Status(models.Model):
# TODO: The original design has the serial number
# monotonically but unpredictably increasing.
remote_url = models.URLField(
max_length = 255,
null = True,
blank = True,
unique = True,
)
account = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
)
in_reply_to_id = models.ForeignKey(
'self',
on_delete = models.DO_NOTHING,
null = True,
blank = True,
)
content = models.TextField(
)
created_at = models.DateTimeField(
default = now,
)
# TODO Media
sensitive = models.BooleanField(
default = False,
)
spoiler_text = models.CharField(
max_length = 255,
null = True,
blank = True,
default = '',
)
visibility = models.CharField(
max_length = 255,
default = 'public',
)
language = models.CharField(
max_length = 255,
null = True,
default = settings.KEPI['LANGUAGES'][0],
)
idempotency_key = models.CharField(
max_length = 255,
null = True,
default = None,
)
@property
def emojis(self):
return [] # TODO
@property
def reblogs_count(self):
return 0 # FIXME
@property
def favourites_count(self):
return 0 # FIXME
@property
def reblogged(self):
return False # FIXME
@property
def favourited(self):
return False # FIXME
@property
def muted(self):
return False # FIXME
@property
def pinned(self):
return False # FIXME
@property
def media_attachments(self):
return [] # FIXME
@property
def mentions(self):
return [] # FIXME
@property
def tags(self):
return [] # FIXME
@property
def card(self):
return None # FIXME
@property
def poll(self):
return None # FIXME
@property
def application(self):
return None # FIXME
@property
def in_reply_to_account_id(self):
return None # FIXME
@property
def uri(self):
return 'FIXME' # FIXME
@property
def url(self):
return 'FIXME' # FIXME
@property
def ancestors(self):
return [] # FIXME
@property
def descendants(self):
return [] # FIXME
###################
class Notification(models.Model):
FOLLOW = 'F'
MENTION = 'M'
REBLOG = 'R'
FAVOURITE = 'L'
TYPE_CHOICES = [
(FOLLOW, 'follow'),
(MENTION, 'mention'),
(REBLOG, 'reblog'),
(FAVOURITE, 'favourite'),
]
notification_type = models.CharField(
max_length = 1,
choices = TYPE_CHOICES,
)
created_at = models.DateTimeField(
default = now,
)
for_account = models.ForeignKey(
Person,
on_delete = models.DO_NOTHING,
related_name = 'notifications_for',
)
about_account = models.ForeignKey(
Person,
on_delete = models.DO_NOTHING,
related_name = 'notifications_about',
blank = True,
null = True,
)
status = models.ForeignKey(
Status,
on_delete = models.DO_NOTHING,
blank = True,
null = True,
)
def __str__(self):
if self.notification_type == self.FOLLOW:
detail = '%s has followed you' % (self.about_account,)
elif self.notification_type == self.MENTION:
detail = '%s has mentioned you' % (self.about_account,)
elif self.notification_type == self.REBLOG:
detail = '%s has reblogged you' % (self.about_account,)
elif self.notification_type == self.FAVOURITE:
detail = '%s has favourited your status' % (self.about_account,)
else:
detail = '(%s?)' % (self.notification_type,)
return '[%s: %s]' % (
self.for_account.id,
detail,
)
#####################################
class Like(models.Model):
liker = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
)
liked = models.ForeignKey(
'Status',
on_delete = models.DO_NOTHING,
)
class Meta:
constraints = [
UniqueConstraint(
fields = ['liker', 'liked'],
name = 'i_cant_like_this_enough',
),
]
def __str__(self):
return '[%s likes %s]' % (liker, liked)
#####################################
class Follow(models.Model):
follower = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'following',
)
following = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
related_name = 'followers',
)
requested = models.BooleanField(
default=True,
)
show_reblogs = models.BooleanField(
default=True,
)
class Meta:
constraints = [
UniqueConstraint(
fields = ['follower', 'following'],
name = 'follow_only_once',
),
]
def __str__(self):
if self.requested:
return '[%s requests to follow %s]' % (
follower,
following,
)
else:
return '[%s follows %s]' % (
follower,
following,
)

Wyświetl plik

@ -0,0 +1,145 @@
from django.db import models
from django.db.models.constraints import UniqueConstraint
from django.contrib.auth.models import AbstractUser
from django.conf import settings
from kepi.bowler_pub.create import create
import kepi.bowler_pub.crypto as crypto
from kepi.bowler_pub.utils import uri_to_url
from django.utils.timezone import now
from django.core.exceptions import ValidationError
import logging
logger = logging.Logger('kepi')
class Status(models.Model):
# TODO: The original design has the serial number
# monotonically but unpredictably increasing.
remote_url = models.URLField(
max_length = 255,
null = True,
blank = True,
unique = True,
)
account = models.ForeignKey(
'Person',
on_delete = models.DO_NOTHING,
)
in_reply_to_id = models.ForeignKey(
'self',
on_delete = models.DO_NOTHING,
null = True,
blank = True,
)
content = models.TextField(
)
created_at = models.DateTimeField(
default = now,
)
# TODO Media
sensitive = models.BooleanField(
default = False,
)
spoiler_text = models.CharField(
max_length = 255,
null = True,
blank = True,
default = '',
)
visibility = models.CharField(
max_length = 255,
default = 'public',
)
language = models.CharField(
max_length = 255,
null = True,
default = settings.KEPI['LANGUAGES'][0],
)
idempotency_key = models.CharField(
max_length = 255,
null = True,
default = None,
)
@property
def emojis(self):
return [] # TODO
@property
def reblogs_count(self):
return 0 # FIXME
@property
def favourites_count(self):
return 0 # FIXME
@property
def reblogged(self):
return False # FIXME
@property
def favourited(self):
return False # FIXME
@property
def muted(self):
return False # FIXME
@property
def pinned(self):
return False # FIXME
@property
def media_attachments(self):
return [] # FIXME
@property
def mentions(self):
return [] # FIXME
@property
def tags(self):
return [] # FIXME
@property
def card(self):
return None # FIXME
@property
def poll(self):
return None # FIXME
@property
def application(self):
return None # FIXME
@property
def in_reply_to_account_id(self):
return None # FIXME
@property
def uri(self):
return 'FIXME' # FIXME
@property
def url(self):
return 'FIXME' # FIXME
@property
def ancestors(self):
return [] # FIXME
@property
def descendants(self):
return [] # FIXME