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)
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
def photo_page_render(user_id, other_id): albums, re_relation = album.album_list(user_id, other_id) t = { "list": albums, "user": user.get_user(other_id), "home": user.isHome(user_id, other_id), } return RGUIController.ui_render_template("albums.html", **t)
def page_list(other_id=None, art_user_id=-1, page=1, size=10): size = int(size) relation = -1 page = int(page) if page < 1: page = 1 if other_id is None: sql = 'select art.* from art left join art_group as g on g.id = art.group_id \ where \ art.user_id=%(art_user)s \ and cate <= 0 \ and (g.id is NULL or g.level <= 0) \ order by addtime desc' relation = 0 elif user.isHome(art_user_id, other_id): relation = 2 sql = 'select art.* from art where user_id=%(art_user)s order by addtime desc' else: sql = 'select art.*, relation from art \ left join art_group as g on g.id = art.group_id \ left join (select relation from user_relation \ where m_user_id = %(art_user)s and o_user_id = %(other_id)s) as r on 1=1 \ where \ art.user_id=%(art_user)s \ and (g.id is NULL or g.level <= 0 or g.level <= r.relation) \ and (cate <= 0 or cate <= r.relation) \ order by addtime desc' args = { 'art_user': art_user_id, 'other_id': other_id, } result, count, new_id = dao.execute_sql(sql, ret=False, args=args) page_count = int(operator.truediv(count - 1, size)) + 1 page = min(page, page_count) sql += ' limit %d offset %d' % (size, (page - 1) * size) result, this_page_count, new_id = dao.execute_sql(sql, kv=True, args=args) page = page if this_page_count > 0 else page_count if result is not None: for row in result: if relation is -1 and 'relation' in row: relation = row['relation'] if relation is None: relation = 0 del row['content'] return result, page_count, page, size, count, relation
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)
def months_list_view(art_user=None, other_id=None, group_id=None, timezone=8): timezone = '%+d' % timezone time_format = '%%Y-%%m' if other_id is None: sql = 'SELECT date_format(CONVERT_TZ(create_time, @@session.time_zone, "{}:00"), "{}") months, count(art.id) as "count" \ FROM art \ left join art_group as g on g.id = art.group_id \ where \ art.user_id=%(art_user)s \ and cate <= 0 \ and (g.id is NULL or g.level <= 0) \ {} \ group by months order by months desc'.format( timezone, time_format, '{}') elif user.isHome(art_user, other_id): sql = 'SELECT date_format(CONVERT_TZ(create_time, @@session.time_zone, "{}:00"), "{}") months, count(art.id) as "count" \ FROM art where user_id=%(art_user)s {} \ group by months order by months desc'.format( timezone, time_format, '{}') else: sql = 'SELECT date_format(CONVERT_TZ(create_time, @@session.time_zone, "{}:00"), "{}") months, count(art.id) as "count" \ FROM art \ left join art_group as g on g.id = art.group_id \ left join (select relation from user_relation \ where m_user_id = %(art_user)s and o_user_id = %(other_id)s) as r on 1=1 \ where art.user_id=%(art_user)s \ and (g.id is NULL or g.level <= 0 or g.level <= r.relation) \ and (cate <= 0 or cate <= r.relation) \ {} \ group by months order by months desc'.format( timezone, time_format, '{}') if group_id is None: sql = sql.format('') elif group_id < 0: sql = sql.format( 'and (group_id is null or group_id not in (SELECT id from art_group))' ) else: sql = sql.format('and group_id=%(group_id)s') result, count, new_id = dao.execute_sql(sql, kv=True, args={ 'art_user': art_user, 'other_id': other_id, 'group_id': group_id, }) return result
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))
def home_page(art_user_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 auth, view_user_id = RGUIController.do_auth() arts, page_count, now_page, page_size, count, re_relation = article.page_list( other_id=view_user_id, art_user_id=art_user_id, page=page, size=size) t = { "list": arts, "pageCount": page_count, "pageSize": page_size, "nowPage": now_page, "count": count, "home": user.isHome(view_user_id, art_user_id), } return RGUIController.ui_render_template("home.html", **t)
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
def month_list(art_user, other_id, group_id, year, month, timezone=8): s_time = RGTimeUtil.timestamp_with_month(year=year, month=month, timezone=timezone) if month + 1 >= 13: year += 1 month = 1 else: month += 1 e_time = RGTimeUtil.timestamp_with_month(year=year, month=month, timezone=timezone) item = "art.id, art.title, art.summary, art.cate, art.cover, \ art.addtime, art.updatetime, art.create_time, art.read_count, art.group_id" if other_id is None: sql = 'select {} from art \ left join art_group as g on g.id = art.group_id \ where \ art.user_id=%(art_user)s \ and addtime >= {} \ and addtime < {} \ and cate <= 0 \ and (g.id is NULL or g.level <= 0) \ {} \ order by addtime desc'.format(item, s_time, e_time, '{}') elif user.isHome(art_user, other_id): sql = 'select {} from art \ where user_id=%(art_user)s and \ addtime >= {} and addtime < {} {} order by addtime desc'.format( item, s_time, e_time, '{}') else: sql = 'select {} from art \ left join art_group as g on g.id = art.group_id \ left join (select relation from user_relation \ where m_user_id = %(art_user)s and o_user_id = %(other_id)s) as r on 1=1 \ where \ art.user_id=%(art_user)s \ and addtime >= {} \ and addtime < {} \ and (g.id is NULL or g.level <= 0 or g.level <= r.relation) \ and (cate <= 0 or cate <= r.relation) \ {} \ order by addtime desc'.format(item, s_time, e_time, '{}') if group_id is None: sql = sql.format('') elif group_id < 0: sql = sql.format( 'and (group_id is null or group_id not in (SELECT id from art_group))' ) else: sql = sql.format('and group_id=%(group_id)s') result, count, new_id = dao.execute_sql(sql, kv=True, args={ 'art_user': art_user, 'other_id': other_id, 'group_id': group_id, }) return result