Пример #1
0
def user_detail_article(dbServ: DbServ,
                        dirServ: DirServ,
                        majorServ: MajorServ,
                        articleKey: str = ''):
    if articleKey:
        article_vo = dbServ.mapper(ArticleVo).and_equal({
            'articleKey':
            articleKey
        }).select_first()
    else:
        article_vo = dbServ.mapper(ArticleVo).order_by(
            'majorPosition,dirPosition,posInDir').select_first()
    assert article_vo, '文章不存在'
    return {
        'article':
        article_vo,
        'dirIndex':
        dirServ.make_dir_index(article_vo.majorId, article_vo.articleId),
        'majorIndex':
        majorServ.make_major_index(article_vo.majorId),
        'config': {
            'site_name': Config.site_name,
            'ga_id': Config.ga_id,
            'icp_beian': Config.icp_beian,
        },
    }
Пример #2
0
def admin_edit_dir(dbServ: DbServ, dirId: int, dirName: str, majorId: int,
                   position: int):
    directory = Directory()
    directory.dirName = dirName
    directory.majorId = majorId
    directory.position = position
    dbServ.mapper(Directory).by_id(dirId).update(directory)
    return {}
Пример #3
0
def admin_create_dir(dbServ: DbServ, dirName: str, majorId: int,
                     position: int) -> Directory:
    directory = Directory()
    directory.dirName = dirName
    directory.majorId = majorId
    directory.position = position
    directory.createdAt = int(time.time())
    dbServ.mapper(Directory).insert(directory)
    return directory
Пример #4
0
def admin_edit_major(
        dbServ: DbServ,
        majorId: int,
        majorName: str,
        gitUrl: str,
        position: int):
    major = Major()
    major.majorName = majorName
    major.gitUrl = gitUrl
    major.position = position
    dbServ.mapper(Major).by_id(majorId).update(major)
    return {}
Пример #5
0
def admin_create_major(
        dbServ: DbServ,
        majorName: str,
        gitUrl: str,
        position: int) -> Major:
    major = Major()
    major.majorName = majorName
    major.gitUrl = gitUrl
    major.position = position
    major.createdAt = int(time.time())
    dbServ.mapper(Major).insert(major)
    return major
Пример #6
0
def admin_create_article(
    dbServ: DbServ,
    majorServ: MajorServ,
    articleKey: str,
    title: str,
    contentMd: str,
    dirId: int,
    posInDir: int,
):
    contentHtml = markdownlib.parse(contentMd)
    article = Article()
    article.articleKey = articleKey
    article.title = title
    article.contentMd = contentMd
    article.contentHtml = contentHtml
    article.dirId = dirId
    article.posInDir = posInDir
    article.createdAt = article.updatedAt = int(time.time())
    dbServ.mapper(Article).insert(article)
    majorServ.update_first_article()
    return {}
Пример #7
0
def admin_delete_major(dbServ: DbServ, majorId: int):
    total = dbServ.mapper(Directory).and_equal({'majorId': majorId}).select_count()
    assert total == 0, '不能删除非空的专栏,请先删除目录'
    dbServ.mapper(Major).by_id(majorId).delete()
    return {}
Пример #8
0
def admin_detail_major(dbServ: DbServ, majorId: int) -> Optional[Major]:
    return dbServ.mapper(Major).by_id(majorId).select_first()
Пример #9
0
def admin_list_major(dbServ: DbServ) -> List[Major]:
    return dbServ.mapper(Major).order_by('position').select()
Пример #10
0
def admin_delete_dir(dbServ: DbServ, dirId: int):
    total = dbServ.mapper(Article).and_equal({'dirId': dirId}).select_count()
    assert total == 0, '不能删除非空的目录,请先删除文章'
    dbServ.mapper(Directory).by_id(dirId).delete()
    return {}
Пример #11
0
def admin_detail_dir(dbServ: DbServ, dirId: int) -> Optional[Directory]:
    return dbServ.mapper(Directory).by_id(dirId).select_first()
Пример #12
0
def admin_list_dir(dbServ: DbServ) -> List[DirectoryVo]:
    return dbServ.mapper(DirectoryVo).order_by(
        'majorPosition,position').select()
Пример #13
0
def admin_list_article(dbServ: DbServ) -> List[ArticleVo]:
    return dbServ.mapper(ArticleVo).order_by(
        'majorPosition,dirPosition,posInDir').select()
Пример #14
0
def admin_detail_article(dbServ: DbServ,
                         articleId: int) -> Optional[ArticleVo]:
    return dbServ.mapper(ArticleVo).by_id(articleId).select_first()
Пример #15
0
def admin_delete_article(dbServ: DbServ, articleId: int):
    dbServ.mapper(Article).by_id(articleId).delete()
    return {}