Пример #1
0
    dt_watched=T.datetime.object.optional,
    is_favorited=T.bool.default(False),
    dt_favorited=T.datetime.object.optional,
    summary=T.str.optional,
    content=T.str.optional,
    image_token=T.str.optional,
).slim

StoryResultSchema = T.dict(
    total=T.int.optional,
    size=T.int.optional,
    offset=T.int.optional,
    storys=T.list(StorySchema).maxlen(5000),
)

StoryView = RestRouter()

STORY_DETAIL_FEILDS = ['story__summary', 'story__content']


@StoryView.get('story/query')
def story_query_by_feed(
    request,
    feed_id: T.feed_unionid.object,
    offset: T.int.min(0).optional,
    size: T.int.min(1).max(100).default(10),
    detail: StoryDetailSchema,
) -> StoryResultSchema:
    """Story list"""
    check_unionid(request, feed_id)
    try:
Пример #2
0
FeedCreationSchema = T.dict(
    id=T.int,
    user=T.dict(
        id=T.int,
    ),
    is_ready=T.bool,
    feed_id=T.feed_unionid.optional,
    status=T.str,
    url=T.url,
    message=T.str.optional,
    dt_updated=T.datetime.object.optional,
    dt_created=T.datetime.object.optional,
)


FeedView = RestRouter()


@FeedView.get('feed/query')
@FeedView.post('feed/query')
def feed_query(
    request,
    hints: T.list(T.dict(id=T.feed_unionid.object, dt_updated=T.datetime.object)).maxlen(5000).optional,
    detail: FeedDetailSchema,
) -> T.dict(
    total=T.int.optional,
    size=T.int.optional,
    feeds=T.list(FeedSchema).maxlen(5000),
    deleted_size=T.int.optional,
    deleted_ids=T.list(T.feed_unionid),
):
Пример #3
0
from django_rest_validr import RestRouter, T
from rest_framework.response import Response
from rssant_common.shopant import SHOPANT_SERVER

ShopantView = RestRouter()


@ShopantView.post('shopant/integration')
def shopant_integration(
    request,
    method: T.str,
    params: T.dict.key(T.str).optional,
) -> T.dict:
    if not SHOPANT_SERVER:
        return Response(status=501)
    if not params:
        params = {}
    user = request.user
    params['customer'] = dict(
        external_id=user.id,
        nickname=user.username,
    )
    return SHOPANT_SERVER.integration(dict(method=method, params=params))
Пример #4
0
from rssant_common.hashid import HASH_ID

UserSchema = T.dict(
    id=T.str,
    username=T.str,
    has_usable_password=T.bool.optional,
    avatar_url=T.str.optional,
    token=T.str.optional,
    social_accounts=T.list(T.dict(
        provider=T.str,
        avatar_url=T.str.optional,
    )).optional,
    shopant_enable=T.bool.default(False),
)

UserView = RestRouter(permission_classes=[AllowAny])


def serialize_user(user):
    avatar_url = None
    social_accounts_info = []
    social_accounts = list(SocialAccount.objects.filter(user=user).all())
    for acc in social_accounts:
        if not avatar_url:
            avatar_url = acc.get_avatar_url()
        social_accounts_info.append(
            dict(
                provider=acc.provider,
                avatar_url=acc.get_avatar_url(),
            ))
    token, created = Token.objects.get_or_create(user=user)