def edit_page(self, name): task = Backend("task").find(name) if not task: raise exc.HTTPNotFound("Not found") if not task.data: task.data = "" else: task.data = json_encode(task.data) return render_template("task.edit.html", task=task, statuses=TASK_STATUSES)
def login(self, username='', password=''): LOGGER.error('username=%s', username) username = username.strip() password = password.strip() user = Backend('user').find_by_username(username) if user and user.check(password): set_secure_cookie('auth', str(user.uid)) LOGGER.info('success') raise exc.HTTPFound(location='/task') return render_template('login.html')
def stop_task(cls, name): task = Backend("task").find(name) if not task.is_running(): task.status = Task.STOP Backend("task").save(task) return True return False
def test_save_after_retry(self): task = Backend('task').find('job_test') task.retry('msg') Backend('task').save(task) task = Backend('task').find('job_test') assert task.name == self.task.name assert task.event == self.task.event assert task.run_times == 1 assert task.attempts == self.task.attempts + 1 assert task.status == Task.RETRY
def delete(self, name): task = Backend("task").find(name) if not task: return {"status": "error", "msg": "Doesn't exist the task"} if not task.is_running(): Backend("task").delete(task) return {"status": "redirect", "msg": "deleted, wait to redirect to /task", "url": "/task"} else: return {"status": "error", "msg": "The task is runnig"}
def test_save(self): task = Backend('task').find('job_test') task.fresh() task.attempts += 1 task.status = Task.COMPLETED Backend('task').save(task) task = Backend('task').find('job_test') assert task.name == self.task.name assert task.event == self.task.event assert task.run_times == 1 assert task.attempts == self.task.attempts + 1 assert task.status == Task.COMPLETED assert task.last_five_logs[0]['status'] == Task.SCHEDULED
def test_save(self): # on dup user = Backend('user').find(self.uid) user.status = 'banned' Backend('user').save(user) user = Backend('user').find(self.uid) assert user.status == 'banned' # new case user = User('username', 'email2', 'real_name', 'password', 'active') Backend('user').save(user) user = Backend('user').find_by_email(self.user.email) assert user is not None
def edit(self, name, action, data, event, status): try: action, data, status = self.process_task_args(action, data, status) except TypeError as e: return {"msg": str(e), "status": "error"} task = Backend("task").find(name) if not task: raise exc.HTTPNotFound("Not found") if not task.is_running(): task.action = action task.status = status try: task.event = event except: return {"msg": "event invalid", "status": "error"} Backend("task").save(task) return {"status": "info", "msg": "saved"} else: return {"status": "error", "msg": "The task is runnig"}
def edit(self, uid, email, real_name, password, newpass1, newpass2, status, role='user'): real_name, newpass1, newpass2 = real_name.strip(), newpass1.strip(), newpass2.strip() uid = int(uid) user = Backend('user').find(uid) if not user: raise exc.HTTPNotFound('user not found') me = ctx.request.user if me.uid == user.uid: if re.match(r'[A-Za-z0-9@#$%^&+=]{4,16}', newpass1): if password and newpass1 and newpass1 == newpass2: user.password = newpass1 elif newpass1: return {'status' : 'error', 'msg' : 'password: %s must be the [A-Za-z0-9_]{4,16} pattern' %(newpass1)} if len(email) > 7 and re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email): user_ = Backend('user').find_by_email(email) if user_ and user_.uid != user.uid: return {'status' : 'error', 'msg' : 'email:%s is used' %(email)} else: user.email = email if me.uid == 1 and user.uid != 1: if role in (ADMIN, USER): user.role = role if user.status != status and status in USER_STATUSES: user.status = status if re.match(r'^[A-Za-z0-9_ ]{4,16}$', real_name): if user.real_name != real_name: user.real_name = real_name Backend('user').save(user) return {'status' : 'info', 'msg' : 'updated'}
def delete_task(cls, name): task = Backend("task").find(name) if not task.is_running(): Backend("task").delete(task) return True return False