Ejemplo n.º 1
0
def edit_persona_properties(request, pk):
    """
    :param request: The request object
    :param pk: The primary key of the persona
    :return: Updates the query of the edited persona
    """
    persona = get_object_or_404(Persona, pk=pk)
    config = get_active_configuration()
    user_manager = config.get_user_manager(token=persona.uuid)

    status = 200

    if request.method == 'GET':
        # user_manager is not necessary for getting the form, just when validating
        form = PersonaPropertiesForm(None, initial={'query': persona.query})

    elif request.method == 'POST':
        form = PersonaPropertiesForm(user_manager, request.POST)
        if form.is_valid():
            # if the query changes, we have to update the UUID of the persona
            if persona.query != form.cleaned_data['query']:
                persona.uuid = uuid.uuid4()
                user_manager.reset_token(persona.uuid)
                persona.query = form.cleaned_data['query']

            # generate users according to query
            if persona.update_users(user_manager, async=True):

                # save changes & show full persona view
                persona.is_ready = True
                persona.save()

                # send info to customer platform
                if PRODUCTION:
                    return redirect(
                        '/team-ideation-tools/propagate/?send_persona=%d&next=absolute'
                        % persona.pk)
                else:
                    return redirect(persona.get_absolute_url(full=True))
            else:
                # not enough users
                request.session[
                    'persona_form_error'] = 'Use less strict filters'
                return redirect(persona.get_edit_properties_url(full=True))

        status = 400
Ejemplo n.º 2
0
def edit_persona_properties(request, pk):
    """
    :param request: The request object
    :param pk: The primary key of the persona
    :return: Updates the query of the edited persona
    """
    persona = get_object_or_404(Persona, pk=pk)
    config = get_active_configuration()
    user_manager = config.get_user_manager(token=persona.uuid)

    status = 200

    if request.method == 'GET':
        # user_manager is not necessary for getting the form, just when validating
        form = PersonaPropertiesForm(None, initial={'query': persona.query})

    elif request.method == 'POST':
        form = PersonaPropertiesForm(user_manager, request.POST)
        if form.is_valid():
            # if the query changes, we have to update the UUID of the persona
            if persona.query != form.cleaned_data['query']:
                persona.uuid = uuid.uuid4()
                user_manager.reset_token(persona.uuid)
                persona.query = form.cleaned_data['query']

            # generate users according to query
            if persona.update_users(user_manager, async=True):

                # save changes & show full persona view
                persona.is_ready = True
                persona.save()

                # send info to customer platform
                if PRODUCTION:
                    return redirect('/team-ideation-tools/propagate/?send_persona=%d&next=absolute' % persona.pk)
                else:
                    return redirect(persona.get_absolute_url(full=True))
            else:
                # not enough users
                request.session['persona_form_error'] = 'Use less strict filters'
                return redirect(persona.get_edit_properties_url(full=True))

        status = 400
Ejemplo n.º 3
0
def update_query(p, data):
    if 'query' in data:
        # set query
        config = get_active_configuration()
        user_manager = config.get_user_manager(token=p.uuid)
        p_form = PersonaPropertiesForm(user_manager, data)
        if not p_form.is_valid():
            return JsonResponse({'error': p_form.errors}, status=400, safe=False)

        p.uuid = uuid.uuid4()
        user_manager.reset_token(p.uuid)
        p.query = p_form.cleaned_data['query']

        # generate users according to query
        p.update_users(user_manager)

    # save changes & show full persona view
    p.is_ready = True
    p.save()
Ejemplo n.º 4
0
    def get_context_data(self, **kwargs):
        context = super(PersonaDetailView, self).get_context_data(**kwargs)
        config = get_active_configuration()
        user_manager = config.get_user_manager(token=context['persona'].uuid)

        context['properties'] = user_manager.list_filters()
        context['users'] = PersonaUsers.objects.filter(
            persona=context['persona'])
        context['info_form'] = PersonaForm(instance=context['persona'])
        context['property_form'] = PersonaPropertiesForm(
            None, initial={'query': context['persona'].query})
        context['filters'] = context['properties']
        context['page'] = 'stats'
        context['not_container'] = True

        return context
Ejemplo n.º 5
0
def edit_persona_info(request, pk):
    """
    Update the basic info of a persona
    For updating the `query` of the persona see the `edit_persona_properties(request, pk)` method below
    """
    persona = get_object_or_404(Persona, pk=pk)
    if request.method == 'POST':
        # update persona, send info & redirect
        form = PersonaForm(request.POST, request.FILES, instance=persona)
        if form.is_valid():
            persona = form.save()
            return redirect(
                '/team-ideation-tools/propagate/?send_persona=%d&next=properties'
                % persona.pk)
        else:
            return redirect(persona.get_edit_info_url(full=True))

    form = PersonaForm(instance=persona)

    # also load other forms
    property_form = PersonaPropertiesForm(None,
                                          initial={'query': persona.query})

    ctx = {
        'info_form':
        form,
        'property_form':
        property_form,
        'filters':
        get_active_configuration().get_user_manager(
            token=persona.uuid).list_filters(),
        'persona':
        persona,
        'page':
        'edit-info',
    }

    return render(request, 'persona_builder/persona/details.html', ctx)