kopia lustrzana https://gitlab.com/marnanel/chapeau
intermediate
rodzic
600d13d4f5
commit
b7ab7cdf84
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2020-03-21 18:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trilby_api', '0011_auto_20200320_1540'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='status',
|
||||
name='remote_url',
|
||||
field=models.URLField(blank=True, max_length=255, null=True, unique=True),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2020-03-21 18:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trilby_api', '0012_status_remote_url'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='locked',
|
||||
field=models.BooleanField(default=False, help_text="If True, only followers can see this account's statuses."),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2020-03-21 18:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trilby_api', '0013_person_locked'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='moved_to',
|
||||
field=models.URLField(blank=True, default=True, help_text='If set, this account has moved away, and this is where it went.', max_length=255, null=True),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2020-03-21 18:48
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('trilby_api', '0014_person_moved_to'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='person',
|
||||
name='bot',
|
||||
field=models.BooleanField(default=False, help_text="If True, this account is a bot. If False, it's a human."),
|
||||
),
|
||||
]
|
|
@ -7,6 +7,7 @@ import kepi.bowler_pub.signals as kepi_signals
|
|||
import kepi.bowler_pub.find as kepi_find
|
||||
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
|
||||
|
@ -106,6 +107,25 @@ class Person(models.Model):
|
|||
help_text="If True, follow requests will be accepted automatically.",
|
||||
)
|
||||
|
||||
locked = models.BooleanField(
|
||||
default=False,
|
||||
help_text="If True, only followers can see this account's statuses.",
|
||||
)
|
||||
|
||||
bot = models.BooleanField(
|
||||
default=False,
|
||||
help_text="If True, this account is a bot. If False, it's a human.",
|
||||
)
|
||||
|
||||
moved_to = models.URLField(
|
||||
max_length = 255,
|
||||
null = True,
|
||||
blank = True,
|
||||
default = True,
|
||||
help_text="If set, this account has moved away, and "+\
|
||||
"this is where it went."
|
||||
)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
if self.remote_url is not None:
|
||||
|
@ -179,6 +199,14 @@ class Person(models.Model):
|
|||
def following(self):
|
||||
return None # FIXME
|
||||
|
||||
@property
|
||||
def fields(self):
|
||||
return [] # FIXME
|
||||
|
||||
@property
|
||||
def emojis(self):
|
||||
return [] # FIXME
|
||||
|
||||
###################
|
||||
|
||||
class Status(models.Model):
|
||||
|
@ -186,6 +214,13 @@ 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,
|
||||
)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return 'FIXME' # FIXME
|
||||
|
@ -234,6 +269,58 @@ class Status(models.Model):
|
|||
max_length = 255,
|
||||
)
|
||||
|
||||
@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
|
||||
|
||||
###################
|
||||
|
||||
class Notification(models.Model):
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
from rest_framework import serializers
|
||||
from kepi.bowler_pub.models import AcItem, AcActor
|
||||
from kepi.bowler_pub.create import create as bowler_pub_create
|
||||
from kepi.trilby_api.models import Notification
|
||||
from kepi.trilby_api.models import *
|
||||
from oauth2_provider.models import Application
|
||||
|
||||
#########################################
|
||||
|
@ -45,7 +43,7 @@ class UserSerializer(serializers.ModelSerializer):
|
|||
statuses_count = serializers.IntegerField()
|
||||
|
||||
class Meta:
|
||||
model = AcActor
|
||||
model = Person
|
||||
fields = (
|
||||
'id',
|
||||
'username',
|
||||
|
@ -94,7 +92,7 @@ class UserSerializerWithSource(UserSerializer):
|
|||
|
||||
class StatusSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = AcItem
|
||||
model = Status
|
||||
fields = (
|
||||
'id',
|
||||
'uri',
|
||||
|
@ -151,11 +149,11 @@ class StatusSerializer(serializers.ModelSerializer):
|
|||
)
|
||||
|
||||
in_reply_to_id = serializers.PrimaryKeyRelatedField(
|
||||
queryset=AcItem.objects.all,
|
||||
queryset=Status.objects.all,
|
||||
required = False)
|
||||
|
||||
in_reply_to_account_id = serializers.PrimaryKeyRelatedField(
|
||||
queryset=AcItem.objects.all,
|
||||
queryset=Status.objects.all,
|
||||
required = False)
|
||||
|
||||
reblog = serializers.URLField(
|
||||
|
@ -202,7 +200,7 @@ class StatusSerializer(serializers.ModelSerializer):
|
|||
|
||||
class StatusContextSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = AcItem
|
||||
model = Status
|
||||
fields = (
|
||||
'ancestors',
|
||||
'descendants',
|
||||
|
|
|
@ -15,7 +15,6 @@ from rest_framework.permissions import IsAuthenticated
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
import logging
|
||||
import kepi.bowler_pub.models as bowler_pub_models
|
||||
import json
|
||||
import re
|
||||
|
||||
|
@ -23,21 +22,6 @@ logger = logging.Logger(name='kepi')
|
|||
|
||||
###########################
|
||||
|
||||
# Decorator
|
||||
def id_field_int_to_hex(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
if 'id' in kwargs:
|
||||
as_hex = '%08x' % (int(kwargs['id']),)
|
||||
logger.debug('Converting decimal id=%s into hex id=%s',
|
||||
kwargs['id'], as_hex)
|
||||
kwargs['id'] = as_hex
|
||||
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
###########################
|
||||
|
||||
class Instance(View):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
@ -71,7 +55,7 @@ def error_response(status, reason):
|
|||
class DoSomethingWithStatus(generics.GenericAPIView):
|
||||
|
||||
serializer_class = StatusSerializer
|
||||
queryset = AcItem.objects.all()
|
||||
queryset = Status.objects.all()
|
||||
|
||||
def _do_something_with(self, the_status, request):
|
||||
raise NotImplementedError()
|
||||
|
@ -108,7 +92,7 @@ class DoSomethingWithStatus(generics.GenericAPIView):
|
|||
class Favourite(DoSomethingWithStatus):
|
||||
|
||||
def _do_something_with(self, the_status, request):
|
||||
existing = bowler_pub_models.AcLike.objects.filter(
|
||||
existing = Like.objects.filter(
|
||||
f_actor = request.user.person.acct,
|
||||
f_object = the_status.id,
|
||||
).exists()
|
||||
|
@ -182,7 +166,7 @@ class Verify_Credentials(generics.GenericAPIView):
|
|||
|
||||
class User(generics.GenericAPIView):
|
||||
|
||||
queryset = AcActor.objects.all()
|
||||
queryset = Person.objects.all()
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
whoever = get_object_or_404(
|
||||
|
@ -198,10 +182,9 @@ class Statuses(generics.ListCreateAPIView,
|
|||
generics.DestroyAPIView,
|
||||
):
|
||||
|
||||
queryset = bowler_pub_models.AcItem.objects.filter_local_only()
|
||||
queryset = Status.objects.filter(remote_url=None)
|
||||
serializer_class = StatusSerializer
|
||||
|
||||
@id_field_int_to_hex
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
queryset = self.get_queryset()
|
||||
|
@ -276,9 +259,8 @@ class Statuses(generics.ListCreateAPIView,
|
|||
|
||||
class StatusContext(generics.ListCreateAPIView):
|
||||
|
||||
queryset = bowler_pub_models.AcItem.objects.all()
|
||||
queryset = Status.objects.all()
|
||||
|
||||
@id_field_int_to_hex
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
||||
queryset = self.get_queryset()
|
||||
|
@ -318,7 +300,7 @@ class PublicTimeline(AbstractTimeline):
|
|||
|
||||
result = []
|
||||
|
||||
timeline = bowler_pub_models.AcItem.objects.all()
|
||||
timeline = Status.objects.all()
|
||||
|
||||
for item in timeline:
|
||||
|
||||
|
@ -340,7 +322,7 @@ class HomeTimeline(AbstractTimeline):
|
|||
|
||||
result = []
|
||||
|
||||
inbox = bowler_pub_models.Collection.get(
|
||||
inbox = Collection.get(
|
||||
user = request.user.person,
|
||||
collection = 'inbox').members
|
||||
|
||||
|
@ -360,7 +342,7 @@ class HomeTimeline(AbstractTimeline):
|
|||
# TODO stub
|
||||
class AccountsSearch(generics.ListAPIView):
|
||||
|
||||
queryset = AcActor.objects.all()
|
||||
queryset = Person.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
||||
permission_classes = [
|
||||
|
@ -394,11 +376,11 @@ class UserFeed(View):
|
|||
|
||||
def get(self, request, username, *args, **kwargs):
|
||||
|
||||
user = get_object_or_404(bowler_pub_models.AcActor,
|
||||
user = get_object_or_404(Person,
|
||||
id = '@'+username,
|
||||
)
|
||||
|
||||
statuses = [x.member for x in bowler_pub_models.Collection.get(
|
||||
statuses = [x.member for x in Collection.get(
|
||||
username+'/outbox',
|
||||
).contents]
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue