Пример #1
0
    def form_valid(self, form):
        skip_steps = []
        email = normalize_email(form.cleaned_data.get('email'))
        name = form.cleaned_data.get('name')
        custom_text = form.cleaned_data.get('custom_text')
        full_name = name
        short_name = name.split(' ')[0]

        consultant = self.model.objects.create_consultant(
            short_name=short_name,
            full_name=full_name,
            email=email,
            invite_user=self.request.user,
            registration_process=True,
            skip_steps=skip_steps,
            custom_text=custom_text,
            coins=form.cleaned_data.get('coins'),
            waiting_list=form.cleaned_data.get('waiting_list'),
        )

        SegmentAnalytics.event(
            user=consultant.user,
            category=settings.INSTRUMENTATION_ONBOARDING_CATEGORY,
            event=settings.INSTRUMENTATION_EVENT_STARTED,
            entry_point=settings.INSTRUMENTATION_USER_ENTRY_POINT_NETWORK,
        )

        return super().form_valid(form)
Пример #2
0
def certification_request_acquired_handler(sender, user, consultant_role,
                                           *args, **kwargs):
    certification_requests = CertificationRequest.objects.filter(
        user=user,
        status=settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_APPROVED,
        certification__certification_role=consultant_role.certification_role,
    )

    certification = None

    if certification_requests.exists():
        certification_request = certification_requests.first()
        certification_request.acquire_certificate(consultant_role)
        certification = certification_request.certification

    if not certification:
        certification = ExOCertification.objects.get(
            level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_1)

    category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
        certification.level)
    data = {
        'user': user,
        'category': category,
        'event': settings.INSTRUMENTATION_EVENT_CERTIFICATION_SENT,
    }

    if certification.level != settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_1:
        data['certificationType'] = certification.get_level_display()

    SegmentAnalytics.event(**data)
Пример #3
0
    def create(self, validated_data):
        email = validated_data.get('email')
        full_name = validated_data.get('full_name')
        level = validated_data.get('level')
        coupon = validated_data.get('coupon', None)
        referrer = validated_data.get('referrer', None)
        user = None

        try:
            user = UserModel.objects.get(email=email)
        except UserModel.DoesNotExist:
            pass

        if level == settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3:
            raise NotAuthenticated({'custom': 'LOGIN_REQUIRED_TO_PROCEED'})

        # Checks whether user can certificate or not
        requester = user if user else email
        certification = user_can_do_certification(requester, level)

        certification_request_defaults = {
            'requester_name': full_name,
        }

        certification_request, created = CertificationRequest.objects.get_or_create(
            certification=certification,
            requester_email=email,
            status__in=[
                settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_DRAFT,
                settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING,
            ],
            defaults=certification_request_defaults,
        )

        if created:
            certification_request.referrer = referrer

        if user:
            certification_request.user = user
            category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
                certification_request.level)
            coupon_code = coupon.code if coupon else None
            SegmentAnalytics.event(
                user=user,
                category=category,
                event=settings.INSTRUMENTATION_EVENT_CERTIFICATION_INTERESTED,
                coupon=coupon_code,
                entry_point=settings.
                INSTRUMENTATION_USER_ENTRY_POINT_CERTIFICATIONS)

        certification_request.coupon = coupon
        certification_request.save(
            update_fields=['user', 'coupon', 'referrer'])

        return certification_request
Пример #4
0
    def create(self, validated_data):
        email = validated_data.get('email')
        password = validated_data.get('password')
        invitation = self.context.get('invitation')
        invitation.accept(invitation.user, email=email, password=password)

        SegmentAnalytics.event(
            user=invitation.user,
            category=settings.INSTRUMENTATION_ONBOARDING_CATEGORY,
            event=settings.INSTRUMENTATION_EVENT_STARTED,
            entry_point=settings.INSTRUMENTATION_USER_ENTRY_POINT_JOIN_US,
        )

        return authenticate(
            username=invitation.user.email,
            password=password,
        )
