Exemplo n.º 1
0
def index():
    return render_template(
        'index.html',
        now_time=main_parse.welcome_home(),
        projects=ProjectModel.get_all_projects_bydict(),
        articles=ArticleModel.get_all_acricles_bydict(),
        sidebar_project=ProjectModel.get_all_projects_bytree())
Exemplo n.º 2
0
 def post(self, **kwargs: dict[str, Any]) -> dict[str, Any]:
     data = ProjectModel(**kwargs)
     db.session.add(data)
     db.session.commit()
     return {
         'data': [data.to_dict()],
         'message': {
             'text': 'Posted Successfully!!',
             'priority': 'success'
         }
     }
Exemplo n.º 3
0
    def post(cls):
        data = _user_parser.parse_args()
        if ProjectModel.find_by_name(data['name']):
            return {'message': "项目名称 '{}' 已存在。".format(data['name'])}, 400

        store = ProjectModel(
            data['name'],
            data['icon'] if data['icon'] is not None else 'fa-newspaper-o',
            data['introduce'], data['article_url'], data['weight'])
        try:
            store.save_to_db()
            ArticleModel.insert_link_article(store)
        except:
            return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500

        return {"message": "新建项目成功!"}, 201
Exemplo n.º 4
0
def articles(topic):
    article = ArticleModel.find_by_id(topic)
    if article:
        project = ProjectModel.find_by_id(article.link_project)
        articles_list = project.get_all_article(None)
        content = ContentModel.find_by_id(article.id)
        if content:
            article_content = content.content_HTML
        else:
            article_content = None
    else:
        abort(404)
    return render_template(
        'generic.html',
        article_id=topic,
        articles={
            "articles_len": len(articles_list['articles']),
            "articles": articles_list['articles'],
            "article_content": article_content,
            "article_name": article.topic
        },
        sidebar_project=ProjectModel.get_all_projects_bytree())
Exemplo n.º 5
0
def query_item(whereitem, wherestr):
    sidebar_article = ArticleModel.get_all_acricles_bytree(whereitem, wherestr)
    sidebar_feature = FeatureModel.get_all_feature_bytree(whereitem, wherestr)
    count_article = sum(len(link['link_articles']) for link in sidebar_article)
    count_feature = sum(len(link['link_features']) for link in sidebar_feature)
    print(sidebar_article, sidebar_feature)
    return render_template(
        'elements.html',
        whereitem=main_parse.querystr(whereitem, wherestr),
        sidebar_article=sidebar_article,
        sidebar_feature=sidebar_feature,
        count_article=count_article,
        count_feature=count_feature,
        sidebar_project=ProjectModel.get_all_projects_bytree())
Exemplo n.º 6
0
def querystr(whereitem, wherestr):
    '''
    转置查询条件为可读,目前有:
    case whereitem:
    when link_project:主题:project_name
    when link_date:时间:xx年xx月
    otherwise:内容包含:xxxxx
    '''
    if whereitem == 'link_project':
        return "主题:" + ProjectModel.find_by_id(wherestr).name
    elif whereitem == 'link_date':
        return "时间:" + wherestr[2:4] + "年" + wherestr[5:7] + "月"
    else:
        return "内容包含:" + wherestr
Exemplo n.º 7
0
    def put(cls):
        data = _user_parser.parse_args()
        store = ProjectModel.find_by_name(data['name'])
        if store:
            store.icon = data['icon'] if data[
                'icon'] is not None else store.icon
            store.introduce = data['introduce'] if data[
                'introduce'] is not None else store.introduce
            store.article_url = data['article_url'] if data[
                'article_url'] is not None else store.article_url
            store.weight = data['weight'] if data[
                'weight'] is not None else store.weight
        else:
            store = ProjectModel(
                data['name'],
                data['icon'] if data['icon'] is not None else 'fa-newspaper-o',
                data['introduce'], data['article_url'], data['weight'])
        try:
            store.save_to_db()
            ArticleModel.insert_link_article(store)
        except:
            return {"message": "后台数据处理发生异常,请联系网站管理员。"}, 500

        return {"store": store.json(), "message": "更新/新增项目状态成功!"}, 201
Exemplo n.º 8
0
def elements():
    return render_template(
        'elements_copy.html',
        sidebar_project=ProjectModel.get_all_projects_bytree())