def getSystemData(cls): data = {} data['Educations'] = cls.convertTuplesToDict(User.USER_EDUCATIONS) data['LoginStatuses'] = cls.convertTuplesToDict(User.USER_STATUSES) data['ProjectTypes'] = cls.convertTuplesToDict(Project.PROJECT_TYPES) data['TaskStatuses'] = cls.convertTuplesToDict(Task.TASK_STATUSES) data['TaskLevels'] = cls.convertTuplesToDict(Task.TASK_LEVELS) data['Roles'] = ViewUtils.getObjects(Role, return_type='dict') data['ProjectManagerRoleId'] = Role.ProjectManagerId data['OfflineStatusID'] = UserStatus.Offline.value data['OnlineStatusID'] = UserStatus.Online.value data['BeforeStartStatusId'] = TaskStatus.Unstart.value data['StartedStatusId'] = TaskStatus.Started.value data['CompletedStatusId'] = TaskStatus.Finished.value data['FailedStatusId'] = TaskStatus.Failed.value data['PausedStatusId'] = TaskStatus.Paused.value data['CancelledStatusId'] = TaskStatus.Cancelled.value data['UnLength'] = User.UN_LEN data['PwdLength'] = User.PWD_LEN data['EmailReg'] = User.EMAIL_REG data['CodeLength'] = CodeDatum.CODE_LENGTH data['CodeSecond'] = CodeDatum.CODE_SECOND return data
def ensureUserNotExist(cls, **args): return ViewUtils.ensureObjectNotExist( User, ErrorType.UsernameNotExist, **args)
def getFriend(cls, id, accepted=True, return_type='object') -> Friend: return ViewUtils.getObject(Friend, ErrorType.NotAFriend, return_type=return_type, id=id, accepted=accepted)
def getUser(cls, return_type='object', **args) -> User: return ViewUtils.getObject(User, ErrorType.UsernameNotExist, return_type=return_type, **args)
def getParticipation(cls, uid, pid, return_type='object') -> Participation: return ViewUtils.getObject(Participation, ErrorType.DoNotParticipated, return_type=return_type, user_id=uid, project_id=pid)
def ensureTaskTakeExist(cls, tid, uid): return ViewUtils.ensureObjectExist(TaskTake, ErrorType.TaskTakeNotExist, task_id=tid, user_id=uid)
def getTaskProgress(cls, return_type='object', **args) -> TaskProgress: return ViewUtils.getObject(TaskProgress, ErrorType.ProgressReqNotExist, return_type=return_type, **args)
def getTask(cls, return_type='object', **args) -> Task: return ViewUtils.getObject(Task, ErrorType.TaskNotExist, return_type=return_type, **args)
def ensureRoleExist(cls, rid): return ViewUtils.ensureObjectExist( Role, ErrorType.RoleNotExist, id=rid)
def ensureProjectExist(cls, **args): return ViewUtils.ensureObjectExist( Project, ErrorType.ProjectNotExist, **args)
def getNoticeReceive(cls, nid, uid, return_type='object') -> NoticeReceive: return ViewUtils.getObject(NoticeReceive, ErrorType.ReceiveNotExist, notice_id=nid, user_id=uid, return_type=return_type)
def getNotice(cls, return_type='object', **args) -> Notice: return ViewUtils.getObject(Notice, ErrorType.NoticeNotExist, return_type=return_type, **args)
def getRole(cls, rid, return_type='object') -> Role: return ViewUtils.getObject(Role, ErrorType.RoleNotExist, return_type=return_type, id=rid)
def getProject(cls, return_type='object', **args) -> Project: return ViewUtils.getObject(Project, ErrorType.ProjectNotExist, return_type=return_type, **args)
def ensureFriendExist(cls, **args): return ViewUtils.ensureObjectExist( Friend, ErrorType.NotAFriend, **args)
def ensureFriendNotExist(cls, **args): return ViewUtils.ensureObjectNotExist( Friend, ErrorType.AlreadyAFriend, **args)
def ensureProjectManager(cls, uid, pid): part = cls.getParticipation(uid, pid) part_roles = part.participationrole_set.all() ViewUtils.ensureObjectExist( ParticipationRole, ErrorType.NotAProjManager, part_roles, role_id=Role.ProjectManagerId)
def getTaskTake(cls, tid, uid, return_type='object') -> TaskTake: return ViewUtils.getObject(TaskTake, ErrorType.TaskTakeNotExist, task_id=tid, user_id=uid, return_type=return_type)
def ensureParticipationNotExist(cls, uid, pid): return ViewUtils.ensureObjectNotExist( Participation, ErrorType.HaveParticipated, user_id=uid, project_id=pid)
def ensureTaskExist(cls, **args): return ViewUtils.ensureObjectExist(Task, ErrorType.TaskNotExist, **args)
def ensureNoticeExist(cls, **args): return ViewUtils.ensureObjectExist( Notice, ErrorType.NoticeNotExist, **args)
def ensureTaskProgressExist(cls, **args): return ViewUtils.ensureObjectExist(TaskProgress, ErrorType.ProgressReqNotExist, **args)
def ensureTypeFormat(cls, val: int): ViewUtils.ensureEnumData( val, ProjectType, ErrorType.InvalidProjTypeId)