You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
3.3 KiB
Python
182 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
|
|
from sqlalchemy import text
|
|
from website import errors
|
|
from website import settings
|
|
from website import consts
|
|
from website import db
|
|
from website.util import shortuuid, aes
|
|
from website.handler import APIHandler, authenticated
|
|
|
|
|
|
class ClassificationAddHandler(APIHandler):
|
|
"""
|
|
添加模型分类
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
name = self.get_escaped_argument("name", "")
|
|
if not name:
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
|
|
if len(name) > 128:
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "分类名称过长")
|
|
|
|
with self.app_mysql.connect() as conn:
|
|
cur = conn.execute(text("select id from model_classification where name=:name"), name=name)
|
|
classification_id = cur.fetchone()[0]
|
|
if classification_id:
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "分类名称重复")
|
|
|
|
conn.execute(text("""
|
|
insert into model_classification (name, created_at) values (:name, NOW())"""),
|
|
name=name)
|
|
conn.commit()
|
|
|
|
self.finish()
|
|
|
|
|
|
class ClassificationListHandler(APIHandler):
|
|
"""
|
|
模型分类列表
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
with self.app_mysql.connect() as conn:
|
|
cur = conn.execute(text("""
|
|
select id, name from model_classification"""))
|
|
result = db.to_json_list(cur)
|
|
|
|
self.finish({"data": result})
|
|
|
|
|
|
class ClassificationDeleteHandler(APIHandler):
|
|
"""
|
|
删除模型分类
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
classification_id = self.get_int_argument("id")
|
|
if not classification_id:
|
|
raise errors.HTTPAPIError(errors.ERROR_BAD_REQUEST, "参数缺失")
|
|
with self.app_mysql.connect() as conn:
|
|
conn.execute(text("""
|
|
DELETE FROM model_classification WHERE id=:id"""),
|
|
id=classification_id)
|
|
|
|
self.finish()
|
|
|
|
|
|
class ListHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class AddHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class EditHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class InfoHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class DeleteHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionAddHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionEditHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionListHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionInfoHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionSetDefaultHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|
|
|
|
|
|
class VersionDeleteHandler(APIHandler):
|
|
"""
|
|
|
|
"""
|
|
|
|
@authenticated
|
|
def post(self):
|
|
self.finish()
|