Example #1
0
    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
        })
Example #2
0
    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
        })
Example #3
0
    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)
Example #4
0
    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))
Example #5
0
    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))
Example #6
0
    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))
Example #7
0
    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))
Example #8
0
    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))
Example #9
0
    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)
Example #10
0
    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))
Example #11
0
    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))
Example #12
0
    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)