def edit_availability(request, display_name): """Edit availability settings.""" user = request.user args = {} created = False if user.groups.filter(Q(name='Mozillians') | Q(name='Alumni')).exists(): raise Http404() try: status = (UserStatus.objects.filter(user=user) .filter(is_unavailable=True).latest('created_on')) except UserStatus.DoesNotExist: status = UserStatus(user=user) created = True initial_data = {'is_replaced': False} if not created: initial_data['expected_date'] = (status.expected_date .strftime('%d %B %Y')) status_form = UserStatusForm(request.POST or None, instance=status, initial=initial_data) email_mentor_form = EmailMentorForm(request.POST or None) if status_form.is_valid(): status_form.save() if created and email_mentor_form.is_valid(): expected_date = (status_form.cleaned_data['expected_date'] .strftime('%d %B %Y')) start_date = (status_form.cleaned_data['start_date'] .strftime('%d %B %Y')) msg = email_mentor_form.cleaned_data['body'] mentee = request.user.get_full_name() template = 'emails/mentor_unavailability_notification.jinja' subject = ('[Mentee {0}] Mentee will be unavailable starting ' 'on {1} until {2}'.format(mentee, start_date, expected_date)) email_mentor_form.send_email(request, subject, msg, template, {'user_status': status}) messages.success(request, 'Request submitted successfully.') return redirect('dashboard') args['status_form'] = status_form args['email_form'] = email_mentor_form args['created'] = created return render(request, 'edit_availability.jinja', args)
def edit_availability(request, display_name): """Edit availability settings.""" user = request.user args = {} created = False if user.groups.filter(Q(name='Mozillians') | Q(name='Alumni')).exists(): raise Http404() try: status = (UserStatus.objects.filter(user=user).filter( is_unavailable=True).latest('created_on')) except UserStatus.DoesNotExist: status = UserStatus(user=user) created = True initial_data = {'is_replaced': False} if not created: initial_data['expected_date'] = ( status.expected_date.strftime('%d %B %Y')) status_form = UserStatusForm(request.POST or None, instance=status, initial=initial_data) email_mentor_form = EmailMentorForm(request.POST or None) if status_form.is_valid(): status_form.save() if created and email_mentor_form.is_valid(): expected_date = ( status_form.cleaned_data['expected_date'].strftime('%d %B %Y')) start_date = ( status_form.cleaned_data['start_date'].strftime('%d %B %Y')) msg = email_mentor_form.cleaned_data['body'] mentee = request.user.get_full_name() template = 'emails/mentor_unavailability_notification.jinja' subject = ('[Mentee {0}] Mentee will be unavailable starting ' 'on {1} until {2}'.format(mentee, start_date, expected_date)) email_mentor_form.send_email(request, subject, msg, template, {'user_status': status}) messages.success(request, 'Request submitted successfully.') return redirect('dashboard') args['status_form'] = status_form args['email_form'] = email_mentor_form args['created'] = created return render(request, 'edit_availability.jinja', args)
def edit_availability(request, display_name): """Edit availability settings.""" user = request.user args = {} created = False if user.groups.filter(name='Mozillians').exists(): raise Http404() if user.userprofile.is_unavailable: status = UserStatus.objects.filter(user=user).latest('created_on') else: status = UserStatus(user=user) created = True initial_data = {'is_replaced': False} if not created: initial_data['expected_date'] = (status.expected_date .strftime('%d %B %Y')) status_form = UserStatusForm(request.POST or None, instance=status, initial=initial_data) email_mentor_form = EmailMentorForm(request.POST or None) if status_form.is_valid(): status_form.save() if created and email_mentor_form.is_valid(): expected_date = status_form.cleaned_data['expected_date'] msg = email_mentor_form.cleaned_data['body'] subject = ('[Rep unavailable] Mentee %s will be unavailable ' 'from %s' % (request.user.get_full_name(), expected_date.strftime('%d %B %Y'))) template = 'emails/mentor_unavailability_notification.txt' subject = ('[Mentee %s] Mentee will be unavailable ' 'until %s' % (request.user.get_full_name(), expected_date.strftime('%d %B %Y'))) email_mentor_form.send_email(request, subject, msg, template, {'user_status': status}) messages.success(request, 'Request submitted successfully.') return redirect('dashboard') args['status_form'] = status_form args['email_form'] = email_mentor_form args['created'] = created return render(request, 'edit_availability.html', args)
def edit_availability(request, display_name): """Edit availability settings.""" user = request.user args = {} created = False if user.groups.filter(name='Mozillians').exists(): raise Http404() if user.userprofile.is_unavailable: status = UserStatus.objects.filter(user=user).latest('created_on') else: status = UserStatus(user=user) created = True initial_data = {'is_replaced': False} if not created: initial_data['expected_date'] = ( status.expected_date.strftime('%d %B %Y')) status_form = UserStatusForm(request.POST or None, instance=status, initial=initial_data) email_mentor_form = EmailMentorForm(request.POST or None) if status_form.is_valid(): status_form.save() if created and email_mentor_form.is_valid(): expected_date = status_form.cleaned_data['expected_date'] msg = email_mentor_form.cleaned_data['body'] subject = ('[Rep unavailable] Mentee %s will be unavailable ' 'from %s' % (request.user.get_full_name(), expected_date.strftime('%d %B %Y'))) template = 'emails/mentor_unavailability_notification.txt' subject = ('[Mentee %s] Mentee will be unavailable ' 'until %s' % (request.user.get_full_name(), expected_date.strftime('%d %B %Y'))) email_mentor_form.send_email(request, subject, msg, template, {'user_status': status}) messages.success(request, 'Request submitted successfully.') return redirect('dashboard') args['status_form'] = status_form args['email_form'] = email_mentor_form args['created'] = created return render(request, 'edit_availability.html', args)
def edit_availability(request, display_name): """Edit availability settings.""" user = request.user args = {} created = False if user.groups.filter(name="Mozillians").exists(): raise Http404() if user.userprofile.is_unavailable: status = UserStatus.objects.filter(user=user).latest("created_on") else: status = UserStatus(user=user) created = True initial_data = {"is_replaced": False} if not created: initial_data["expected_date"] = status.expected_date.strftime("%d %B %Y") status_form = UserStatusForm(request.POST or None, instance=status, initial=initial_data) email_mentor_form = EmailMentorForm(request.POST or None) if status_form.is_valid(): status_form.save() if created and email_mentor_form.is_valid(): expected_date = status_form.cleaned_data["expected_date"] msg = email_mentor_form.cleaned_data["body"] subject = "[Rep unavailable] Mentee %s will be unavailable " "from %s" % ( request.user.get_full_name(), expected_date.strftime("%d %B %Y"), ) template = "emails/mentor_unavailability_notification.txt" subject = "[Mentee %s] Mentee will be unavailable " "until %s" % ( request.user.get_full_name(), expected_date.strftime("%d %B %Y"), ) email_mentor_form.send_email(request, subject, msg, template, {"user_status": status}) messages.success(request, "Request submitted successfully.") return redirect("dashboard") args["status_form"] = status_form args["email_form"] = email_mentor_form args["created"] = created return render(request, "edit_availability.html", args)