Пример #1
0
def test_set_format():
    duration = Duration(days=7,
                        hours=12,
                        minutes=47,
                        seconds=56)
    duration.set_format("{0:0>2}:{1:0>2}:{2:0>2}:{3:0>2}")
    nt.assert_equal("07:12:47:56", duration.__str__())
Пример #2
0
class ClassFactory(DjangoModelFactory):
    class Meta:
        model = conf.Class

    e_title = Sequence(lambda x: "Test Class #%d" % x)
    e_description = LazyAttribute(lambda a: "Description for %s" % a.e_title)
    b_title = Sequence(lambda x: "Test Class #%d" % x)
    b_description = LazyAttribute(lambda a: "Description for %s" % a.e_title)

    duration = Duration(hours=1)
    teacher = SubFactory(PersonaFactory)
    minimum_enrollment = 1
    maximum_enrollment = 20
    organization = "Some Organization"
    type = "Lecture"
    fee = 0
    length_minutes = 60
    history = LazyAttribute(lambda a: "History for test Class %s" % a.e_title)
    run_before = LazyAttribute(
        lambda a: "run_before for test Class %s" % a.e_title)
    schedule_constraints = LazyAttribute(
        lambda a: "schedule constraints for test Class %s" % a.e_title)
    space_needs = ''
    physical_restrictions = LazyAttribute(
        lambda a: "physical restrictions for test Class %s" % a.e_title)
    multiple_run = 'No'
    b_conference = SubFactory(ConferenceFactory)
    e_conference = SubFactory(ConferenceFactory)
Пример #3
0
class ShowFactory(DjangoModelFactory):
    class Meta:
        model = conf.Show

    e_title = Sequence(lambda n: 'Test Show%d' % n)
    e_description = 'Test Description'
    duration = Duration(hours=1)
    e_conference = SubFactory(ConferenceFactory)
Пример #4
0
def cal_times_for_conf(conference, day_name=None):
    from gbe.functions import get_conference_days  # late import, circularity
    days = get_conference_days(conference)

    if not days.exists():
        return get_default_range()
    if day_name:
        selected_day = select_day(days, day_name)
        if not selected_day:
            return get_default_range()
        day = date_to_datetime(selected_day.day)
        if day:
            return day + Duration(hours=8), day + Duration(hours=28)

    else:
        first_day = date_to_datetime(days.first().day)
        last_day = date_to_datetime(days.last().day)
        return (first_day + Duration(hours=8), last_day + Duration(hours=28))
Пример #5
0
class EventFactory(DjangoModelFactory):
    class Meta:
        model = conf.Event

    e_title = Sequence(lambda x: "Test Event #%d" % x)
    e_description = LazyAttribute(lambda a: "Description for %s" % a.e_title)
    blurb = LazyAttribute(lambda a: "Blurb for %s" % a.e_title)
    duration = Duration(hours=2)
    e_conference = SubFactory(ConferenceFactory)
Пример #6
0
class GenericEventFactory(DjangoModelFactory):
    class Meta:
        model = conf.GenericEvent

    e_title = Sequence(lambda n: 'Test Generic Event %d' % n)
    e_description = LazyAttribute(lambda a: "Description for %s" % a.e_title)
    duration = Duration(hours=1)
    type = 'Special'
    volunteer_type = SubFactory(AvailableInterestFactory)
    e_conference = SubFactory(ConferenceFactory)
Пример #7
0
class StageInfoFactory(DjangoModelFactory):
    class Meta:
        model = conf.StageInfo

    act_duration = Duration(minutes=5)
    intro_text = "intro text field for test StageInfo object"
    confirm = True
    set_props = False
    cue_props = False
    clear_props = False
    notes = "Notes field for test StageInfo object"
Пример #8
0
class AudioInfoFactory(DjangoModelFactory):
    class Meta:
        model = conf.AudioInfo

    track_title = Sequence(lambda n: 'Test Track Title %d' % n)
    track_artist = Sequence(lambda n: 'Test Track Artist %d' % n)
    #  no track for now  - do we mock this, or what?
    track_duration = Duration(minutes=5)
    need_mic = True
    own_mic = False
    notes = "Notes about test AudioInfo object."
    confirm_no_music = False
