def submit_request_to_go_live(service_id):

    zendesk_client.create_ticket(
        subject='Request to go live - {}'.format(current_service.name),
        message=(
            'Service: {service_name}\n'
            '{service_dashboard}\n'
            '\n---'
            '\nOrganisation type: {organisation_type}'
            '\nAgreement signed: {agreement}'
            '\n'
            '\nEmails in next year: {volume_email_formatted}'
            '\nText messages in next year: {volume_sms_formatted}'
            '\nLetters in next year: {volume_letter_formatted}'
            '\n'
            '\nConsent to research: {research_consent}'
            '\nOther live services: {existing_live}'
            '\n'
            '\nService reply-to address: {email_reply_to}'
            '\n'
            '\n---'
            '\nRequest sent by {email_address}'
            '\n').format(
                service_name=current_service.name,
                service_dashboard=url_for('main.service_dashboard',
                                          service_id=current_service.id,
                                          _external=True),
                organisation_type=str(
                    current_service.organisation_type).title(),
                agreement=current_service.organisation.
                as_agreement_statement_for_go_live_request(
                    current_user.email_domain),
                volume_email_formatted=format_thousands(
                    current_service.volume_email),
                volume_sms_formatted=format_thousands(
                    current_service.volume_sms),
                volume_letter_formatted=format_thousands(
                    current_service.volume_letter),
                research_consent='Yes'
                if current_service.consent_to_research else 'No',
                existing_live='Yes' if current_user.live_services else 'No',
                email_address=current_user.email_address,
                email_reply_to=current_service.default_email_reply_to_address
                or 'not set',
            ),
        ticket_type=zendesk_client.TYPE_QUESTION,
        user_email=current_user.email_address,
        user_name=current_user.name,
        tags=current_service.request_to_go_live_tags,
    )

    current_service.update(go_live_user=current_user.id)

    flash(
        'Thanks for your request to go live. We’ll get back to you within one working day.',
        'default')
    return redirect(url_for('.service_settings', service_id=service_id))
Пример #2
0
def cancel_letter_job(service_id, job_id):
    if request.method == 'POST':
        job = job_api_client.get_job(service_id, job_id)['data']
        notification_count = notification_api_client.get_notification_count_for_job_id(
            service_id=service_id, job_id=job_id)
        if job['job_status'] != 'finished' or notification_count < job[
                'notification_count']:
            flash(
                "We are still processing these letters, please try again in a minute.",
                'try again')
            return view_job(service_id, job_id)
        try:
            number_of_letters = job_api_client.cancel_letter_job(
                current_service.id, job_id)
        except HTTPError as e:
            flash(e.message, 'dangerous')
            return redirect(
                url_for('main.view_job', service_id=service_id, job_id=job_id))
        flash(
            "Cancelled {} letters from {}".format(
                format_thousands(number_of_letters),
                job['original_file_name']), 'default_with_tick')
        return redirect(
            url_for('main.service_dashboard', service_id=service_id))

    flash("Are you sure you want to cancel sending these letters?", 'cancel')
    return view_job(service_id, job_id)
Пример #3
0
def cancel_letter_job(service_id, job_id):
    if request.method == "POST":
        job = job_api_client.get_job(service_id, job_id)["data"]
        notifications = notification_api_client.get_notifications_for_service(
            job["service"], job["id"])["notifications"]
        if job["job_status"] != "finished" or len(
                notifications) < job["notification_count"]:
            flash(
                "We are still processing these letters, please try again in a minute.",
                "try again",
            )
            return view_job(service_id, job_id)
        try:
            number_of_letters = job_api_client.cancel_letter_job(
                current_service.id, job_id)
        except HTTPError as e:
            flash(e.message, "dangerous")
            return redirect(
                url_for("main.view_job", service_id=service_id, job_id=job_id))
        flash(
            "Cancelled {} letters from {}".format(
                format_thousands(number_of_letters),
                job["original_file_name"]),
            "default_with_tick",
        )
        return redirect(
            url_for("main.service_dashboard", service_id=service_id))

    flash("Are you sure you want to cancel sending these letters?", "cancel")
    return view_job(service_id, job_id)
    def __call__(self, **kwargs):

        if self.get_form().is_submitted() and not self.get_form().validate():
            return super().__call__(
                value=(self.raw_data or [None])[0],
                **kwargs
            )

        try:
            value = int(self.data)
            value = format_thousands(value)
        except (ValueError, TypeError):
            value = self.data if self.data is not None else ''

        return super().__call__(value=value, **kwargs)
Пример #5
0
def cancel_letter_job(service_id, job_id):
    if request.method == 'POST':
        job = Job.from_id(job_id, service_id=service_id)

        if job.status != 'finished' or job.notifications_created < job.notification_count:
            flash("We are still processing these letters, please try again in a minute.", 'try again')
            return view_job(service_id, job_id)
        try:
            number_of_letters = job.cancel()
        except HTTPError as e:
            flash(e.message, 'dangerous')
            return redirect(url_for('main.view_job', service_id=service_id, job_id=job_id))
        flash("Cancelled {} letters from {}".format(
            format_thousands(number_of_letters), job.original_file_name
        ), 'default_with_tick')
        return redirect(url_for('main.service_dashboard', service_id=service_id))

    flash("Are you sure you want to cancel sending these letters?", 'cancel')
    return view_job(service_id, job_id)
    def pre_validate(self, form):

        if self.data:
            error = None
            try:
                if int(self.data) > self.POSTGRES_MAX_INT:
                    error = 'Number of {} must be {} or less'.format(
                        self.things,
                        format_thousands(self.POSTGRES_MAX_INT),
                    )
            except ValueError:
                error = 'Enter the number of {} {}'.format(
                    self.things,
                    self.format_error_suffix,
                )

            if error:
                raise ValidationError(error)

        return super().pre_validate(form)