def get(self, value, by="id"): if by == "id": return FindModel(models_list=users).by_id(id_=value) elif by == "username": return FindModel(models_list=users).by_username(username=value) else: raise ValueError("Get user by id or username")
def post(self, thread_application_model, accept): # Update thread application and mark as accepted or rejected status = ApplicationStatusType.ACCEPTED if accept else ApplicationStatusType.REJECTED thread_application_model.status = status.value thread_application_model.updated_at = int(time()) thread_model = FindModel(models_list=threads).by_id(thread_application_model.thread) # Add user to thread thread_model.users.insert(0, thread_application_model.user) # Update thread thread_model.updated_at = int(time()) # Add thread to users threads users_threads[thread_application_model.user].insert(0, thread_model) return thread_application_model
def get(self): """ @api {GET} /validate/username Validate username @apiGroup User @apiDescription Validate username. Check whether it's already taken and has correct format @apiParam (URL query param) {String} username Validate username. Has to be unique, must not be a number, length 2-20 @apiSuccessExample {JSON} Success-Response: { UserValidationModel } """ args = self.reqparse.parse_args() errors = [] user_model = FindModel(models_list=users).by_username(args.username) if user_model: errors.append("Username already taken") return UsernameValidationModel(errors=errors).jsonify() if args.username.isdigit(): errors.append("Username must not be a number") if not validate_length(2, 20, args.username): errors.append( "Username length must be between 2 and 20 characters") return UsernameValidationModel(errors=errors).jsonify()
def __init__(self, container, value=None, by="id", model=None): assert (value is not None) or model self.value = value self.by = by if model: self.model = model if model in container else None else: self.model = FindModel( container)._find_model_in_models_list_by_attr(attr_name=by, attr_value=value)
def user_model(self): username = self.username() user_model = FindModel(users).by_username(username) return user_model
def get(self, thread_id, invitation_id): # Get thread invitation thread_invitation_model = FindModel( models_list=threads_invitations[thread_id]).by_id(invitation_id) return thread_invitation_model
def get(self, thread_id, message_id): # Find and return message return FindModel( models_list=threads_messages[thread_id]).by_id(message_id)
def check_user_invited(self, user_id): return True if FindModel(models_list=threads_invitations[self.thread_model.id]).by_user(user_id) else False
def get(self, thread_id): return FindModel(models_list=threads).by_id(thread_id)
def get(self, thread_id, application_id): # Get thread application thread_application_model = FindModel(models_list=threads_applications[thread_id]).by_id(application_id) return thread_application_model