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)
def test_base(self): user = UserFactory.create() date = get_date() data = {'expected_date': date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(form.is_valid()) db_obj = form.save() eq_(db_obj.expected_date, get_date()) eq_(db_obj.user.get_full_name(), user.get_full_name())
def test_base(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) date = get_date(days=1) data = {"expected_date": date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(form.is_valid()) db_obj = form.save() eq_(db_obj.expected_date, get_date(days=1)) eq_(db_obj.user.get_full_name(), user.get_full_name())
def test_base(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) date = get_date(days=1) data = {'expected_date': date} form = UserStatusForm(data, instance=UserStatus(user=user)) ok_(form.is_valid()) db_obj = form.save() eq_(db_obj.expected_date, get_date(days=1)) eq_(db_obj.user.get_full_name(), user.get_full_name())
def remove_unavailability_status(self): user = UserFactory.create() date = get_date() data = {'expected_date': date} user_status = UserStatusFactory.create(user=user, expected_date=date) form = UserStatusForm(data, instance=user_status) ok_(form.is_valid()) ok_(not user_status.end_date) db_obj = form.save() eq_(db_obj.expected_date, get_date()) eq_(db_obj.user.get_full_name(), user.get_full_name()) ok_(db_obj.return_date)
def remove_unavailability_status(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) date = get_date() data = {'expected_date': date} user_status = UserStatusFactory.create(user=user, expected_date=date) form = UserStatusForm(data, instance=user_status) ok_(form.is_valid()) ok_(not user_status.end_date) db_obj = form.save() eq_(db_obj.expected_date, get_date()) eq_(db_obj.user.get_full_name(), user.get_full_name()) ok_(db_obj.return_date)
def remove_unavailability_status(self): mentor = UserFactory.create() user = UserFactory.create(userprofile__mentor=mentor) start_date = get_date() expected_date = get_date(days=1) data = {'start_date': start_date, 'expected_date': expected_date} user_status = UserStatusFactory.create(user=user, expected_date=expected_date, start_date=start_date) form = UserStatusForm(data, instance=user_status) ok_(form.is_valid()) ok_(not user_status.end_date) db_obj = form.save() eq_(db_obj.expected_date, get_date()) eq_(db_obj.user.get_full_name(), user.get_full_name()) ok_(db_obj.return_date)