示例#1
0
 def test_invalid_timespan(self):
     mentor = UserFactory.create()
     user = UserFactory.create(userprofile__mentor=mentor)
     date = get_date(weeks=15)
     data = {'expected_date': date}
     form = UserStatusForm(data, instance=UserStatus(user=user))
     ok_(not form.is_valid())
     ok_('expected_date' in form.errors)
示例#2
0
 def test_expected_date_before_start_date(self):
     mentor = UserFactory.create()
     user = UserFactory.create(userprofile__mentor=mentor)
     start_date = get_date(4)
     expected_date = get_date(days=2)
     data = {'start_date': start_date, 'expected_date': expected_date}
     form = UserStatusForm(data, instance=UserStatus(user=user))
     ok_(not form.is_valid())
     ok_('expected_date' in form.errors)
示例#3
0
文件: test_forms.py 项目: seocam/remo
 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())
示例#4
0
 def test_expected_date_before_start_date(self):
     mentor = UserFactory.create()
     user = UserFactory.create(userprofile__mentor=mentor)
     start_date = get_date(4)
     expected_date = get_date(days=2)
     data = {'start_date': start_date,
             'expected_date': expected_date}
     form = UserStatusForm(data, instance=UserStatus(user=user))
     ok_(not form.is_valid())
     ok_('expected_date' in form.errors)
示例#5
0
 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())
示例#6
0
 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())
示例#7
0
文件: test_forms.py 项目: seocam/remo
 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)
示例#8
0
 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)
示例#9
0
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)
示例#10
0
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)
示例#11
0
文件: views.py 项目: caktus/remo
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)
示例#12
0
文件: views.py 项目: TheTeraByte/remo
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)
示例#13
0
 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)
示例#14
0
文件: views.py 项目: ppapadeas/remo
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)