Example #1
0
def complex_query():
    # rs = db.session.query(Todo.todo_type, func.sum(Todo.todo_time)).filter(
    #     and_(Todo.todo_date >= "2015-12-04", Todo.todo_date <= "2015-12-04",
    #          Todo.todo_status == Todo.STATUS_DONE)).all()
    # print rs
    #
    # type_dict = {
    #     "0": "计划",
    #     "1": "紧急",
    #     "2": "优先",
    #     "3": "普通",
    # }
    # print rs
    # json_list = list()
    # for row in rs:
    #     if row[0] is None:
    #         continue
    #     json_dict = dict()
    #     json_dict['value'] = long(row[1] or 0)
    #     json_dict['name'] = type_dict[str(row[0])]
    #     json_list.append(json_dict)
    # print json_list
    _todos = (
        Todo.query.search_date(timeutils.today(), timeutils.today())
        .filter(Todo.todo_status == Todo.STATUS_NOT_DONE)
        .sort_by_type()
        .all()
    )
    print len(_todos)
Example #2
0
def dashboard_main():
    if not mem_cache.get('month_finish_plan'):
        month_finish_plan = db.session.query(func.count(Plan.id)).filter(
            and_(Plan.plan_end_date >= timeutils.get_firstday_month(),
                 Plan.plan_end_date <= timeutils.get_lastday_month(),
                 Plan.plan_status == Plan.STATUS_FINISH)).scalar()
        mem_cache.set("month_finish_plan", month_finish_plan)

    if not mem_cache.get('progress_plan'):
        progress_plan = db.session.query(func.count(Plan.id)).filter(
            Plan.plan_status == Plan.STATUS_PROGRESS).scalar()
        mem_cache.set("progress_plan", progress_plan)

    if not mem_cache.get('post_count'):
        post_count = db.session.query(func.count(Post.id)).scalar()
        mem_cache.set("post_count", post_count)

    if not mem_cache.get('img_count'):
        img_count = db.session.query(func.count(Image.id)).scalar()
        mem_cache.set("img_count", img_count)
    overview_data = {
        'progress_plan': mem_cache.get("progress_plan"),
        'month_finish_plan': mem_cache.get("month_finish_plan"),
        'post_count': mem_cache.get("post_count"),
        'img_count': mem_cache.get("img_count"),
    }
    type_dict = {
        Todo.TYPE_PLAN: "计划",
        Todo.TYPE_URGENT: "紧急",
        Todo.TYPE_PRIOR: "优先",
        Todo.TYPE_NORMAL: "普通", }
    type_style = {
        Todo.TYPE_PLAN: "label-success",
        Todo.TYPE_URGENT: "label-danger",
        Todo.TYPE_PRIOR: "label-primary",
        Todo.TYPE_NORMAL: "label-default", }
    _todos = Todo.query.search_date(timeutils.today(), timeutils.today()).filter(
        Todo.todo_status == Todo.STATUS_NOT_DONE).sort_by_type().all()
    _completeds = Todo.query.search_date(timeutils.today(), timeutils.today()).filter(
        Todo.todo_status == Todo.STATUS_DONE).sort_by_type().all()
    return render_template('admin/dashboard.html', todos=_todos, completeds=_completeds, type_dict=type_dict,
                           type_style=type_style, overview_data=overview_data)
Example #3
0
 def plan_remain_day(self):
     if self.plan_status != Plan.STATUS_PROGRESS or self.plan_start_date is None or self.plan_day is None:
         return 0
     remain_day = self.plan_day - (timeutils.today() - self.plan_start_date).days
     return remain_day