Пример #1
0
def all(username):
    weibo_list = Weibo.find_all(username=username)
    if weibo_list is not None:
        weibos = Weibo.all_json(weibo_list)
    else:
        weibos = None
    return jsonify(weibos)
Пример #2
0
def delete(request):
    weibo_id = int(request.query['weibo_id'])
    Weibo.delete(weibo_id)
    comments = Comment.all(weibo_id=weibo_id)
    for comment in comments:
        Comment.delete(comment.id)
    return redirect('/weibo')
Пример #3
0
def weibo_index(request):
    u = current_user(request)
    res_u = request.query.get('user_id', '')
    if res_u != '':
        weibos = Weibo.all(user_id=int(res_u))
    else:
        weibos = Weibo.all(user_id=u.id)
    return html_response('weibo_index.html', weibos=weibos, user=u, res=res_u)
Пример #4
0
def delete():
    weibo_id = int(request.args.get('id'))
    w = Weibo.remove(weibo_id)
    comments = Comment.find_all(weibo_id=weibo_id)
    for comment in comments:
        Comment.remove(comment.id)
    return jsonify(w.json())
Пример #5
0
def index(request):
    user_id = request.query.get('user_id', -1)
    user_id = int(user_id)
    log('user_id', user_id)
    user = User.find(user_id)
    if user is None:
        return redirect('/login')
    weibos = Weibo.find_all(user_id=user_id)
    body = templates('weibo_index.html', weibos=weibos, user=user)
    return http_response(body)
Пример #6
0
	def decorated_function(*args, **kwargs):
		u = current_user()
		model_name = request.path.split('/')[-2]
		# 根据不同请求方法,获取实例的 id
		if request.method == 'POST':
			data = request.json
			id = int(data.get('id'))
		else:
			id = int(request.args.get('id'))
		# 根据 model 的名字,判断从哪里获取实例
		path_dict = dict(
			weibo=Weibo.find_by(id=id),
			comment=Comment.find_by(id=id),
			blog=Blog.find_by(id=id),
			blogComment=BlogComment.find_by(id=id),
		)
		instance = path_dict.get(model_name)
		user_id = instance.user_id
		# 检查登录用户 id 与实例的 user_id 是否一致
		if u.id == user_id:
			return f(*args, **kwargs)
		else:
			log("{} try to access {}'s data\r\n".format(u.username, instance.username))
			return redirect('#')
Пример #7
0
def update():
    data = request.json
    weibo_id = int(data.get('id', -1))
    w = Weibo.update(weibo_id, data)
    return jsonify(w.json())
Пример #8
0
def add():
    data = request.json
    data['user_id'] = current_user().id
    data['username'] = current_user().username
    w = Weibo.new(data)
    return jsonify(w.json())
Пример #9
0
def update(request):
    form = request.form()
    Weibo.update_weibo(form)
    return redirect('/weibo')
Пример #10
0
def edit(request):
    weibo_id = int(request.query['weibo_id'])
    weibo = Weibo.one(id=weibo_id)
    return html_response('weibo_edit.html', weibo=weibo)
Пример #11
0
def add(request):
    form = request.form()
    u = current_user(request)
    Weibo.add(u.id, form)
    return redirect('/weibo')
Пример #12
0
def add_weibo(request):
    form = request.json()
    m = Weibo.new(form)
    return json_response(m.json())
Пример #13
0
def all_weibos(request):
    ms = Weibo.all()
    data = [m.json() for m in ms]
    return json_response(data)