Пример #5
0
    def update(self, instance, validated_data):
        payment_status = validated_data.get('payment_status')

        instance.validate_payment(payment_status)
        instance.refresh_from_db()

        if payment_status == settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_APPROVED:
            category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
                instance.level)
            SegmentAnalytics.event(
                user=instance.user,
                category=category,
                event=settings.INSTRUMENTATION_EVENT_CERTIFICATION_UPDATED,
                action_done=settings.INSTRUMENTATION_CERTIFICATION_ACTION_PAY,
                cohort=instance.cohort.date,
                language=instance.cohort.language,
                final_price=instance.price,
                payment_method=validated_data.get('payment_method'))

        return instance
Пример #6
0
    def create(self, validated_data):
        level = validated_data.get('level')
        coupon = validated_data.get('coupon', None)
        referrer = validated_data.get('referrer', None)
        user = validated_data.get('user')

        certification = user_can_do_certification(user, level)

        certification_defaults = {
            'requester_name': user.full_name,
            'user': user,
        }

        certification_request, created = CertificationRequest.objects.get_or_create(
            certification=certification,
            requester_email=user.email,
            status__in=[
                settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_DRAFT,
                settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING,
            ],
            defaults=certification_defaults,
        )

        if created:
            certification_request.referrer = referrer

        category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
            certification_request.level)
        coupon_code = coupon.code if coupon else None
        SegmentAnalytics.event(
            user=user,
            category=category,
            event=settings.INSTRUMENTATION_EVENT_CERTIFICATION_INTERESTED,
            coupon=coupon_code,
            entry_point=settings.
            INSTRUMENTATION_USER_ENTRY_POINT_CERTIFICATIONS)

        certification_request.coupon = coupon
        certification_request.save()

        return certification_request
Пример #7
0
def signal_segment_event_user_save_handler(sender, instance, created, *args,
                                           **kwargs):
    SegmentAnalytics.identify(instance)
Пример #8
0
def update_certification_request(certification_request, data):
    country = data.get('country')

    certification_request.application_details = data.get(
        'application_details', {})
    certification_request.cohort = data.get('cohort')
    certification_request.status = settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING
    certification_request.save()

    # Checks whether the user is created or not
    if not certification_request.user:
        consultant = Consultant.objects.create_consultant(
            full_name=certification_request.requester_name,
            short_name=certification_request.requester_name,
            email=certification_request.requester_email,
            registration_process=True,
            skip_steps=[settings.REGISTRATION_STEPS_NAMES[1][0]],
            entry_point=get_entry_point_by_level(certification_request.level),
        )
        certification_request.user = consultant.user
        certification_request.save()

        category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
            certification_request.level)
        coupon_code = certification_request.coupon.code if certification_request.coupon else None
        SegmentAnalytics.event(
            user=certification_request.user,
            category=category,
            event=settings.INSTRUMENTATION_EVENT_CERTIFICATION_INTERESTED,
            coupon=coupon_code,
            entry_point=settings.
            INSTRUMENTATION_USER_ENTRY_POINT_CERTIFICATIONS)
    elif not certification_request.user.is_consultant:
        Consultant.objects.create_consultant(
            full_name=certification_request.user.full_name,
            short_name=certification_request.user.short_name,
            email=certification_request.user.email,
            registration_process=True,
            skip_steps=[settings.REGISTRATION_STEPS_NAMES[1][0]],
            entry_point=get_entry_point_by_level(certification_request.level),
        )
        certification_request.refresh_from_db()

    contracting_data = {
        'name': data.get('billing_name'),
        'tax_id': data.get('tax_id'),
        'address': data.get('billing_address'),
        'company_name': data.get('company_name'),
    }
    user = certification_request.user
    user.consultant.exo_profile.set_contracting(**contracting_data)
    certification_request.price = certification_request.cohort.price
    if certification_request.coupon:
        certification_request.apply_coupon(certification_request.coupon, user)

    # Generates or updates payment
    trigger_payment(certification_request, country)

    certification_request.notify_referrer()

    category = settings.EXO_CERTIFICATION_INSTRUMENTATION_EVENTS.get(
        certification_request.level)
    SegmentAnalytics.event(
        user=certification_request.user,
        category=category,
        event=settings.INSTRUMENTATION_EVENT_CERTIFICATION_UPDATED,
        action_done=settings.
        INSTRUMENTATION_CERTIFICATION_ACTION_PROCEED_PAYMENT,
    )

    return certification_request