Example #1
0
def feedback(request):
    recipient = get_customization('feedback_email_address')
    email_contents = get_media_file_contents('feedback_email.html')
    if not recipient or not email_contents:
        return render(request, 'feedback.html',
                      {'customization_required': True})

    if request.method == 'GET':
        return render(request, 'feedback.html')
    contents = parse_parameter_string(request.POST, 'feedback',
                                      FEEDBACK_MAXIMUM_LENGTH)
    if contents == '':
        return render(request, 'feedback.html')
    dictionary = {
        'contents': contents,
        'user': request.user,
    }

    email = Template(email_contents).render(Context(dictionary))
    send_mail('Feedback from ' + str(request.user), email, request.user.email,
              [recipient])
    dictionary = {
        'title':
        'Feedback',
        'heading':
        'Thanks for your feedback!',
        'content':
        'Your feedback has been sent to the NanoFab staff. We will follow up with you as soon as we can.',
    }
    return render(request, 'acknowledgement.html', dictionary)
Example #2
0
def cancel_reservation(request, reservation_id):
	""" Cancel a reservation for a user. """
	reservation = get_object_or_404(Reservation, id=reservation_id)

	reason = parse_parameter_string(request.POST, 'reason')
	response = cancel_the_reservation(reservation=reservation, user_cancelling_reservation=request.user, reason=reason)

	if request.device == 'desktop':
		return response
	if request.device == 'mobile':
		if response.status_code == HTTPStatus.OK:
			return render(request, 'mobile/cancellation_result.html', {'event_type': 'Reservation', 'tool': reservation.tool})
		else:
			return render(request, 'mobile/error.html', {'message': response.content})
Example #3
0
def consultation(request):
    recipient = get_customization('feedback_email_address')
    email_contents = get_media_file_contents('consultation_email.html')
    email_response_contents = get_media_file_contents(
        'consultation_email_response.html')
    if not recipient or not email_contents or not email_response_contents:
        return render(request, 'feedback.html',
                      {'customization_required': True})

    if request.method == 'GET':
        return render(request, 'consultation.html')
    contents = parse_parameter_string(request.POST, 'consultation',
                                      FEEDBACK_MAXIMUM_LENGTH)
    if contents == '':
        return render(request, 'consultation.html')
    dictionary = {
        'contents': contents,
        'user': request.user,
    }

    email = Template(email_contents).render(Context(dictionary))
    send_mail('Consultation Request from ' + str(request.user),
              '',
              request.user.email, [recipient],
              html_message=email)

    response_email = EmailMessage()
    email_body = Template(email_response_contents).render(Context(dictionary))
    storage = get_storage_class()()
    response_email.subject = 'Design Consultation Request Follow Up'
    response_email.from_email = recipient
    response_email.to = [request.user.email]
    response_email.body = email_body
    response_email.content_subtype = "html"
    response_email.attach_file(
        storage.path('design_consultation_template.pptx'))
    response_email.send()

    dictionary = {
        'title':
        'Design Consultation Request',
        'heading':
        'Request Sent!',
        'content':
        'Your design consultation request has been sent to the staff. We will follow up with you as soon as we can.',
    }
    return render(request, 'acknowledgement.html', dictionary)
Example #4
0
def cancel_reservation(request, reservation_id):
    """ Cancel a reservation for a user. """
    reservation = get_object_or_404(Reservation, id=reservation_id)
    response = check_policy_to_cancel_reservation(reservation, request.user)
    # Staff must provide a reason when cancelling a reservation they do not own.
    reason = parse_parameter_string(request.POST, 'reason')
    if reservation.user != request.user and not reason:
        response = HttpResponseBadRequest(
            "You must provide a reason when cancelling someone else's reservation."
        )

    if response.status_code == HTTPStatus.OK:
        # All policy checks passed, so cancel the reservation.
        reservation.cancelled = True
        reservation.cancellation_time = timezone.now()
        reservation.cancelled_by = request.user
        reservation.save()

        if reason:
            dictionary = {
                'staff_member': request.user,
                'reservation': reservation,
                'reason': reason,
                'template_color': bootstrap_primary_color('info')
            }
            email_contents = get_media_file_contents('cancellation_email.html')
            if email_contents:
                cancellation_email = Template(email_contents).render(
                    Context(dictionary))
                reservation.user.email_user('Your reservation was cancelled',
                                            cancellation_email,
                                            request.user.email)

    if request.device == 'desktop':
        return response
    if request.device == 'mobile':
        if response.status_code == HTTPStatus.OK:
            return render(request, 'mobile/cancellation_result.html', {
                'event_type': 'Reservation',
                'tool': reservation.tool
            })
        else:
            return render(request, 'mobile/error.html',
                          {'message': response.content})