Exemplo n.º 1
0
def choose_template_to_copy(
    service_id,
    from_service=None,
    from_folder=None,
):

    if from_service:

        current_user.belongs_to_service_or_403(from_service)
        service = Service(service_api_client.get_service(from_service)['data'])

        return render_template(
            'views/templates/copy.html',
            services_templates_and_folders=TemplateList(
                service, template_folder_id=from_folder, user=current_user),
            template_folder_path=service.get_template_folder_path(from_folder),
            from_service=service,
            search_form=SearchByNameForm(),
        )

    else:
        return render_template(
            'views/templates/copy.html',
            services_templates_and_folders=TemplateLists(current_user),
            search_form=SearchByNameForm(),
        )
Exemplo n.º 2
0
def choose_template(service_id, template_type="all", template_folder_id=None):
    template_folder = current_service.get_template_folder(template_folder_id)

    user_has_template_folder_permission = current_user.has_template_folder_permission(
        template_folder)

    template_list = TemplateList(current_service, template_type,
                                 template_folder_id, current_user)

    templates_and_folders_form = TemplateAndFoldersSelectionForm(
        all_template_folders=current_service.get_user_template_folders(
            current_user),
        template_list=template_list,
        template_type=template_type,
        allow_adding_letter_template=current_service.has_permission("letter"),
        allow_adding_copy_of_template=(current_service.all_templates
                                       or len(current_user.service_ids) > 1),
    )
    option_hints = {template_folder_id: "current folder"}

    if request.method == "POST" and templates_and_folders_form.validate_on_submit(
    ):
        if not current_user.has_permissions("manage_templates"):
            abort(403)
        try:
            return process_folder_management_form(templates_and_folders_form,
                                                  template_folder_id)
        except HTTPError as e:
            flash(e.message)

    if "templates_and_folders" in templates_and_folders_form.errors:
        flash(_("Select at least one template or folder"))

    initial_state = request.args.get("initial_state")
    if request.method == "GET" and initial_state:
        templates_and_folders_form.op = initial_state

    sending_view = request.args.get("view") == "sending"

    return render_template(
        "views/templates/choose.html",
        current_template_folder_id=template_folder_id,
        template_folder_path=current_service.get_template_folder_path(
            template_folder_id),
        template_list=template_list,
        show_search_box=current_service.count_of_templates_and_folders > 7,
        show_template_nav=(current_service.has_multiple_template_types
                           and (len(current_service.all_templates) > 2)),
        sending_view=sending_view,
        template_nav_items=get_template_nav_items(template_folder_id,
                                                  sending_view),
        template_type=template_type,
        search_form=SearchByNameForm(),
        templates_and_folders_form=templates_and_folders_form,
        move_to_children=templates_and_folders_form.move_to.children(),
        user_has_template_folder_permission=user_has_template_folder_permission,
        option_hints=option_hints,
    )
Exemplo n.º 3
0
def conversation_reply(
    service_id,
    notification_id,
    from_folder=None,
):
    return render_template(
        'views/templates/choose-reply.html',
        templates_and_folders=TemplateList(current_service,
                                           template_folder_id=from_folder,
                                           user=current_user,
                                           template_type='sms'),
        template_folder_path=current_service.get_template_folder_path(
            from_folder),
        search_form=SearchByNameForm(),
        notification_id=notification_id,
        template_type='sms')
Exemplo n.º 4
0
def choose_template(service_id, template_type='all', template_folder_id=None):
    template_folder = current_service.get_template_folder(template_folder_id)

    user_has_template_folder_permission = current_user.has_template_folder_permission(
        template_folder)

    template_list = TemplateList(current_service, template_type,
                                 template_folder_id, current_user)

    templates_and_folders_form = TemplateAndFoldersSelectionForm(
        all_template_folders=current_service.get_user_template_folders(
            current_user),
        template_list=template_list,
        template_type=template_type,
        available_template_types=current_service.available_template_types,
        allow_adding_copy_of_template=(current_service.all_templates
                                       or len(current_user.service_ids) > 1),
    )
    option_hints = {template_folder_id: 'current folder'}

    if request.method == 'POST' and templates_and_folders_form.validate_on_submit(
    ):
        if not current_user.has_permissions('manage_templates'):
            abort(403)
        try:
            return process_folder_management_form(templates_and_folders_form,
                                                  template_folder_id)
        except HTTPError as e:
            flash(e.message)
    elif templates_and_folders_form.trying_to_add_unavailable_template_type:
        return redirect(
            url_for(
                '.action_blocked',
                service_id=current_service.id,
                notification_type=templates_and_folders_form.
                add_template_by_template_type.data,
                return_to='add_new_template',
            ))

    if 'templates_and_folders' in templates_and_folders_form.errors:
        flash('Select at least one template or folder')

    initial_state = request.args.get('initial_state')
    if request.method == 'GET' and initial_state:
        templates_and_folders_form.op = initial_state

    return render_template(
        'views/templates/choose.html',
        current_template_folder_id=template_folder_id,
        template_folder_path=current_service.get_template_folder_path(
            template_folder_id),
        template_list=template_list,
        show_search_box=current_service.count_of_templates_and_folders > 7,
        show_template_nav=(current_service.has_multiple_template_types
                           and (len(current_service.all_templates) > 2)),
        template_nav_items=get_template_nav_items(template_folder_id),
        template_type=template_type,
        search_form=SearchByNameForm(),
        templates_and_folders_form=templates_and_folders_form,
        move_to_children=templates_and_folders_form.move_to.children(),
        user_has_template_folder_permission=user_has_template_folder_permission,
        option_hints=option_hints)