Exemple #1
0
def show(id):
    m = Model.query.get(id)
    ts = Tag.query.all()
    if current_user():
        u = current_user()
        uid = u.id
    else:
        uid = 0
    return render_template('blog.html', blog=m, tag_list=ts, uid=uid)
Exemple #2
0
def new():
    print('blog new was called')
    u = current_user()
    if u is not None:
        return render_template('blog_add.html')
    else:
        return redirect(url_for('user.login_view'))
Exemple #3
0
def add_comment():
    form = request.form
    # print('ajax发过来的内容是:{}'.format(form))
    u = current_user()
    c = Model(form)
    c.user_id = u.id
    c.topic_id = form.get('topic_id')
    r = {'data': []}
    if c.valid():
        c.save()
        r['success'] = True
        data = c.json()
        u = User.query.get(c.user_id)
        t = Topic.query.get(c.topic_id)
        # print('topic', t.title)
        data['user'] = u.username
        data['avatar'] = u.avatar
        data['comments_num'] = len(t.comments)
        data['topic_id'] = c.topic_id
        r['data'] = data
        # print('new comment', r)
    else:
        r['success'] = False
        message = c.error_message()
        r['message'] = message
        # print('new topic failure', r)
    return json.dumps(r, ensure_ascii=False)
Exemple #4
0
def add():
    u = current_user()
    form = request.form
    m = Model.new(form)
    m.user_id = u.id
    m.save()
    return redirect(url_for('.index'))
Exemple #5
0
def index():
    u = current_user()
    if u.id == 1:
        ms = Model.query.all()
        return render_template('node_index.html', node_list=ms)
    else:
        abort(404)
Exemple #6
0
def update(weibo_id):
    print('1234')
    form = request.form
    w = Weibo.query.get(weibo_id)
    u = current_user()
    t = Weibo(form)
    print('debug', w.weibo, '1', t.weibo, '2', t.name, '3', u.username, '4',
          w.name, '5')
    r = {'data': []}
    if w.name == u.username:
        print('233')
        if t.valid():
            w.weibo = t.weibo
            w.save()
            r['success'] = True
            r['data'] = t.json()
            print('3344')
        else:
            r['success'] = False
            message = t.error_message()
            r['message'] = message
            print('4455')
    else:
        print('332')
        r['success'] = False
        r['message'] = '暗搓搓的改别人微博你这价值观有问题啊'
    return json.dumps(r, ensure_ascii=False)
Exemple #7
0
def index():
    # print("enter task index")
    u = current_user()
    ms = Model.query.filter_by(user_id=u.id).all()
    # print(u, ms)
    # ms = Model.query.all()
    weeks, m, y = cal_list()
    # format_weeks = list(map())

    format_weeks = []
    for w in weeks:
        if w != 0 and int(w) < 10:
            w = '{0}-{1}-0{2}'.format(y, m, str(w))
            format_weeks.append(w)
        elif w != 0:
            w = '{0}-{1}-{2}'.format(y, m, str(w))
            format_weeks.append(w)

    sl_dict = dict()
    sum_dict = dict()
    achieved_dict = dict()
    sum_values = []
    if ms:
        for m in ms:
            sl = json.loads(m.status_list)
            status_list_dict = dict()
            sld = status_list_dict
            sls = []
            for fw in format_weeks:
                if fw in sl.keys():
                    sld[fw] = sl[fw]
                    sls.append(sl[fw])
                else:
                    sld[fw] = 0
                    sls.append(0)
            sl_dict[m.id] = sls
            print("sls", sls)
            sum_dict[m.id] = sum(sls)
            achieved_dict[m.id] = int(int(m.aim) * len(weeks) * 4 / 7)
            print("in sys", sl_dict)
        print("out sys", sl_dict)

        ss = sl_dict
        sum_values = sum_lists(list(ss.values()))
        print("out sys", sl_dict)

    print("sl_dict", sl_dict)
    # sl_dict = json.dumps(sl_dict)
    # print(sl_dict)
    # fw = list(map(lambda x: x[5:], format_weeks))
    return render_template(
        'task/indexx.html',
        task_list=ms,
        sum_values=sum_values,
        user=u,
        weeks=format_weeks,
        status_lists=sl_dict,
        achieved_dict=achieved_dict,
        sum_dict=sum_dict)
Exemple #8
0
def admin_required():
    u = current_user()
    if u is None:
        abort(404)
    if u.id == 1:
        return True
    else:
        return False
Exemple #9
0
def add():
    form = request.form
    m = Model(form)
    m.user_id = current_user().id
    m.tag_id = int(form.get('tag_id'))
    # m.tag_id = Tag.query.filter_by(name=tag).first()
    m.save()
    return redirect(url_for('blog.show', id=m.id))
Exemple #10
0
def index(page):
    # ms = Model.query.all()
    pagination = Model.query.order_by(Blog.created_time.desc()).paginate(
        page, PER_PAGE, False)
    total = pagination.total / PER_PAGE
    total = int(math.ceil(total))
    ts = Tag.query.all()
    if current_user():
        u = current_user()
        uid = u.id
    else:
        uid = 0
    return render_template('blog_index.html',
                           pagination=pagination,
                           total=total,
                           tag_list=ts,
                           uid=uid)
Exemple #11
0
def delete(id):
    t = Model.query.get(id)
    # 单个话题没了的话肯定是返回到该用户的所有话题页面
    # 但是呢,对应用户删除对应用户的文章,不可越界
    t.delete()
    u = current_user()
    topics = u.topics
    return redirect(url_for('user.topics'))
Exemple #12
0
def comment():
    form = request.form
    u = current_user()
    c = Comment(form)
    c.name = u.username
    if c.valid():
        c.save()
    return redirect(url_for('.index'))