Пример #9
0
 def post(self, request, *args, **kwargs):
     more_view = "edit_event"
     context = self.groundwork(request, args, kwargs)
     if self.event_type == "show":
         context['second_form'] = ShowBookingForm(request.POST)
         more_view = "edit_show"
     else:
         context['second_form'] = GenericBookingForm(request.POST)
     context['scheduling_form'] = ScheduleOccurrenceForm(
         request.POST,
         conference=self.conference)
     context['worker_formset'] = self.make_formset(
         event_settings[self.event_type]['roles'],
         post=request.POST)
     if validate_perms(request, ('Ticketing - Admin',), require=False):
         context['tickets'] = LinkBPTEventForm(request.POST, initial={
             'conference': self.conference, })
     if context['second_form'].is_valid(
             ) and context['scheduling_form'].is_valid(
             ) and self.is_formset_valid(context['worker_formset']) and (
             not context['tickets'] or context['tickets'].is_valid()):
         new_event = context['second_form'].save(commit=False)
         new_event.duration = Duration(
             minutes=context['scheduling_form'].cleaned_data[
                 'duration']*60)
         new_event.save()
         response = self.book_event(context['scheduling_form'],
                                    context['worker_formset'],
                                    new_event)
         if context['tickets']:
             self.setup_ticket_links(request, new_event, context['tickets'])
         success = self.finish_booking(
             request,
             response,
             context['scheduling_form'].cleaned_data['day'].pk)
         if success:
             if request.POST.get(
                     'set_event') == 'More...':
                 return HttpResponseRedirect(
                     "%s?volunteer_open=True&rehearsal_open=True" %
                     reverse(more_view,
                             urlconf='gbe.scheduling.urls',
                             args=[self.conference.conference_slug,
                                   response.occurrence.pk]))
             else:
                 return success
     return render(request, self.template, context)
Пример #10
0
 def setUp(self):
     self.context = VolunteerContext(event=GenericEventFactory())
     self.context.sched_event.max_volunteer = 7
     self.context.sched_event.save()
     self.context.event.duration = Duration(hours=1, minutes=30)
     self.context.event.save()
     self.room = self.context.room
     self.staff_lead = self.context.set_staff_lead()
     self.extra_day = ConferenceDayFactory(
         conference=self.context.conference,
         day=self.context.conf_day.day + timedelta(days=1))
     self.url = reverse(
         self.view_name,
         args=[self.context.conference.conference_slug,
               self.context.opp_event.pk],
         urlconf='gbe.scheduling.urls')
     self.client = Client()
     self.privileged_user = ProfileFactory().user_object
     grant_privilege(self.privileged_user, 'Scheduling Mavens')
Пример #11
0
def process_post_response(request,
                          slug,
                          item,
                          start_success_url,
                          next_step,
                          occurrence_id,
                          additional_validity=True,
                          people_forms=[]):
    success_url = start_success_url
    context = {}
    response = None
    context['event_form'] = EventBookingForm(request.POST, instance=item)
    context['scheduling_form'] = ScheduleOccurrenceForm(
        request.POST,
        conference=item.e_conference,
        open_to_public=event_settings[item.type.lower()]['open_to_public'])

    if context['event_form'].is_valid(
    ) and context['scheduling_form'].is_valid() and additional_validity:
        new_event = context['event_form'].save(commit=False)
        new_event.duration = Duration(
            minutes=context['scheduling_form'].cleaned_data['duration'] * 60)
        new_event.save()
        response = update_event(context['scheduling_form'], occurrence_id,
                                people_forms)
        if request.POST.get('edit_event', 0) != "Save and Continue":
            success_url = "%s?%s-day=%d&filter=Filter&new=%s" % (
                reverse('manage_event_list',
                        urlconf='gbe.scheduling.urls',
                        args=[slug]),
                slug,
                context['scheduling_form'].cleaned_data['day'].pk,
                str([occurrence_id]),
            )
        else:
            success_url = "%s?%s=True" % (success_url, next_step)
    else:
        context['start_open'] = True
    return context, success_url, response
Пример #12
0
def test_mod_by_bad_dividend():
    duration = Duration(seconds=25)
    foo = set([1, 2, 3])
    nt.assert_raises(TypeError, duration.__mod__, duration, foo)
Пример #13
0
def test_mod_by_int():
    duration1 = Duration(minutes=5)
    result = duration1 % 120
    nt.assert_equal(1, result.minutes())
Пример #14
0
def test_minutes():
    duration = Duration(seconds=125)
    nt.assert_equal(2, duration.minutes())
Пример #15
0
def test_mod_by_duration():
    duration1 = Duration(minutes=5)
    duration2 = Duration(minutes=2)
    result = duration1 % duration2
    nt.assert_equal(1, result.minutes())
Пример #16
0
def test_floordiv_by_duration():
    duration = Duration(minutes=7200)
    dividend = Duration(minutes=3600)
    quotient = duration // dividend
    nt.assert_equal(2, quotient)
Пример #17
0
def test_divmod_by_int():
    duration = Duration(500)
    nt.assert_equal((duration / 50, duration % 50),
                    duration.__divmod__(50))
Пример #18
0
def test_default_string_representation():
    duration = Duration(hours=12, minutes=47, seconds=56)
    nt.assert_equal("12:47:56", duration.__str__())
