Ejemplo n.º 1
0
 def user_and_stage_is_valid(self, uid, sid):
     if uid > 0 and sid > 0:
         users_dao = UsersDao()
         cur_user = users_dao.get_user_by_uid(uid)
         if cur_user:
             stage_dao = StageDao()
             cur_stage = stage_dao.get_stage_by_sid(sid)
             if cur_stage:
                 return True
             else:
                 return False
         else:
             return False
     else:
         return False
Ejemplo n.º 2
0
 def __init__(self):
     self.dao = StageDao()
Ejemplo n.º 3
0
class StageManager:

    def __init__(self):
        self.dao = StageDao()

    def clear(self):
        all_stages = self.dao.get_all_stages()
        for stage in all_stages:
            self.dao.delete_stage(stage)

    def add_stage(self, sid, name, info):
        if sid < 0:
            return 'Sid invalid.'
        if sid == 0:
            all_stages = self.dao.get_all_stages()
            if len(all_stages) > 0:
                sid = all_stages[-1].sid + 1
            else:
                sid = 1

        target = self.dao.get_stage_by_sid(sid)
        if target:
            return 'Stage #' + str(sid) + 'already exists.'
        else:
            self.dao.create_stage(sid, name, info)
            return 'Succeeded, new stage\'s sid: #' + str(sid)

    def get_stage(self, sid):
        if sid <= 0:
            return None
        else:
            cur_stage = self.dao.get_stage_by_sid(sid)
            if cur_stage:
                return cur_stage
            else:
                return None

    def get_all_stages(self):
        return self.dao.get_all_stages()

    def delete_stage(self, sid):
        if sid <= 0:
            return 'Sid invalid.'
        else:
            cur_stage = self.dao.get_stage_by_sid(sid)
            if cur_stage:
                self.dao.delete_stage(sid)
                return 'Succeeded.'
            else:
                return 'Succeeded. Stage #' + str(sid) + ' does not exist, nothing is done.'

    def update_stage(self, sid, new_name, new_info):
        if sid <= 0:
            return 'Sid invalid.'

        cur_stage = self.dao.get_stage_by_sid(sid)
        if cur_stage:
            if len(new_name) > 0:
                self.dao.update_name(cur_stage, new_name)
            if len(new_info) > 0:
                self.dao.update_info(cur_stage, new_info)
            return 'Succeeded.'
        else:
            return 'Stage #' + str(sid) + 'does not exist.'