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(), )
def choose_broadcast_area(service_id, broadcast_message_id, library_slug): broadcast_message = BroadcastMessage.from_id( broadcast_message_id, service_id=current_service.id, ) library = BroadcastMessage.libraries.get(library_slug) if library.is_group: return render_template( 'views/broadcast/areas-with-sub-areas.html', search_form=SearchByNameForm(), show_search_form=(len(library) > 7), library=library, page_title=f'Choose a {library.name_singular.lower()}', broadcast_message=broadcast_message, ) form = BroadcastAreaForm.from_library(library) if form.validate_on_submit(): broadcast_message.add_areas(*form.areas.data) return redirect( url_for( '.preview_broadcast_areas', service_id=current_service.id, broadcast_message_id=broadcast_message.id, )) return render_template( 'views/broadcast/areas.html', form=form, search_form=SearchByNameForm(), show_search_form=(len(form.areas.choices) > 7), page_title=f'Choose {library.name.lower()}', broadcast_message=broadcast_message, )
def find_services_by_name(): form = SearchByNameForm() services_found = None if form.validate_on_submit(): services_found = service_api_client.find_services_by_name( service_name=form.search.data)['data'] return render_template('views/find-services/find-services-by-name.html', form=form, services_found=services_found)
def find_services_by_name(): form = SearchByNameForm() services_found = None if form.validate_on_submit(): with suppress(ValueError): return redirect( url_for('main.service_dashboard', service_id=uuid.UUID(form.search.data))) services_found = service_api_client.find_services_by_name( service_name=form.search.data)['data'] return render_template('views/find-services/find-services-by-name.html', form=form, services_found=services_found)
def choose_broadcast_sub_area(service_id, broadcast_message_id, library_slug, area_slug): broadcast_message = BroadcastMessage.from_id( broadcast_message_id, service_id=current_service.id, ) area = BroadcastMessage.libraries.get_areas(area_slug)[0] back_link = _get_broadcast_sub_area_back_link(service_id, broadcast_message_id, library_slug) is_county = any(sub_area.sub_areas for sub_area in area.sub_areas) form = BroadcastAreaFormWithSelectAll.from_library( [] if is_county else area.sub_areas, select_all_choice=(area.id, f'All of {area.name}'), ) if form.validate_on_submit(): broadcast_message.add_areas(*form.selected_areas) return redirect( url_for( '.preview_broadcast_areas', service_id=current_service.id, broadcast_message_id=broadcast_message.id, )) if is_county: # area = county. sub_areas = districts. they have wards, so link to individual district pages return render_template( 'views/broadcast/counties.html', form=form, search_form=SearchByNameForm(), show_search_form=(len(area.sub_areas) > 7), library_slug=library_slug, page_title=f'Choose an area of {area.name}', broadcast_message=broadcast_message, county=area, back_link=back_link, ) return render_template( 'views/broadcast/sub-areas.html', form=form, search_form=SearchByNameForm(), show_search_form=(len(form.areas.choices) > 7), library_slug=library_slug, page_title=f'Choose an area of {area.name}', broadcast_message=broadcast_message, back_link=back_link, )
def add_organisation_from_nhs_local_service(service_id): if (not current_service.organisation_type == Organisation.TYPE_NHS_LOCAL) or current_service.organisation: abort(403) form = AddNHSLocalOrganisationForm( organisation_choices=[(organisation.id, organisation.name) for organisation in Organisations() if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL]) search_form = SearchByNameForm() if form.validate_on_submit(): Organisation.from_id( form.organisations.data).associate_service(service_id) return redirect(url_for( '.service_agreement', service_id=service_id, )) return render_template( 'views/organisations/add-nhs-local-organisation.html', form=form, search_form=search_form, )
def service_set_email_branding(service_id): email_branding = email_branding_client.get_all_email_branding() current_branding = current_service.email_branding_id if current_branding is None: current_branding = (FieldWithLanguageOptions.FRENCH_OPTION_VALUE if current_service.default_branding_is_french is True else FieldWithLanguageOptions.ENGLISH_OPTION_VALUE) form = SetEmailBranding( all_branding_options=get_branding_as_value_and_label(email_branding), current_branding=current_branding, ) if form.validate_on_submit(): return redirect( url_for( '.service_preview_email_branding', service_id=service_id, branding_style=form.branding_style.data, )) return render_template('views/service-settings/set-email-branding.html', form=form, search_form=SearchByNameForm())
def letter_branding(): brandings = letter_branding_client.get_all_letter_branding() return render_template('views/letter-branding/select-letter-branding.html', letter_brandings=brandings, search_form=SearchByNameForm())
def edit_organisation_email_branding(org_id): email_branding = email_branding_client.get_all_email_branding() current_branding = current_organisation.email_branding_id # organizations don't support multi language yet / we aren't using organizations if current_branding is None: current_branding = (FieldWithLanguageOptions.FRENCH_OPTION_VALUE if current_organisation.default_branding_is_french is True else FieldWithLanguageOptions.ENGLISH_OPTION_VALUE) form = SetEmailBranding( all_branding_options=get_branding_as_value_and_label(email_branding), current_branding=current_branding, ) if form.validate_on_submit(): return redirect(url_for( '.organisation_preview_email_branding', org_id=org_id, branding_style=form.branding_style.data, )) return render_template( 'views/organisations/organisation/settings/set-email-branding.html', form=form, search_form=SearchByNameForm() )
def email_branding(): brandings = email_branding_client.get_all_email_branding(sort_key='name') return render_template( 'views/email-branding/select-branding.html', email_brandings=brandings, search_form=SearchByNameForm() )
def organisations(): orgs = organisations_client.get_organisations() return render_template( 'views/organisations/index.html', organisations=orgs, search_form=SearchByNameForm(), )
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, )
def pricing(): return render_template( 'views/pricing.html', sms_rate=0.0158, international_sms_rates=sorted( [(cc, country['names'], country['billable_units']) for cc, country in INTERNATIONAL_BILLING_RATES.items()], key=lambda x: x[0]), search_form=SearchByNameForm(), )
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')
def service_set_email_branding(service_id): email_branding = email_branding_client.get_all_email_branding() form = SetEmailBranding( all_branding_options=get_branding_as_value_and_label(email_branding), current_branding=current_service.email_branding_id, ) if form.validate_on_submit(): return redirect( url_for( '.service_preview_email_branding', service_id=service_id, branding_style=form.branding_style.data, )) return render_template('views/service-settings/set-email-branding.html', form=form, search_form=SearchByNameForm())
def edit_organisation_letter_branding(org_id): letter_branding = letter_branding_client.get_all_letter_branding() form = SetLetterBranding( all_branding_options=get_branding_as_value_and_label(letter_branding), current_branding=current_organisation.letter_branding_id, ) if form.validate_on_submit(): return redirect( url_for( '.organisation_preview_letter_branding', org_id=org_id, branding_style=form.branding_style.data, )) return render_template( 'views/organisations/organisation/settings/set-letter-branding.html', form=form, search_form=SearchByNameForm())
def organisation_dashboard(org_id): year, current_financial_year = requested_and_current_financial_year(request) services = current_organisation.services_and_usage( financial_year=year )['services'] return render_template( 'views/organisations/organisation/index.html', services=services, years=get_tuples_of_financial_years( partial(url_for, '.organisation_dashboard', org_id=current_organisation.id), start=current_financial_year - 1, end=current_financial_year + 1, ), selected_year=year, search_form=SearchByNameForm() if len(services) > 7 else None, **{ f'total_{key}': sum(service[key] for service in services) for key in ('emails_sent', 'sms_cost', 'letter_cost') } )
def link_service_to_organisation(service_id): all_organisations = organisations_client.get_organisations() form = LinkOrganisationsForm( choices=convert_dictionary_to_wtforms_choices_format( all_organisations, 'id', 'name'), organisations=current_service.organisation_id) if form.validate_on_submit(): if form.organisations.data != current_service.organisation_id: organisations_client.update_service_organisation( service_id, form.organisations.data) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/link-service-to-organisation.html', has_organisations=all_organisations, form=form, search_form=SearchByNameForm(), )
def organisation_trial_mode_services(org_id): return render_template( 'views/organisations/organisation/trial-mode-services.html', search_form=SearchByNameForm(), )
def organisations(): return render_template( 'views/organisations/index.html', organisations=Organisations(), search_form=SearchByNameForm(), )
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)