Exemple #13
0
def index():
    # cs = Comment.query.all()
    # us = User.query.all()
    u = current_user()
    if u is not None:
        return redirect(url_for('task.index'))
    else:
        return redirect(url_for('user.index'))
Exemple #14
0
def add():
    print('node add was called')
    form = request.form
    m = Model(form)
    u = current_user()
    m.user_id = u.id
    m.save()
    return redirect(url_for('.index'))
Exemple #15
0
def show(id):
    m = Model.query.get(id)
    u = current_user()
    node_topics_num = len(m.topics)
    return render_template('node.html',
                           node=m,
                           user=u,
                           topics_num=node_topics_num)
Exemple #16
0
def comment():
    form = request.form
    u = current_user()
    c = BlogComment(form)
    c.name = u.username
    if c.valid():
        c.save()
    c.avatar = c.get_avatar()
    return c.json()
Exemple #17
0
def add():
    form = request.form
    u = current_user()
    t = Weibo(form)
    t.name = u.username
    if t.valid():
        t.save()
    # 蓝图中的 url_for 需要加上蓝图的名字,这里是 todo
    return redirect(url_for('.index'))
Exemple #18
0
def delete(todo_id):
    u = current_user()
    if u is not None:
        t = Todo.query.get(todo_id)
        t.user_id = u.id
        t.delete()
    else:
        abort(404)
    return redirect(url_for('todo.index', username=u.username))
Exemple #19
0
def add():
    form = request.form
    u = current_user()
    b = Blog(form)
    b.name = '3000'
    if b.valid():
        b.save()
    # 蓝图中的 url_for 需要加上蓝图的名字,这里是 todo
    return redirect(url_for('.index'))
Exemple #20
0
 def function(*args, **kwargs):
     # your code
     print('admin required')
     u = current_user()
     if u.is_administrator:
         print('current user is administrator')
     else:
         print('current user is not administrator')
         abort(410)
Exemple #21
0
def comment():
    form = request.form
    u = current_user()
    c = WeiboComment(form)
    c.name = u.username
    c.user_id = u.id
    # c.weibo_id =
    if c.valid():
        c.save()
    return redirect(url_for('.index'))
Exemple #22
0
def add():
    print('topic.add was called')
    form = request.form
    t = Model(form)
    u = current_user()
    t.node_id = int(form.get('node_id'))
    t.user_id = u.id
    t.save()
    print('topic', t)
    return redirect(url_for('.index', id=t.id))
Exemple #23
0
def add():
    u = current_user()
    if u is not None:
        t = Todo(request.form)
        t.user_id = u.id
        if t.validate_todo():
            t.save()
    else:
        abort(404)
    return redirect(url_for('.index', username=u.username))
Exemple #24
0
def new():
    print('node.new was called')
    u = current_user()
    print('u.is_administrator', u.is_administrator)
    if u.is_administrator:
        print('current user is administrator')
    else:
        print('current user is not administrator')
        abort(410)
    return render_template('node_new.html')
Exemple #25
0
def index():
    u = current_user()
    if u is None:
        return redirect(url_for('user.login_view'))
    blogs = Blog.query.order_by(Blog.id.desc()).all()
    for i in blogs:
        i.comment = i.comments()
        for j in i.comment:
            j.avatar = j.get_avatar()
        i.comments_num = len(i.comment)
    return render_template('blog_index.html', blogs=blogs)
Exemple #26
0
def index():
    u = current_user()
    if u is None:
        abort(404)
    weibo_list = Weibo.query.order_by(Weibo.id.desc()).all()
    for w in weibo_list:
        w.comment = w.comments()
        for i in w.comment:
            i.avatar = i.get_avatar()
        w.comments_num = len(w.comment)
        w.avatar = w.get_avatar()
    return render_template('weibo_index.html', weibos=weibo_list)
Exemple #27
0
def weibo_comment_add():
    #form = request.form
    form = request.get_json()
    c = Comment(form)
    u = current_user()
    c.name = u.username
    print('form', form)
    if c.valid():
        c.save()
        return api_response(True, data=c.json())
    else:
        return api_response(False, message=c.error_message())
Exemple #28
0
def comment():
    print('blog.comment was called ')
    u = current_user()
    if u is not None:
        form = request.form
        c = BlogComment(form)
        c.name = u.username
        if c.valid():
            c.save()

            print('blogcomment was saved',c)
    # c.avatar = c.get_avatar()
    return c.json()
Exemple #29
0
def weibo_add():
    #form = request.form
    print('weiboadd')
    form = request.get_json()
    print('form', form)
    w = Weibo(form)
    u = current_user()
    w.name = u.username
    print('form', form)
    if w.valid():
        w.save()
        return api_response(True, data=w.json())
    else:
        return api_response(False, message=w.error_message())
Exemple #30
0
def delete(weibo_id):
    u = current_user()
    w = Weibo.query.get(weibo_id)
    print(w)
    if w.name == u.username:
        w.remove()
        r = {
            'success': True,
            'data': w.json(),
        }
    else:
        r = {
            'success': False,
            'data': w.json(),
        }
    return json.dumps(r, ensure_ascii=False)
Exemple #31
0
def new():
    u = current_user()
    ns = Node.query.all()
    return render_template('topic/new.html', c_user=u, nodes=ns)
Exemple #32
0
 def function(*args, **kwargs):
     # print('admin required')
     if current_user().id != 1:
         # print('not admin')
         abort(404)
     return f(*args, **kwargs)
Exemple #33
0
def config():
    cu = current_user()
    ns = Model.query.all()
    return render_template('node/config.html', c_user=cu , nodes=ns)
Exemple #34
0
def show(id):
    u = current_user()
    m = Model.query.get(id)
    return render_template('node/show.html', c_user=u, node=m)