def ui_render_template(template_name_or_list, **context):

    art_user_id = request_value(request, 'user_id', None)
    need_user = int(request_value(request, 'needUserInfo', 0))

    if need_user > 0 and (art_user_id is None
                          or is_int_number(art_user_id) is False):
        return jsonify(form_res(RGResCode.lack_param))

    params = dict({"js_ver": RGJSVersion, "css_ver": RGCSSVersion}, **context)
    render = render_template(template_name_or_list, **params)

    if need_user > 0:
        from Model import user
        auth, view_user_id = do_auth()
        relation = user.get_relation(view_user_id, art_user_id)
        re_relation = user.get_relation(art_user_id, view_user_id)
        t = {
            "user": user.get_user(art_user_id).__dict__,
            "home": user.isHome(view_user_id, art_user_id),
            "auth": view_user_id is not None,
            "relation": relation,
            "re_relation": re_relation,
            'render': render
        }
        return jsonify(form_res(RGResCode.ok, t))
    return render
Example #2
0
def blog_page_render(art_user_id, view_user_id):
    relation = user.get_relation(view_user_id, art_user_id)
    re_relation = user.get_relation(art_user_id, view_user_id)
    t = {
        "user": user.get_user(art_user_id),
        "home": user.isHome(view_user_id, art_user_id),
        "authed": view_user_id is not None,
        "relation": relation,
        "re_relation": re_relation,
    }
    return RGUIController.ui_render_template("index.html", **t)
Example #3
0
def user_visit_page_info(view_user_id):
    art_user_id = request_value(request, 'user_id', None)
    if art_user_id is None or is_int_number(art_user_id) is False:
        return jsonify(form_res(RGResCode.lack_param))

    relation = user.get_relation(view_user_id, art_user_id)
    re_relation = user.get_relation(art_user_id, view_user_id)
    t = {
        "user": user.get_user(art_user_id).__dict__,
        "home": user.isHome(view_user_id, art_user_id),
        "auth": view_user_id is not None,
        "relation": relation,
        "re_relation": re_relation,
    }
    return jsonify(form_res(RGResCode.ok, t))
Example #4
0
def blog_view_page_render(view_user_id, art_user_id):
    relation = user.get_relation(view_user_id, art_user_id)
    t = {
        "user": user.get_user(art_user_id),
        "relation": relation,
    }
    return RGUIController.ui_render_template("blogView.html", **t)
Example #5
0
def photos_page_render(user_id, other_id, album_id):
    t = get_data_with_request(request)
    page = t['page'] if 'page' in t else 0
    size = t['size'] if 'size' in t else 10

    relation = user.get_relation(user_id, other_id)

    flag, album_detail = album.album_detail(album_id=album_id,
                                            relation=relation)

    if flag is False:
        photos, page_count, now_page, page_size, count = \
            ([], 1, 1, 10, 0)
    else:
        photos, page_count, now_page, page_size, count = \
            pic.page_list(other_id, album_id, page, size, relation)

    t = {
        "list": photos,
        "pageCount": page_count,
        "pageSize": page_size,
        "nowPage": now_page,
        "count": count,
        "user": user.get_user(other_id, need_icon=True),
        "home": user.isHome(user_id, other_id),
        'album': album_detail
    }
    return RGUIController.ui_render_template("photos.html", **t)
Example #6
0
def photo_pre_list(user_id):
    t = get_data_with_request(request)

    c_id = None
    album_id = None
    size = 1

    if 'id' in t:
        c_id = t['id']

    if 'albumId' in t:
        album_id = t['albumId']

    if 'size' in t:
        size = t['size']

    flag, _album = album.album_detail(album_id, -1)

    other_id = _album['user_id']

    relation = user.get_relation(other_id, user_id)

    flag, pre_ids, next_ids, current = \
        pic.id_list(user_id=other_id, album_id=album_id, current_id=c_id, size=size, relation=relation)

    if flag is True:
        return jsonify(
            form_res(RGResCode.ok, {
                'pre': pre_ids,
                'next': next_ids,
                'current': current
            }))
    else:
        return jsonify(form_res(RGResCode.update_fail, None))
Example #7
0
def art_group_list(user_id):
    t = get_data_with_request(request)

    if 'userId' in t:
        other_id = t['userId']
    else:
        other_id = user_id

    relation = user.get_relation(other_id, user_id)
    flag, result = article.group_list(other_id=other_id, relation=relation)

    code = RGResCode.ok if flag is True else RGResCode.not_existed
    res = form_res(code, result)
    return jsonify(res)
Example #8
0
def user_follow(user_id):
    t = get_data_with_request(request)

    other_id = int(t['id'])
    flag, relation = user.follow(user_id, t['id'])

    if flag is True:
        code = RGResCode.ok
        data = {
            'relation': relation,
            're_relation': user.get_relation(other_id, user_id),
        }
    else:
        code = RGResCode.insert_fail
        data = None
    return jsonify(form_res(code, data))
Example #9
0
def album_list(user_id, other_id):
    relation = 0

    lastPicUrl = 'lastPicUrl'
    coverUrl = 'coverUrl'

    sql = "SELECT ab.*, covers.filename as '{}', jp.filename as '{}' \
                    FROM \
                    album as ab \
                    left join (select file.filename, pic.album_id \
                        from pic, file \
                        where pic.file_id = file.id and pic.user_id = %(other_id)s \
                        order by file.timestamp desc limit 1) as jp \
                            on jp.album_id = ab.id \
                    left join (select file.filename, pic.id \
                          from pic, file \
                          where pic.file_id = file.id and pic.user_id = %(other_id)s) as covers \
                          on covers.id = ab.cover \
                    where ab.user_id=%(other_id)s {} order by ab.id desc".format(
        coverUrl, lastPicUrl, '{}')

    if user.isHome(user_id, other_id):
        sql = sql.format('')
    else:
        relation = user.get_relation(other_id, user_id)
        if relation == 0:
            sql = sql.format('and level=0')
        elif relation == 1:
            sql = sql.format('and level<=1')
        else:
            return None, relation
    result, count, new_id = dao.execute_sql(sql,
                                            ret=True,
                                            kv=True,
                                            args={'other_id': other_id})

    if count > 0:
        for row in result:
            if row[lastPicUrl] is not None:
                row[lastPicUrl] = url_with_name(row[lastPicUrl], thumb=True)
            if row[coverUrl] is not None:
                row[coverUrl] = url_with_name(row[coverUrl], thumb=True)
        return result, relation
    else:
        return None, relation