Exemplo n.º 1
0
def safety(request):
	dictionary = {}
	if request.method == 'POST':
		form = SafetyIssueCreationForm(request.user, data=request.POST)
		if form.is_valid():
			issue = form.save()
			send_safety_email_notification(request, issue)
			create_safety_notification(issue)
			dictionary = {
				'title': 'Concern received',
				'heading': 'Your safety concern was sent to NanoFab staff and will be addressed promptly',
			}
			if form.cleaned_data['post_alert']:
				now = timezone.now()
				alert_title = "Alert: Cleanroom may not be safe for entry"
				alert_preface = f'On {format_datetime(now)} {issue.reporter.get_full_name()} reported the following issue:\n'
				alert_contents = (alert_preface + issue.concern)
				safety_alert = Alert(title=alert_title, contents=alert_contents, creator=issue.reporter, debut_time=now)
				safety_alert.save()
				send_alert_emails(safety_alert)
				dictionary = {
					'title': 'Concern received',
					'heading': 'Your safety concern was sent to NanoFab staff and will be addressed promptly. An alert has been posted, and all labmembers have been emailed.',
				}
			return render(request, 'acknowledgement.html', dictionary)
	tickets = SafetyIssue.objects.filter(resolved=False).order_by('-creation_time')
	if not request.user.is_staff:
		tickets = tickets.filter(visible=True)
	dictionary['tickets'] = tickets
	dictionary['safety_introduction'] = get_media_file_contents('safety_introduction.html')
	dictionary['notifications'] = get_notifications(request.user, SafetyIssue)
	return render(request, 'safety/safety.html', dictionary)
Exemplo n.º 2
0
def safety(request):
	dictionary = {}
	if request.method == 'POST':
		form = SafetyIssueCreationForm(request.user, data=request.POST)
		if form.is_valid():
			issue = form.save()
			send_safety_email_notification(request, issue)
			dictionary['title'] = 'Concern received'
			dictionary['heading'] = 'Your safety concern was sent to NanoFab staff and will be addressed promptly'
			create_safety_notification(issue)
			return render(request, 'acknowledgement.html', dictionary)
	tickets = SafetyIssue.objects.filter(resolved=False).order_by('-creation_time')
	if not request.user.is_staff:
		tickets = tickets.filter(visible=True)
	dictionary['tickets'] = tickets
	dictionary['safety_introduction'] = get_media_file_contents('safety_introduction.html')
	dictionary['notifications'] = get_notifications(request.user, SafetyIssue)
	return render(request, 'safety/safety.html', dictionary)