Пример #19
0
def test_total_minutes():
    duration = Duration(hours=3, minutes=24)
    nt.assert_equal(204, duration.total_minutes())
Пример #20
0
def test_date_time_range_contains_date_time_range():
    sub_range = DateTimeRange(duration=Duration(days=1),
                              endtime=datetime(2015, 5, 5))
    containing_range = DateTimeRange(starttime=datetime(2015, 1, 1),
                                     endtime=datetime(2016, 1, 1))
    nt.assert_true(sub_range in containing_range)
Пример #21
0
    def post(self, request, *args, **kwargs):
        working_class = None
        context = self.groundwork(request, args, kwargs)
        context['second_form'] = PickClassForm(
            request.POST, initial={'conference': self.conference})
        context['third_title'] = "Make New Class"
        if 'pick_class' in request.POST.keys(
        ) and context['second_form'].is_valid():
            if context['second_form'].cleaned_data['accepted_class']:
                working_class = context['second_form'].cleaned_data[
                    'accepted_class']
                context['third_title'] = "Book Class:  %s" % (
                    working_class.e_title)
                context['third_form'] = ClassBookingForm(
                    instance=working_class)
                duration = working_class.duration.hours() + float(
                    working_class.duration.minutes()) / 60
                context['scheduling_info'] = get_scheduling_info(working_class)
            else:
                context['third_form'] = ClassBookingForm()
                duration = 1
            context['scheduling_form'] = ScheduleOccurrenceForm(
                conference=self.conference,
                open_to_public=True,
                initial={
                    'duration': duration,
                })
            context['scheduling_form'].fields[
                'max_volunteer'].widget = HiddenInput()
            context['worker_formset'] = self.make_formset(working_class)

        elif 'set_class' in request.POST.keys(
        ) and 'eventitem_id' in request.POST.keys():
            if request.POST['eventitem_id']:
                working_class = get_object_or_404(
                    Class, eventitem_id=request.POST['eventitem_id'])
                context['third_title'] = "Book Class:  %s" % (
                    working_class.e_title)
                context['third_form'] = ClassBookingForm(
                    request.POST, instance=working_class)
                context['scheduling_info'] = get_scheduling_info(working_class)
            else:
                context['third_form'] = ClassBookingForm(request.POST)
            context['second_form'] = PickClassForm(
                initial={
                    'conference': self.conference,
                    'accepted_class': working_class
                })
            context['scheduling_form'] = ScheduleOccurrenceForm(
                request.POST, conference=self.conference)
            context['scheduling_form'].fields[
                'max_volunteer'].widget = HiddenInput()
            context['worker_formset'] = self.make_formset(working_class,
                                                          post=request.POST)
            if context['third_form'].is_valid() and context[
                    'scheduling_form'].is_valid() and self.is_formset_valid(
                        context['worker_formset']):
                working_class = context['third_form'].save(commit=False)
                working_class.duration = Duration(
                    minutes=context['scheduling_form'].cleaned_data['duration']
                    * 60)
                if not hasattr(working_class, 'teacher'):
                    teacher = None
                    for form in context['worker_formset']:
                        if form.cleaned_data['worker']:
                            teacher = form.cleaned_data['worker']
                            break
                    if teacher:
                        working_class.teacher = teacher
                    else:
                        user_message = UserMessage.objects.get_or_create(
                            view=self.__class__.__name__,
                            code="NEED_LEADER",
                            defaults={
                                'summary':
                                "Need Leader for Class",
                                'description':
                                "You must select at least " +
                                "one person to run this class."
                            })
                        messages.error(request, user_message[0].description)
                        return render(request, self.template, context)
                    working_class.e_conference = self.conference
                    working_class.b_conference = self.conference

                working_class.save()
                response = self.book_event(context['scheduling_form'],
                                           context['worker_formset'],
                                           working_class)
                success = self.finish_booking(
                    request, response,
                    context['scheduling_form'].cleaned_data['day'].pk)
                if success:
                    return success
        return render(request, self.template, context)
Пример #22
0
def test_hours():
    duration = Duration(seconds=7215)
    nt.assert_equal(2, duration.hours())
Пример #23
0
def test_default_string_representation():
    duration = Duration(hours=12,
                        minutes=47,
                        seconds=56)
    nt.assert_equal("12:47:56", duration.__str__())
Пример #24
0
def test_divmod_by_int():
    duration1 = Duration(500)
    duration2 = Duration(10)
    nt.assert_equal((duration1 / duration2, duration1 % duration2),
                    duration1.__divmod__(duration2))
Пример #25
0
def test_divmod_by_int():
    duration = Duration(500)
    nt.assert_equal((duration / 50, duration % 50), duration.__divmod__(50))
