Esempio n. 1
0
def run_pytools_promotion_campaign() -> int:
    """
    Run pytools campaign for users registered 7 weeks ago
    :return: number of user's marked for promotion
    """
    begin, end = _payments_facade.calculate_7th_week_before_promotion()
    promotion_users = _core_facade.find_leads_by_date_joined_interval(
        begin, end)
    for user in promotion_users:
        try:
            _email_marketing_facade.tag_as(user.email, user.id,
                                           'pytools-promotion')
        except _ActiveCampaignError:
            pass
    return len(promotion_users)
Esempio n. 2
0
def force_register_member(first_name, email, source='unknown'):
    """
    Create a new user on the system generation a random password or update existing one based on email.
    An Welcome email is sent to the user informing his password with the link to change it.
    User is also registered on Mailchimp. But she will be registered even if api call fails
    :param first_name: User's first name
    :param email: User's email
    :param source: source of User traffic
    :return: User
    """
    user = _core_facade.register_member(first_name, email, source)
    _cohorts_facade.subscribe_to_last_cohort(user)
    cohort = _cohorts_facade.find_most_recent_cohort()
    sync_user_on_discourse(user)
    try:
        _email_marketing_facade.create_or_update_member(first_name, email, id=user.id)
        _email_marketing_facade.tag_as(email, user.id, f'turma-{cohort.slug}')
    except _ActiveCampaignError:
        pass
    return user
Esempio n. 3
0
def tag_newly_completed_contents(user_or_user_id, topic_id: int):
    """
    Tag user completed contents on email marketing for segmentation
    This will only consider module -> section -> chapter -> topic
    accordingly with topics_id
    :param topic_id: topic_id from topic user last updated
    :param user_or_user_id: Django User or his id
    :return: list of contents_full_tags
    """
    user = core_facade.find_user_by_id(user_or_user_id)
    topic = get_topic_with_contents_by_id(topic_id)
    possible_changing_tags = {
        topic.chapter.section.module.full_slug,
        topic.chapter.section.full_slug,
        topic.chapter.full_slug,
        topic.full_slug,
    }
    completed_module_content_slugs = (c.full_slug for c in completed_module_contents(user, topic.find_module()))
    tags = [s for s in completed_module_content_slugs if s in possible_changing_tags]
    if tags:
        email_marketing_facade.tag_as(user.email, user.id, *tags)
    return tags
Esempio n. 4
0
def enrol(request, slug):
    module = get_module_with_contents(slug)
    user = request.user
    tag_as(user.email, user.id, slug)
    return render(request, 'modules/module_enrol.html', context={'module': module})