Beispiel #1
0
 def create(email,
            password,
            first_name=None,
            middle_name=None,
            last_name=None):
     """
     :param first_name: first name of a user
     :type first_name: str
     :param middle_name: middle name of a user
     :type middle_name: str
     :param last_name: last name of a user
     :type last_name: str
     :param email: email of a user
     :type email: str
     :param password: password of a user
     :type password: str
     :return: a new user object which is also written into the DB
     """
     # print(validate_email("96mail.com"))
     data = {}
     data['first_name'] = first_name if first_name else ''
     data['last_name'] = last_name if last_name else ''
     data['middle_name'] = middle_name if middle_name else ''
     data['email'] = email
     user = CustomUser(**data)
     user.set_password(password)
     try:
         validate_email(user.email)
         user.save()
         return user
     except (IntegrityError, AttributeError, ValidationError, DataError):
         LOGGER.error("Wrong attributes or relational integrity error")
         raise ValueError("Some troubles with creating user!")
 def get_by_id(calculator_id):
     try:
         calculator = Calculator.objects.get(id=calculator_id)
         return calculator
     except CustomUser.DoesNotExist:
         LOGGER.error("User does not exist")
     return False
 def delete_by_user_id(user_id):
     try:
         tasks = Calculator.results(user_id)
         for i in tasks:
             i.delete()
         return True
     except Calculator.DoesNotExist:
         LOGGER.error("Task does not exist")
     return False
Beispiel #4
0
 def get_by_id(user_id):
     """
     :param user_id: SERIAL: the id of a user to be found in the DB
     :return: user object or None if a user with such ID does not exist
     """
     try:
         user = CustomUser.objects.get(id=user_id)
         return user
     except CustomUser.DoesNotExist:
         LOGGER.error("User does not exist")
     return False
 def create(size, matrix_a, vector_b, e, user):
     calculator = Calculator(size=size,
                             matrix_a=matrix_a,
                             vector_b=vector_b,
                             e=e,
                             user=user,
                             result=[0 for i in range(size)])
     try:
         calculator.save()
         return calculator
     except (IntegrityError, AttributeError, DataError, ValueError) as err:
         LOGGER.error("Wrong attributes or relational integrity error")
Beispiel #6
0
 def get_by_email(email):
     """
     Returns user by email
     :param email: email by which we need to find the user
     :type email: str
     :return: user object or None if a user with such ID does not exist
     """
     try:
         user = CustomUser.objects.get(email=email)
         return user
     except CustomUser.DoesNotExist:
         LOGGER.error("User does not exist")
         raise ValueError("Incorrect email")
Beispiel #7
0
    def delete_by_id(user_id):
        """
        :param user_id: an id of a user to be deleted
        :type user_id: int
        :return: True if object existed in the db and was removed or False if it didn't exist
        """

        try:
            user = CustomUser.objects.get(id=user_id)
            user.delete()
            return True
        except CustomUser.DoesNotExist:
            LOGGER.error("User does not exist")
        return False