Пример #26
0
def test_hours():
    duration = Duration(seconds=7215)
    nt.assert_equal(2, duration.hours())
Пример #27
0
def test_divmod_by_int():
    duration1 = Duration(500)
    duration2 = Duration(10)
    nt.assert_equal((duration1 / duration2, duration1 % duration2),
                    duration1.__divmod__(duration2))
Пример #28
0
def test_floordiv_by_int():
    duration = Duration(seconds=7200)
    quotient = duration // 2
    nt.assert_equal(1, quotient.hours())
Пример #29
0
def test_set_format():
    duration = Duration(days=7, hours=12, minutes=47, seconds=56)
    duration.set_format("{0:0>2}:{1:0>2}:{2:0>2}:{3:0>2}")
    nt.assert_equal("07:12:47:56", duration.__str__())
Пример #30
0
def test_minutes():
    duration = Duration(seconds=125)
    nt.assert_equal(2, duration.minutes())
Пример #31
0
 def clean_duration(self):
     data = Duration(minutes=self.cleaned_data['duration']*60)
     return data
Пример #32
0
 def set_valid_form(self, request):
     self.bid_object.duration = Duration(
         minutes=self.bid_object.length_minutes)
     self.bid_object.b_conference = self.conference
     self.bid_object.e_conference = self.conference
     self.bid_object = self.form.save(commit=True)
Пример #33
0
def test_date_time_range_contains_datetime():
    moment = datetime(2015, 6, 6, 6, 0, 0)
    range = DateTimeRange(starttime=datetime(2015, 1, 1),
                          duration=Duration(days=365))
    nt.assert_true(moment in range)
Пример #34
0
def test_total_minutes():
    duration = Duration(hours=3, minutes=24)
    nt.assert_equal(204, duration.total_minutes())
Пример #35
0
 def post(self, request, *args, **kwargs):
     working_class = None
     context = self.groundwork(request, args, kwargs)
     context['second_form'] = PickVolunteerTopicForm(
         request.POST, initial={'conference': self.conference})
     context['third_title'] = "Make New Volunteer Opportunity"
     if 'pick_topic' in request.POST.keys(
     ) and context['second_form'].is_valid():
         if context['second_form'].cleaned_data[
                 'volunteer_topic'] and 'staff_' in context[
                     'second_form'].cleaned_data['volunteer_topic']:
             staff_area_id = context['second_form'].cleaned_data[
                 'volunteer_topic'].split("staff_")[1]
             return HttpResponseRedirect(
                 "%s?volunteer_open=True" %
                 reverse('edit_staff',
                         urlconf='gbe.scheduling.urls',
                         args=[staff_area_id]))
         elif context['second_form'].cleaned_data['volunteer_topic']:
             occurrence_id = context['second_form'].cleaned_data[
                 'volunteer_topic']
             return HttpResponseRedirect("%s?volunteer_open=True" % reverse(
                 'edit_event',
                 urlconf='gbe.scheduling.urls',
                 args=[self.conference.conference_slug, occurrence_id]))
         else:
             context['third_title'] = "Make New Volunteer Opportunity"
             context['third_form'] = GenericBookingForm(
                 initial={
                     'e_conference': self.conference,
                     'type': "Volunteer"
                 })
             context['scheduling_form'] = ScheduleOccurrenceForm(
                 conference=self.conference,
                 initial={
                     'duration': 1,
                     'max_volunteer': 1
                 })
             context['worker_formset'] = self.make_formset(self.roles)
     elif 'set_opp' in request.POST.keys():
         context['third_title'] = "Make New Volunteer Opportunity"
         context['third_form'] = GenericBookingForm(request.POST)
         context['second_form'] = PickVolunteerTopicForm(
             initial={'conference': self.conference})
         context['scheduling_form'] = ScheduleOccurrenceForm(
             request.POST, conference=self.conference)
         context['worker_formset'] = self.make_formset(self.roles,
                                                       post=request.POST)
         if context['third_form'].is_valid() and context[
                 'scheduling_form'].is_valid() and self.is_formset_valid(
                     context['worker_formset']):
             volunteer_event = context['third_form'].save(commit=False)
             volunteer_event.duration = Duration(
                 minutes=context['scheduling_form'].cleaned_data['duration']
                 * 60)
             volunteer_event.save()
             response = self.book_event(context['scheduling_form'],
                                        context['worker_formset'],
                                        volunteer_event)
             success = self.finish_booking(
                 request, response,
                 context['scheduling_form'].cleaned_data['day'].pk)
             if success:
                 return success
     return render(request, self.template, context)
Пример #36
0
def get_default_range():
    today = date_to_datetime(date.today())
    return (today + Duration(hours=8), today + Duration(hours=28))