def list(self, idObjective): page = int(fn.Http(self.request).get_query_param('page')) goals = Goal.objects.filter(objective__id=idObjective, isActive=True).order_by( 'done', 'dateGoal', 'goal', ) paginator = Paginator(goals, 5, allow_empty_first_page=True) try: next = paginator.page(page).next_page_number() except: next = 0 goalsDTO = list( map(lambda goal: GoalSerializer(goal).data, paginator.get_page(page).object_list)) return Response({ 'count': paginator.count, 'next': next, 'goals': goalsDTO })
def list(self): page = int(fn.Http( self.request).get_query_param('page')) objectives = Objective.objects.filter( user__id=self.user['id'], isActive=True).order_by('done', 'dateObjective', 'objective') paginator = Paginator(objectives, 5, allow_empty_first_page=True) try: next = paginator.page(page).next_page_number() except: next = 1 objectivesDTO = list(map(lambda objective: ObjectiveSerializer(objective).data, paginator.get_page(page).object_list)) return Response({ 'count': paginator.count, 'next': next, 'objectives': objectivesDTO })
def get(self, token=None): if token == None: bearer = fn.Http(self.request).get_header('Authorization') token = bearer.split(' ')[1] return self.__get_access_token(token) \ .make(self.__dto)
def verify(self): token = fn.Http(self.request).get_property('token') return self.__get_token(token, 'V') \ .execute(function=self.__verify_user, params=['V']) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse( fn.SuccessResponse( var.SUCCESS.USER_VERIFY))
def recovery(self): password, token = fn.Http(self.request).get_properties( ['password', 'token']) return self.__get_token(token, 'R') \ .execute(function=self.__change_password, params=[password, 'R']) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse( fn.SuccessResponse( var.SUCCESS.RECOVERY_SUCCESS))
def create(self, idObjective, idGoal): task, description = fn.Http(self.request).get_properties( ['task', 'description']) return fn.Optional(idObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(idGoal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(task) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_task(idObjective, idGoal, task, description))
def create(self, idObjective): goal, dateGoal = fn.Http(self.request).get_properties( ['goal', 'dateGoal']) return fn.Optional(idObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(goal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dateGoal) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_goal(idObjective, goal, dateGoal))
def update(self, id): name, lastName = fn.Http(self.request).get_properties( ['firstName', 'lastName']) return fn.Optional(id) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(name) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(lastName) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__update_user( id, name, lastName))
def login(self): username, password = fn.Http(self.request).get_properties( ['username', 'password']) user = authenticate(self.request, username=username, password=password) return fn.Optional(username) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(password) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(user) \ .is_null(var.ERRORS.USER_NOT_EXIST) \ .is_active(var.ERRORS.USER_IS_NOT_ACTIVE) \ .make(self.__get_person)
def create(self): objective, dateObjective, dificulty = fn.Http( self.request).get_properties([ 'objective', 'dateObjective', 'dificulty' ]) return fn.Optional(objective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dateObjective) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(dificulty) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .httpReponse(self.__create_objective(objective, dateObjective, dificulty))
def create(self): name, lastName, username, password, password_confirmation = fn.Http( self.request).get_properties([ 'name', 'lastName', 'username', 'password', 'passwordConfirmation' ]) return fn.Optional(name) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(lastName) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(username) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .alsoVerify(password) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .is_equals(var.ERRORS.USER_PASSWORD_NOT_MATCH, password_confirmation) \ .httpReponse(self.__create_user( name, lastName, username, password))
def password_recovery(self): email = fn.Http(self.request).get_property('email') return fn.Optional(email) \ .is_null(var.ERRORS.EMPTY_FIELD) \ .build(self.__get_by_email)