Пример #1
0
def obtain_share(db, poster_id, visible):
    """ 点击分享时,返回分享所需信息,信息体只包含:
    """
    # 0. raw data
    m_poster = obtain_by_id(db, poster_id, visible)

    # 1. title
    m_order = order_usecase.retrieve_order(db, m_poster.order_no)
    if m_order is None:
        raise exception.NoExistOrder(m_poster.order_no)
    title = m_order.child_nickname + ShareCopy.Title.value

    description = ShareCopy.Description.value
    webpage_url = Facade.config["wechat"][
        "url"] + str(poster_id) + '&child=' + common_usecase.change_CN_url(m_poster.child_nickname)
    #webpage_url = common_usecase.change_CN_url(m_poster.child_nickname)

    thumb_image_url = ''
    if m_poster.media_obj_list != []:
        media = m_poster.media_obj_list[0]
        thumb_image_url = media.cover_url + ShareCopy.ThumbingApi.value
    else:
        thumb_image_url = ShareCopy.DefaultImage.value

    data = DictObject(
        title=title,
        description=description,
        webpage_url=webpage_url,
        thumb_image_url=thumb_image_url
    )

    return data
Пример #2
0
def retrieve_to_user_id(db, order_no: int) -> int:
    """   """
    m_order = order_orm.find_order_by_order_no(db, order_no)

    if m_order is None:
        raise exception.NoExistOrder(order_no)

    return m_order.buyer_id
Пример #3
0
def has_auth_submit_rate(db: Session, user_id: int, order_no: int):
    """
    是否有权限对poster对应的order进行评分
    -> 他是order的buyer
    """
    result = False
    #---------
    m_order = order_usecase.obtain_order(db, order_no=order_no)
    if m_order is None:
        raise exception.NoExistOrder(order_no)

    if m_order.buyer_id == user_id:
        result = True
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_submit_rate',
            which=str(order_no),
            who=str(user_id))
Пример #4
0
def has_auth_obtain_order_poster(db: Session, user_id: int,
                                 order_no: int) -> None:
    """
    是否有权限查看当前order是否有poster
    -> 他是order的seller
    """
    result = False
    #---------
    m_order = order_usecase.obtain_order(db, order_no=order_no)
    if m_order is None:
        raise exception.NoExistOrder(order_no)

    if m_order.seller_id == user_id:
        result = True
    #---------
    if not result:
        raise exception.MoretimeAuthorityException(
            where='has_auth_obtain_order_poster',
            which=str(order_no),
            who=str(user_id))
Пример #5
0
def obtain_by_id(
        db: Session,
        poster_id: int, visible_choose: int=None)->Dict:
    """ 通过poster的id来找到并包装poster
        0. basic information
        1. child_nickname & start_ts
        2. 
    """
    # 0. basic information
    m_poster = obtain_simple(db, poster_id=poster_id)
    if m_poster is None:
        raise exception.NoExistPoster(poster_id)

    # 1. child_nickname
    m_order = order_usecase.retrieve_order(db, m_poster.index_id)
    if m_order is None:
        raise exception.NoExistOrder(m_poster.index_id)
    child_nickname = m_order.child_nickname

    # 1. 订单时间
    m_timeshare = order_usecase.retrieve_timeshare(db, m_order.time_sharing_id)
    if m_timeshare is None:
        raise exception.NoExistTimeSharing(m_order.time_sharing_id)
    start_ts = m_timeshare.start_ts

    # 2. visible
    if visible_choose is None:
        visible_choose = visible_usecase.obtain_visible_choose(
            m_poster)

    # 3. packing video
    video_obj_list = video_usecase.video_ids_to_objs(
        db, m_poster, visible_choose)

    # 4. packing picture
    picture_obj_list = picture_usecase.picture_ids_to_objs(
        db, m_poster, visible_choose)

    # 5. sort media
    media_obj_list = []
    if m_poster.sort_order != '' or m_poster.sort_order is not None and (video_obj_list is not None or picture_obj_list is not None):

        order_list = [int(i) for i in m_poster.sort_order.split(',')] \
            if m_poster.sort_order is not None and m_poster.sort_order != '' else []

        media_obj_list = common_usecase.prepare_sort_object(
            order_list, picture_obj_list, video_obj_list)

    # 6. user 头像信息
    user = user_usecase.obtain_user(db, m_poster.from_user_id)
    if user is None:
        raise exception.NoExistUser(m_poster.from_user_id)

    # 7. 评分
    rate = MoretimeRate.Default.value
    m_rate = rate_orm.find_rate_by_order_no(db, m_poster.index_id)
    if m_rate is not None:
        rate = m_rate.rate

    # 8. packing poster
    poster = packing(m_poster, child_nickname, start_ts,
                     media_obj_list, user, rate)

    return poster