add Post.feed_info()
This commit is contained in:
parent
87d2eb6d0b
commit
b6fa88f201
4 changed files with 25 additions and 6 deletions
|
|
@ -26,7 +26,7 @@ from suou import twocolon_list, WantsContentType
|
||||||
|
|
||||||
from .colors import color_themes, theme_classes
|
from .colors import color_themes, theme_classes
|
||||||
|
|
||||||
__version__ = '0.5.0-dev35'
|
__version__ = '0.5.0-dev36'
|
||||||
|
|
||||||
APP_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
APP_BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,3 +79,5 @@ class UserLoader(AuthUser):
|
||||||
return self._auth_obj
|
return self._auth_obj
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
|
username: str
|
||||||
|
display_name: str
|
||||||
|
|
|
||||||
|
|
@ -644,6 +644,16 @@ class Post(Base):
|
||||||
def is_text_post(self):
|
def is_text_post(self):
|
||||||
return self.post_type == POST_TYPE_DEFAULT
|
return self.post_type == POST_TYPE_DEFAULT
|
||||||
|
|
||||||
|
def feed_info(self):
|
||||||
|
return dict(
|
||||||
|
id=Snowflake(self.id).to_b32l(),
|
||||||
|
slug = self.slug,
|
||||||
|
title = self.title,
|
||||||
|
author = self.author.simple_info(),
|
||||||
|
to = self.topic_or_user().simple_info(),
|
||||||
|
created_at = self.created_at
|
||||||
|
)
|
||||||
|
|
||||||
class Comment(Base):
|
class Comment(Base):
|
||||||
__tablename__ = 'freak_comment'
|
__tablename__ = 'freak_comment'
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from quart import Blueprint, redirect, url_for
|
from quart import Blueprint, redirect, request, url_for
|
||||||
from quart_auth import AuthUser, current_user, login_required, login_user, logout_user
|
from quart_auth import AuthUser, current_user, login_required, login_user, logout_user
|
||||||
from quart_schema import QuartSchema, validate_request, validate_response
|
from quart_schema import QuartSchema, validate_request, validate_response
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
@ -48,9 +48,10 @@ async def health():
|
||||||
## to get complete sooner or later
|
## to get complete sooner or later
|
||||||
|
|
||||||
## XXX there is a bug in suou.sqlalchemy.auth_required() — apparently, /user/@me does not
|
## XXX there is a bug in suou.sqlalchemy.auth_required() — apparently, /user/@me does not
|
||||||
## redirect, neither is able to get user injected.
|
## redirect, neither is able to get user injected. It was therefore dismissed.
|
||||||
## Auth-based REST endpoints won't be fully functional until 0.6 in most cases
|
## Auth-based REST endpoints won't be fully functional until 0.6 in most cases
|
||||||
|
|
||||||
|
## USERS ##
|
||||||
|
|
||||||
@bp.get('/user/@me')
|
@bp.get('/user/@me')
|
||||||
@login_required
|
@login_required
|
||||||
|
|
@ -84,6 +85,7 @@ async def resolve_user(username: str):
|
||||||
abort(404, 'User not found')
|
abort(404, 'User not found')
|
||||||
return redirect(url_for('rest.user_get', id=uid)), 302
|
return redirect(url_for('rest.user_get', id=uid)), 302
|
||||||
|
|
||||||
|
## POSTS ##
|
||||||
|
|
||||||
@bp.get('/post/<b32l:id>')
|
@bp.get('/post/<b32l:id>')
|
||||||
async def get_post(id: int):
|
async def get_post(id: int):
|
||||||
|
|
@ -104,6 +106,8 @@ async def get_post(id: int):
|
||||||
|
|
||||||
return dict(posts={f'{Snowflake(id):l}': pj})
|
return dict(posts={f'{Snowflake(id):l}': pj})
|
||||||
|
|
||||||
|
## GUILDS ##
|
||||||
|
|
||||||
async def _guild_info(gu: Guild):
|
async def _guild_info(gu: Guild):
|
||||||
return dict(
|
return dict(
|
||||||
id = f'{Snowflake(gu.id):l}',
|
id = f'{Snowflake(gu.id):l}',
|
||||||
|
|
@ -138,21 +142,24 @@ async def guild_feed(gname: str):
|
||||||
# TODO add feed
|
# TODO add feed
|
||||||
feed = []
|
feed = []
|
||||||
algo = topic_timeline(gname)
|
algo = topic_timeline(gname)
|
||||||
posts: list[Post] = makelist((await db.paginate(algo)))
|
posts = await db.paginate(algo)
|
||||||
for p in posts:
|
async for p in posts:
|
||||||
feed.append(p.feed_info())
|
feed.append(p.feed_info())
|
||||||
|
|
||||||
return dict(guilds={f'{Snowflake(gu.id):l}': gj}, feed=feed)
|
return dict(guilds={f'{Snowflake(gu.id):l}': gj}, feed=feed)
|
||||||
|
|
||||||
|
## LOGIN/OUT ##
|
||||||
|
|
||||||
class LoginIn(BaseModel):
|
class LoginIn(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
remember: bool
|
remember: bool = False
|
||||||
|
|
||||||
@bp.post('/login')
|
@bp.post('/login')
|
||||||
@validate_request(LoginIn)
|
@validate_request(LoginIn)
|
||||||
async def login(data: LoginIn):
|
async def login(data: LoginIn):
|
||||||
|
|
||||||
|
print(data)
|
||||||
async with db as session:
|
async with db as session:
|
||||||
u = (await session.execute(select(User).where(User.username == data.username))).scalar()
|
u = (await session.execute(select(User).where(User.username == data.username))).scalar()
|
||||||
match check_login(u, data.password):
|
match check_login(u, data.password):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue