Ejemplo n.º 1
0
def create_user(
    activity: str = None,
    civility: str = None,
    cultural_survey_id: str = None,
    cultural_survey_filled_date: datetime = None,
    date_created: datetime = datetime.utcnow(),
    date_of_birth: datetime = None,
    departement_code: str = "93",
    email: str = "*****@*****.**",
    first_name: str = None,
    has_seen_tutorials: bool = None,
    idx: int = None,
    is_admin: bool = False,
    is_beneficiary: bool = True,
    is_email_validated: bool = True,
    last_connection_date: datetime = None,
    last_name: str = None,
    needs_to_fill_cultural_survey: bool = False,
    password: str = None,
    phone_number: str = None,
    postal_code: str = None,
    public_name: str = "John Doe",
    reset_password_token: str = None,
    reset_password_token_validity_limit: datetime = None,
    validation_token: str = None,
) -> User:
    user = User()
    user.activity = activity
    user.civility = civility
    user.culturalSurveyId = cultural_survey_id
    user.culturalSurveyFilledDate = cultural_survey_filled_date
    user.dateCreated = date_created
    user.dateOfBirth = date_of_birth
    user.departementCode = departement_code
    user.email = email
    user.firstName = first_name
    user.hasSeenTutorials = has_seen_tutorials
    user.id = idx
    user.isAdmin = is_admin
    user.isBeneficiary = is_beneficiary
    user.isEmailValidated = is_email_validated
    user.lastConnectionDate = last_connection_date
    user.lastName = last_name
    user.needsToFillCulturalSurvey = needs_to_fill_cultural_survey
    user.phoneNumber = phone_number
    user.publicName = public_name
    user.postalCode = postal_code
    user.validationToken = validation_token

    if password:
        user.setPassword(password)
    else:
        user.setPassword(PLAIN_DEFAULT_TESTING_PASSWORD)
        user.resetPasswordToken = reset_password_token
        user.resetPasswordTokenValidityLimit = reset_password_token_validity_limit

    return user
Ejemplo n.º 2
0
def update_cultural_survey(user: User,
                           body: serializers.CulturalSurveyRequest) -> None:
    with transaction():
        if not body.needs_to_fill_cultural_survey:
            user.needsToFillCulturalSurvey = False
        if body.cultural_survey_id:
            logger.info("User %s updated cultural survey",
                        user.id,
                        extra={"actor": user.id})
            user.culturalSurveyId = body.cultural_survey_id
            user.culturalSurveyFilledDate = datetime.now()
    return
Ejemplo n.º 3
0
def update_cultural_survey(user: User,
                           body: serializers.CulturalSurveyRequest) -> None:
    with transaction():
        if not body.needs_to_fill_cultural_survey:
            user.needsToFillCulturalSurvey = False
        if body.cultural_survey_id:
            if user.culturalSurveyId:
                raise ApiErrors({
                    "culturalSurveyId":
                    "L'utilisateur a déjà rempli le formulaire"
                })
            user.culturalSurveyId = body.cultural_survey_id
            user.culturalSurveyFilledDate = datetime.now()
    return