Exemplo n.º 1
0
def all():
    u = current_user()
    todos = Ajaxtodo.find_all_json(user_id=u.id)
    for t in todos:
        t['ct'] = formatted_time(t['created_time'])
        t['ut'] = formatted_time(t['updated_time'])
    return jsonify(todos)
Exemplo n.º 2
0
 def new(cls, form):
     m = super().new(form)
     t = int(time.time())
     m.created_time = formatted_time(t)
     m.updated_time = formatted_time(t)
     m.save()
     return m
Exemplo n.º 3
0
def add():
    form = request.json
    u = current_user()
    t = Ajaxtodo.add(form, user_id=u.id)
    t = t.json()
    t['ct'] = formatted_time(t['created_time'])
    t['ut'] = formatted_time(t['updated_time'])
    return jsonify(t)
Exemplo n.º 4
0
 def __init__(self, form):
     super().__init__(form)
     self.task = form.get('task', '')
     self.completed = False
     # 和别的数据关联的方式, 用 user_id 表明拥有它的 user 实例
     # 默认不关联任何用户
     self.user_id = form.get('user_id', -1)
     self.created_time = formatted_time(
         form.get('created_time', int(time.time())))
     self.updated_time = formatted_time(
         form.get('updated_time', int(time.time())))
Exemplo n.º 5
0
def get_article_link(begin, publisher, fakeid):
    url = article_list_url(begin, fakeid)
    # 获取json响应
    r = requests.get(url, headers=headers.get_cookie())
    # json转化为字典
    d = json.loads(r.content)
    log('d', type(d), d)
    app_msg_list = d['app_msg_list']
    # log('app-msg-list', app_msg_list)
    articles = []
    # 查询条目是否已经在数据库中,不在则插入,存在则更新
    for item in app_msg_list:
        # 转义不能用在文件名里的非法字符
        item['title'] = validate_title(item['title'])
        # 文件名为时间+标题+html
        time_prefix = formatted_time(item['create_time']).split(' ', 1)[0].replace('/', '')
        item['filename'] = time_prefix + '-' + item['title']
        item['publisher'] = publisher
        a = Article.one(aid=item['aid'])
        if a is None:
            a = Article.new(item)
        else:
            a.update(a.id, **item)
            break

        articles.append(a)
        # 返回article对象的列表
    return articles
Exemplo n.º 6
0
 def __init__(self, form):
     self.id = form.get('id', None)
     self.title = form.get('title', '')
     self.user_id = int(form.get('user_id', -1))
     # 还应该增加 时间 等数据
     self.created_time = form.get('created_time', formatted_time())
     self.update_time = form.get('update_time', self.created_time)
Exemplo n.º 7
0
 def valid_names(cls):
     names = super().valid_names()
     names = names + [
         ('content', str, ''),
         ('topic_id', str, 0),
         ('user_id', str, 0),
         ('ct', str, formatted_time(int(time.time()))),
     ]
     return names
Exemplo n.º 8
0
    def valid_names(cls):
        names = super().valid_names()
        names = names + [
            ('username', str, ''),
            ('password', str, ''),
            ('user_image', str, '/uploads/default.png'),
            ('signature', str, '这家伙很懒,什么个性签名都没有留下'),
            ('ct', str, formatted_time(int(time.time()))),

        ]
        return names
Exemplo n.º 9
0
 def update(cls, id, form):
     t = cls.find(id)
     valid_names = [
         'task',
     ]
     for key in form:
         if key in valid_names:
             setattr(t, key, form[key])
     t.updated_time = formatted_time(int(time.time()))
     t.save()
     return t
Exemplo n.º 10
0
 def valid_names(cls):
     names = super().valid_names()
     names = names + [
         ('views', int, 0),
         ('title', str, ''),
         ('content', str, ''),
         ('user_id', str, 0),
         ('board_id', str, 0),
         ('ct', str, formatted_time(int(time.time()))),
     ]
     return names
Exemplo n.º 11
0
def detail(id):
    """
    话题详情页面
    """
    c_u = current_user()
    m = Topic.find(id)
    topic_created_time = formatted_time(m.created_time)
    token = new_csrf_token()
    # 5 个最近无人回复的话题
    ts = Topic.topic_noreply()
    return render_template(
        "topic/detail.html",
        current_user=c_u,
        topic=m,
        ts=ts,
        topic_created_time=topic_created_time,
        token=token,
    )
Exemplo n.º 12
0
def update(request):
    """
    用于增加新 todo 的路由函数
    """
    # uname = current_user(request)
    # u = User.find_by(username=uname)
    # if u is None:
    #     return redirect('/login')
    if request.method == 'POST':
        # 修改并且保存 todo
        form = request.form()
        print('debug update', form)
        todo_id = int(form.get('id', -1))
        t = Todo.find_by(id=todo_id)
        t.title = form.get('title', t.title)
        t.update_time = formatted_time()
        t.save()
    # 浏览器发送数据过来被处理后, 重定向到首页
    # 浏览器在请求新首页的时候, 就能看到新增的数据了
    return redirect('/todo')
Exemplo n.º 13
0
Arquivo: user.py Projeto: snzhaoch/bbs
def user_detail(username):
    """
    用户详情页面
    """
    u = User.find_by(username=username)
    c_u = current_user()
    if u is None:
        abort(404)
    else:
        user_created_time = formatted_time(u.created_time)
        # 5 个最近创建的话题
        topics_after = Topic.find_lss(5, 0, -1, user_id=u.id)
        # 5 个最近参与的话题
        replys_after = Reply.find_lss(5, 0, -1, user_id=u.id)
        replys_topic = []
        topic_ids = []
        for v in replys_after:
            topic_id = v.topic_id
            if topic_id in topic_ids:
                continue
            else:
                t = Topic.find_by(id=v.topic_id)
                # 下面这个 if else 是因为删除 topic 时未删除 对应的 reply,
                # 导致 t 有为 None 的情况,项目完成初始化 mongodb 时可以去掉
                if t is not None:
                    replys_topic.append(t)
                    topic_ids.append(topic_id)
                else:
                    continue
        # 5 个最近无人回复的话题
        ts = Topic.topic_noreply()
        return render_template(
            '/user/profile.html',
            user=u,
            current_user=c_u,
            user_created_time=user_created_time,
            topics=topics_after,
            ts=ts,
            replys_topic=replys_topic
        )
Exemplo n.º 14
0
 def updated_time_formatted(self):
     return formatted_time(self.updated_time)
Exemplo n.º 15
0
 def created_time_formatted(self):
     return formatted_time(self.created_time)
Exemplo n.º 16
0
 def formatted_updated_time(self):
     return formatted_time(self.updated_time)
Exemplo n.º 17
0
 def formatted_created_time(self):
     return formatted_time(self.created_time)
Exemplo n.º 18
0
def update():
    form = request.json
    t = Ajaxtodo.update(form)
    t = t.json()
    t['ut'] = formatted_time(t['updated_time'])
    return jsonify(t)