def get(cls, user: User, pid=None): # 若不传 pid 参数,获取该用户所有 Project if pid is None: return cls._getProjects(user) # 否则,获取指定 pid 的 Project pid = InterfaceManager.convertDataType(pid, 'int') return cls._getProject(user, pid)
def edit(cls, user: User, tid, name, desc, parent_id, prev_ids, auto_adjust, progress, start_date, duration=0, end_date=None, status_id=None, prev_order_id=None): # 参数处理 # 如果有 status_id 参数,判断格式 if status_id is not None: cls.Check.ensureStatusFormat(status_id) # 如果有 end_date 参数,直接解析使用 if end_date is not None: end_date = InterfaceManager.convertDataType(end_date, 'date') # 否则,根据 duration 计算一个 end_date else: delta = datetime.timedelta(duration) end_date = start_date + delta # 参数校验 cls.Check.ensureNameFormat(name) cls.Check.ensureDescFormat(desc) cls.Check.ensureDurationFormat(duration) cls.Check.ensureEndDateFormat(start_date, end_date) cls.Common.ensureTaskExist(id=parent_id) for prev_id in prev_ids: cls.Common.ensureTaskExist(id=prev_id) # 校验 & 获取必要数据 task = cls.Common.getTask(id=tid) project = task.project # 确保项目经理权限 ProjectView.Common.ensureProjectManager(user.id, project.id) prev_order = None if prev_order_id is not None: prev_order = cls.Common.getTask(id=prev_order_id, project_id=task.project_id) # 修改任务 project.editTask(task, name, desc, parent_id, prev_ids, auto_adjust, progress, start_date, end_date, status_id, prev_order)
def get(cls, user: User, pid=None): if pid is None: tasks = ModelUtils.getObjectRelatedForAll(user.tasktake_set, 'task') else: pid = InterfaceManager.convertDataType(pid, 'int') proj = ProjectView.Common.getProject(id=pid) tasks = proj.tasks(True) return {'tasks': ModelUtils.objectsToDict(tasks, type='detail')}
def add(cls, user: User, pid, name, desc, parent_id, prev_ids, auto_adjust, start_date, duration=0, end_date=None, prev_order_id=None): # 参数处理 # 如果有 end_date 参数,直接解析使用 if end_date is not None: end_date = InterfaceManager.convertDataType(end_date, 'date') # 否则,根据 duration 计算一个 end_date else: delta = datetime.timedelta(duration) end_date = start_date + delta # 参数校验 cls.Check.ensureNameFormat(name) cls.Check.ensureDescFormat(desc) cls.Check.ensureDurationFormat(duration) cls.Check.ensureEndDateFormat(start_date, end_date) cls.Common.ensureTaskExist(id=parent_id) for prev_id in prev_ids: cls.Common.ensureTaskExist(id=prev_id) ProjectView.Common.ensureProjectManager(user.id, pid) # 校验 & 获取必要数据 proj = ProjectView.Common.getProject(id=pid) prev_order = None if prev_order_id is not None: prev_order = cls.Common.getTask(id=prev_order_id, project=proj) # 添加任务 proj.addTask(name, desc, parent_id, prev_ids, auto_adjust, start_date, end_date, prev_order)
from .views import DataManager from utils.interface_manager import InterfaceManager Interfaces = { 'data': { # 接收POST数据(字段名,数据类型) 'GET': [], # 逻辑处理函数 'func': DataManager.getSystemData }, } urlpatterns = InterfaceManager.generateUrlPatterns(Interfaces)