예제 #1
0
def timeslot_offset_options(
        interval=swingtime_settings.TIMESLOT_INTERVAL,
        start_time=swingtime_settings.TIMESLOT_START_TIME,
        end_delta=swingtime_settings.TIMESLOT_END_TIME_DURATION,
        fmt=swingtime_settings.TIMESLOT_TIME_FORMAT):
    '''
    Create a list of time slot options for use in swingtime forms.

    The list is comprised of 2-tuples containing the number of seconds since the
    start of the day and a 12-hour temporal representation of that offset.

    '''
    dt = datetime.combine(date.today(), time(0))
    dtstart = datetime.combine(dt.date(), start_time)
    dtend = dtstart + end_delta
    options = []

    delta = utils.time_delta_total_seconds(dtstart - dt)
    seconds = utils.time_delta_total_seconds(interval)
    while dtstart <= dtend:
        options.append((delta, dtstart.strftime(fmt)))
        dtstart += interval
        delta += seconds

    return options
예제 #2
0
def timeslot_offset_options(
    interval=swingtime_settings.TIMESLOT_INTERVAL,
    start_time=swingtime_settings.TIMESLOT_START_TIME,
    end_delta=swingtime_settings.TIMESLOT_END_TIME_DURATION,
    fmt=swingtime_settings.TIMESLOT_TIME_FORMAT
):
    '''
    Create a list of time slot options for use in swingtime forms.

    The list is comprised of 2-tuples containing the number of seconds since the
    start of the day and a 12-hour temporal representation of that offset.

    '''
    dt = datetime.combine(date.today(), time(0))
    dtstart = datetime.combine(dt.date(), start_time)
    dtend = dtstart + end_delta
    options = []

    delta = utils.time_delta_total_seconds(dtstart - dt)
    seconds = utils.time_delta_total_seconds(interval)
    while dtstart <= dtend:
        options.append((delta, dtstart.strftime(fmt)))
        dtstart += interval
        delta += seconds

    return options
예제 #3
0
def timeslot_offset_options(
    type=False,
    interval=False,
    start_time=False,
    end_time=False,
    fmt=swingtime_settings.TIMESLOT_TIME_FORMAT,
):
    '''
    Create a list of time slot options for use in swingtime forms.
    
    The list is comprised of 2-tuples containing the number of seconds since the
    start of the day and a 12-hour temporal representation of that offset.

    type : string start or end
    interval : int 
    start_time : string format 08:45 or 08:00
    end_time : string format 20:45 or 20:00
    
    '''
    dt = datetime.combine(date.today(), time(0))
    interval = timedelta(minutes=interval)

    H, M = start_time.split(",")
    dtstart = datetime.combine(dt.date(), time(int(H), int(M)))

    H, M = end_time.split(",")
    dtend = datetime.combine(dt.date(), time(int(H), int(M)))

    options = []
    delta = utils.time_delta_total_seconds(dtstart - dt)
    seconds = utils.time_delta_total_seconds(interval)

    while dtstart <= dtend:
        options.append((delta, dtstart.strftime('%H:%M')))
        dtstart += interval
        delta += seconds

    if type == 'start':  # remove last
        del options[-1]

    if type == 'end':  # remove first
        del options[0]

    return options
예제 #4
0
def timeslot_offset_options(
    type=False,
    interval=False,
    start_time=False,
    end_time=False,
    fmt=swingtime_settings.TIMESLOT_TIME_FORMAT,
):
    '''
    Create a list of time slot options for use in swingtime forms.
    
    The list is comprised of 2-tuples containing the number of seconds since the
    start of the day and a 12-hour temporal representation of that offset.

    type : string start or end
    interval : int 
    start_time : string format 08:45 or 08:00
    end_time : string format 20:45 or 20:00
    
    '''
    dt = datetime.combine(date.today(), time(0))
    interval = timedelta(minutes=interval)

    H,M = start_time.split(",")
    dtstart = datetime.combine(dt.date(), time(int(H), int(M)) )

    H,M = end_time.split(",")
    dtend = datetime.combine(dt.date(), time(int(H), int(M)) )

    options = []
    delta = utils.time_delta_total_seconds(dtstart - dt)
    seconds = utils.time_delta_total_seconds(interval)

    while dtstart <= dtend:
        options.append((delta, dtstart.strftime('%H:%M')))
        dtstart += interval
        delta += seconds

    if type == 'start': # remove last
        del options[-1]

    if type == 'end': # remove first
        del options[0]

    return options
예제 #5
0
    ('until', _(u'Until date')),
)

ISO_WEEKDAYS_MAP = (
    None,
    rrule.MO,
    rrule.TU,
    rrule.WE,
    rrule.TH,
    rrule.FR,
    rrule.SA,
    rrule.SU
)

MINUTES_INTERVAL = swingtime_settings.TIMESLOT_INTERVAL.seconds // 60
SECONDS_INTERVAL = utils.time_delta_total_seconds(swingtime_settings.DEFAULT_OCCURRENCE_DURATION)


def timeslot_options(interval=swingtime_settings.TIMESLOT_INTERVAL,
    start_time=swingtime_settings.TIMESLOT_START_TIME,
    end_delta=swingtime_settings.TIMESLOT_END_TIME_DURATION,
    fmt=swingtime_settings.TIMESLOT_TIME_FORMAT):
    """
    Create a list of time slot options for use in swingtime forms.

    The list is comprised of 2-tuples containing a 24-hour time value and a
    12-hour temporal representation of that offset.
    """
    dt = datetime.combine(date.today(), time(0))
    dtstart = datetime.combine(dt.date(), start_time)
    dtend = dtstart + end_delta
예제 #6
0
    (rrule.DAILY, _('Day(s)')),
    (rrule.WEEKLY, _('Week(s)')),
    (rrule.MONTHLY, _('Month(s)')),
    (rrule.YEARLY, _('Year(s)')),
)

REPEAT_CHOICES = (
    ('count', _('By count')),
    ('until', _('Until date')),
)

ISO_WEEKDAYS_MAP = (None, rrule.MO, rrule.TU, rrule.WE, rrule.TH, rrule.FR,
                    rrule.SA, rrule.SU)

MINUTES_INTERVAL = swingtime_settings.TIMESLOT_INTERVAL.seconds // 60
SECONDS_INTERVAL = utils.time_delta_total_seconds(
    swingtime_settings.DEFAULT_OCCURRENCE_DURATION)


#-------------------------------------------------------------------------------
def timeslot_options(interval=swingtime_settings.TIMESLOT_INTERVAL,
                     start_time=swingtime_settings.TIMESLOT_START_TIME,
                     end_delta=swingtime_settings.TIMESLOT_END_TIME_DURATION,
                     fmt=swingtime_settings.TIMESLOT_TIME_FORMAT):
    '''
    Create a list of time slot options for use in swingtime forms.

    The list is comprised of 2-tuples containing a 24-hour time value and a
    12-hour temporal representation of that offset.

    '''
    dt = datetime.combine(date.today(), time(0))
예제 #7
0
def daily_occurrences(request, year=1, month=1, day=None, place=None):
    """
        return JSON
        filter permission : professional or secretary
    """
    occurrences = schedule_occurrences(request, year, month, day)

    i = 0
    groups = []
    array = {} #json

    date = datetime.strptime(('%s/%s/%s' % (year, month, day)), "%Y/%m/%d")

    if place == None:
        # Possible to exist more than one place as matriz or none, filter and get first element
        if Place.objects.filter( place_type=1, organization=request.user.get_profile().org_active):
            place = Place.objects.filter(place_type=1, organization=request.user.get_profile().org_active)[0].id
        # non exist a matriz place
        else:
            place = Place.objects.filter(organization=request.user.get_profile().org_active)[0].id

    array['util'] = {
        'date': ('%s-%s-%s' % (year, month, day)),
        'date_field': ('%s/%s/%s' % (year, month, day)),
        u'str_date': '%s, %s %s %s %s %s' % (date.strftime("%A").decode('utf-8').capitalize(), date.strftime("%d"), _('of'), date.strftime("%B").decode('utf-8'), _('of'), date.strftime("%Y")),
        'next_day': (date + timedelta(days=+1)).strftime("%Y/%m/%d"),
        'prev_day': (date + timedelta(days=-1)).strftime("%Y/%m/%d"),
        'weekday': date.weekday(),
        'place': place,
    }
    
    """
        secretary and/or admin
            see all occurrences
        professional and/or student
            see event if owner of it OR reservado
    """
    # to check each occurence permission
    for o in occurrences:

        have_same_group = False
        if hasattr(o.event.referral.group, 'id'):
            if '%s-%s-%s' % (o.event.referral.group.id, o.room_id, o.start_time.strftime('%H:%M:%S')) in groups:
                have_same_group = True

        if not have_same_group:
            range = o.end_time-o.start_time
            rowspan = range.seconds/time_delta_total_seconds( timedelta(minutes=int(request.user.get_profile().org_active.time_slot_schedule)) ) 

        if show_event_(request, o): # to show full data
            array[i] = {
                'id': o.id,
                'event_id': o.event.id,
                'room': o.room_id,
                'place': o.room.place_id,
                'room_name': (u"%s" % o.room),
                'service_id':o.event.referral.service.id,
                'group': (u"%s" % '' if not hasattr(o.event.referral.group, 'id') else o.event.referral.group.description),
                'group_id': '' if not hasattr(o.event.referral.group, 'id') else o.event.referral.group.id,
                'service': u"%s" % o.event.referral,
                'color':o.event.referral.service.color,
                'font_color':o.event.referral.service.font_color,
                'start_time': o.start_time.strftime('%H:%M:%S'),
                'end_time': o.end_time.strftime('%H:%M:%S'),
                'rowspan': rowspan,
                'online': o.is_online,
            }
        else: # to show as reservado
            array[i] = {
                'room': o.room_id,
                'room_name': (u"%s" % o.room),
                'place': o.room.place_id,
                'group': u"",
                'service': "RESERVADO",
                'service_id':o.event.referral.service.id,
                'color':o.event.referral.service.color,
                'font_color':o.event.referral.service.font_color,
                'start_time': o.start_time.strftime('%H:%M:%S'),
                'end_time': o.end_time.strftime('%H:%M:%S'),
                'rowspan': rowspan,
            }
        
        array[i]['professional'] = {}
        array[i]['client'] = {}
        array[i]['device'] = {}

        if show_event_(request, o): # to show full data

            sub_count = 0
            for p in o.event.referral.professional.all():
                array[i]['professional'][sub_count] = ({'id':p.id, 'name':p.person.name})
                sub_count = sub_count + 1

            sub_count = 0
            for c in o.event.referral.client.all():
                array[i]['client'][sub_count] = ({'id':c.id, 'name':c.person.name})
                sub_count = sub_count + 1
        
            sub_count = 0
            if not o.scheduleoccurrence.was_confirmed():
                device_list = o.device.all()
            else:
                device_list = o.occurrenceconfirmation.device.all()

            for o in device_list:
                array[i]['device'][sub_count] = ({'id':o.id, 'name': ("%s - %s - %s" % (o.device.description, o.brand, o.model)) })
                sub_count = sub_count + 1

            # concat group id, room id and start time to register in a list and verify in the begin of the loop if the same
            # occurrence already has been registered
            if hasattr(o, 'event') and hasattr(o.event.referral.group, 'id'):
                groups.append('%s-%s-%s' % (o.event.referral.group.id, o.room_id, o.start_time.strftime('%H:%M:%S')))

        i = i + 1

    array['util']['occurrences_total'] = i
    array = simplejson.dumps(array)
    
    return HttpResponse(array, mimetype='application/json')
예제 #8
0
def add_event(
        request, 
        template='schedule/schedule_form.html',
        event_form_class=ReferralForm,
        recurrence_form_class=ScheduleOccurrenceForm,
        redirect_to = None
    ):

    # have to contains dtstart variable in URL. URL from schedule have to contains date and time data.
    if not 'dtstart' in request.GET:
        return http.HttpResponseRedirect('/schedule/')

    # get from url
    dtstart = parser.parse( request.GET['dtstart'] )
    room = get_object_or_None(Room, pk=request.GET.get('room'), place__organization=request.user.get_profile().org_active)
    client = get_object_or_None(Client, pk=request.GET.get('client'), person__organization=request.user.get_profile().org_active)
    referral = get_object_or_None(Referral, pk=request.GET.get('referral'), service__organization=request.user.get_profile().org_active)
    event_form = event_form_class

    if request.POST:

        # instance form
        recurrence_form = recurrence_form_class(request, room.place, request.POST)

        # no errors found, form is valid.
        if recurrence_form.is_valid():
            if not request.POST.get('group'): # booking single client
                referral = get_object_or_404(Referral, pk=request.POST.get('referral'), service__organization=request.user.get_profile().org_active)
                event = recurrence_form.save(referral)

            else: # booking a group
                group = get_object_or_404(ServiceGroup, pk=request.POST.get('group'), service__organization=request.user.get_profile().org_active, active=True)
                if group.charged_members(): # this check is already done in template. just to prevent empty groups
                    first = True
                    for group_member in group.charged_members():
                        if first:
                            event = recurrence_form.save(group_member.referral)
                            first = False
                        else:
                            if not event.errors:
                                event = recurrence_form.save(group_member.referral, True) # ignore busy check

            if not request.POST.get('group'): # booking single client
                '''
                    Create a payment for each upcoming event when event by pack or occurrence
                    Event per period will be created by script run by crontab everyday
                '''
                # check if occurrences have one payment by pack or event opened
                for o in referral.upcoming_nopayment_occurrences_():

                    # exist a payment for event?
                    if Receive.objects.filter(occurrence=o).count() == 0 :

                        # Filter payment by pack or occurrence
                        for x in referral.covenant.filter(Q(charge=1) | Q(charge=2) ).distinct():

                            receive = Receive() # new

                            # by pack
                            if x.charge == 2:
                                # check not terminated pack of same referral
                                for p in Receive.objects.filter(occurrence__event=event, covenant_charge=2):
                                    if not p.terminated_():
                                        # not terminated pack
                                        receive = p

                            # by occurrence
                            # new
                            if not receive.id:
                                receive.name = x.name
                                receive.price = x.price
                                receive.off = 0
                                receive.total = x.price
                                receive.covenant_charge = x.charge
                                receive.covenant_id = x.id
                                receive.save()

                                # by pack
                                receive.covenant_pack_size = x.event_time if x.charge == 2 else 0

                                # clear all
                                receive.covenant_payment_way_options = ''
                                for pw in x.payment_way.all():
                                    x = "(%s,'%s')," % ( pw.id , pw.name ) # need be a dict
                                    receive.covenant_payment_way_options += x

                            # add occurrence
                            receive.occurrence.add(o)
                            # update m2m
                            receive.save()


            if not event.errors:
                messages.success(request, _('Schedule saved successfully'))
                return http.HttpResponseRedirect(redirect_to or '/schedule/')
            else:
                return render_to_response(
                    'schedule/event_detail.html', 
                    dict(event=event),
                    context_instance=RequestContext(request)
                )


    # mount form or return form errors
    # convert hour:minutes to second to set initial select
    interval_sec = time_delta_total_seconds( timedelta(minutes=int(request.user.get_profile().org_active.time_slot_schedule)) )
    start_sec = time_delta_total_seconds( timedelta(hours=dtstart.hour, minutes=dtstart.minute) )
    end_sec = start_sec + interval_sec

    recurrence_form = recurrence_form_class( request,
                                             room.place, # start, end hour of place, render select in this range.
                                             initial = dict(
                                                            dtstart=dtstart, 
                                                            day=datetime.strptime(dtstart.strftime("%Y-%m-%d"), "%Y-%m-%d"), 
                                                            until=datetime.strptime(dtstart.strftime("%Y-%m-%d"), "%Y-%m-%d"),
                                                            room=room.id,
                                                            start_time_delta=start_sec,
                                                            end_time_delta=end_sec,
                                                        )
    )

    recurrence_form.fields['device'].widget.choices = [(i.id, i) for i in DeviceDetails.objects.active(request.user.get_profile().org_active).filter(Q(room=room) | Q(mobility="2", lendable=True) | Q(place=room.place, mobility="2", lendable=False))]

    return render_to_response( template,
                               dict(
                                        slot_time = request.user.get_profile().org_active.time_slot_schedule,
                                        dtstart = dtstart, 
                                        event_form = event_form, 
                                        recurrence_form = recurrence_form, 
                                        group = ServiceGroup.objects.filter(service__organization = request.user.get_profile().org_active, active=True),
                                        room = room,
                                        object = client,
                                        referral = referral,
                                        room_id = room.id,
                                    ),
                                context_instance=RequestContext(request)
    )
예제 #9
0
def daily_occurrences(request, year=1, month=1, day=None, place=None):
    """
        return JSON
        filter permission : professional or secretary
    """
    occurrences = schedule_occurrences(request, year, month, day)

    i = 0
    groups = []
    array = {} #json

    date = datetime.strptime(('%s/%s/%s' % (year, month, day)), "%Y/%m/%d")

    if place == None:
        # Possible to exist more than one place as matriz or none, filter and get first element
        if Place.objects.filter( place_type=1, organization=request.user.get_profile().org_active):
            place = Place.objects.filter(place_type=1, organization=request.user.get_profile().org_active)[0].id
        # non exist a matriz place
        else:
            place = Place.objects.filter(organization=request.user.get_profile().org_active)[0].id

    array['util'] = {
        'date': ('%s-%s-%s' % (year, month, day)),
        'date_field': ('%s/%s/%s' % (year, month, day)),
        u'str_date': '%s, %s %s %s %s %s' % (date.strftime("%A").decode('utf-8').capitalize(), date.strftime("%d"), _('of'), date.strftime("%B").decode('utf-8'), _('of'), date.strftime("%Y")),
        'next_day': (date + timedelta(days=+1)).strftime("%Y/%m/%d"),
        'prev_day': (date + timedelta(days=-1)).strftime("%Y/%m/%d"),
        'weekday': date.weekday(),
        'place': place,
    }
    
    """
        secretary and/or admin
            see all occurrences
        professional and/or student
            see event if owner of it OR reservado
    """
    # to check each occurence permission
    for o in occurrences:

        have_same_group = False
        if hasattr(o.event.referral.group, 'id'):
            if '%s-%s-%s' % (o.event.referral.group.id, o.room_id, o.start_time.strftime('%H:%M:%S')) in groups:
                have_same_group = True

        if not have_same_group:
            range = o.end_time-o.start_time
            rowspan = range.seconds/time_delta_total_seconds( timedelta(minutes=int(request.user.get_profile().org_active.time_slot_schedule)) ) 

        if show_event_(request, o): # to show full data
            array[i] = {
                'id': o.id,
                'event_id': o.event.id,
                'room': o.room_id,
                'place': o.room.place_id,
                'room_name': (u"%s" % o.room),
                'service_id':o.event.referral.service.id,
                'group': (u"%s" % '' if not hasattr(o.event.referral.group, 'id') else o.event.referral.group.description),
                'group_id': '' if not hasattr(o.event.referral.group, 'id') else o.event.referral.group.id,
                'service': u"%s" % o.event.referral,
                'color':o.event.referral.service.color,
                'font_color':o.event.referral.service.font_color,
                'start_time': o.start_time.strftime('%H:%M:%S'),
                'end_time': o.end_time.strftime('%H:%M:%S'),
                'rowspan': rowspan,
                'online': o.is_online,
            }
        else: # to show as reservado
            array[i] = {
                'room': o.room_id,
                'room_name': (u"%s" % o.room),
                'place': o.room.place_id,
                'group': u"",
                'service': "RESERVADO",
                'service_id':o.event.referral.service.id,
                'color':o.event.referral.service.color,
                'font_color':o.event.referral.service.font_color,
                'start_time': o.start_time.strftime('%H:%M:%S'),
                'end_time': o.end_time.strftime('%H:%M:%S'),
                'rowspan': rowspan,
            }
        
        array[i]['professional'] = {}
        array[i]['client'] = {}
        array[i]['device'] = {}

        if show_event_(request, o): # to show full data

            sub_count = 0
            for p in o.event.referral.professional.all():
                array[i]['professional'][sub_count] = ({'id':p.id, 'name':p.person.name})
                sub_count = sub_count + 1

            sub_count = 0
            for c in o.event.referral.client.all():
                array[i]['client'][sub_count] = ({'id':c.id, 'name':c.person.name})
                sub_count = sub_count + 1
        
            sub_count = 0
            if not o.scheduleoccurrence.was_confirmed():
                device_list = o.device.all()
            else:
                device_list = o.occurrenceconfirmation.device.all()

            for o in device_list:
                array[i]['device'][sub_count] = ({'id':o.id, 'name': ("%s - %s - %s" % (o.device.description, o.brand, o.model)) })
                sub_count = sub_count + 1

            # concat group id, room id and start time to register in a list and verify in the begin of the loop if the same
            # occurrence already has been registered
            if hasattr(o, 'event') and hasattr(o.event.referral.group, 'id'):
                groups.append('%s-%s-%s' % (o.event.referral.group.id, o.room_id, o.start_time.strftime('%H:%M:%S')))

        i = i + 1

    array['util']['occurrences_total'] = i
    array = simplejson.dumps(array)
    
    return HttpResponse(array, mimetype='application/json')
예제 #10
0
def add_event(
        request, 
        template='schedule/schedule_form.html',
        event_form_class=ReferralForm,
        recurrence_form_class=ScheduleOccurrenceForm,
        redirect_to = None
    ):

    disable_check_busy = False
    to_confirm_conflict = False  # dont show checkbox to ignore conflict

    # have to contains dtstart variable in URL. URL from schedule have to contains date and time data.
    if not 'dtstart' in request.GET:
        return http.HttpResponseRedirect('/schedule/')

    # get from url
    dtstart = parser.parse( request.GET['dtstart'] )
    room = get_object_or_None(Room, pk=request.GET.get('room'), place__organization=request.user.get_profile().org_active)
    client = get_object_or_None(Client, pk=request.GET.get('client'), person__organization=request.user.get_profile().org_active)
    referral = get_object_or_None(Referral, pk=request.GET.get('referral'), service__organization=request.user.get_profile().org_active)
    event_form = event_form_class

    if request.POST:
        if request.POST.get('ignore_conflict') == 'on':
            disable_check_busy = True

        # instance form
        recurrence_form = recurrence_form_class(request, room.place, request.POST)

        # no errors found, form is valid.
        if recurrence_form.is_valid():
            if not request.POST.get('group'): # booking single client
                referral = get_object_or_404(Referral, pk=request.POST.get('referral'), service__organization=request.user.get_profile().org_active)
                event_form = recurrence_form.save(referral, disable_check_busy=disable_check_busy)

            else: # booking a group
                group = get_object_or_404(ServiceGroup, pk=request.POST.get('group'), service__organization=request.user.get_profile().org_active, active=True)
                if group.charged_members(): # this check is already done in template. just to prevent empty groups
                    first = True
                    for group_member in group.charged_members():
                        if first:
                            event_form = recurrence_form.save(group_member.referral)
                            first = False
                        else:
                            if not event_form.errors:
                                event_form = recurrence_form.save(group_member.referral, True) # ignore busy check

            if not request.POST.get('group'): # booking single client
                '''
                    Create a payment for each upcoming event when event by pack or occurrence
                    Event per period will be created by script run by crontab everyday
                '''
                # check if occurrences have one payment by pack or event opened
                for o in referral.upcoming_nopayment_occurrences_():

                    # exist a payment for event?
                    if Receive.objects.filter(occurrence=o).count() == 0 :

                        # Filter payment by pack or occurrence
                        for x in referral.covenant.filter(Q(charge=1) | Q(charge=2) ).distinct():
                            receive = Receive() # new

                            """
                                by pack, by event.
                                charge2 overwrite charge1
                            """
                            # by pack
                            if x.charge == 2:
                                # check not terminated pack of same referral
                                for p in Receive.objects.filter(occurrence__event=event_form, covenant_charge=2):
                                    if not p.terminated_()[0]:
                                        # not terminated pack
                                        receive = p

                            # by occurrence
                            # new
                            if not receive.id:
                                receive.name = x.name
                                receive.price = x.price
                                receive.off = 0
                                receive.total = x.price
                                receive.covenant_charge = x.charge
                                receive.covenant_id = x.id
                                receive.save()

                                # by pack
                                receive.covenant_pack_size = x.event_time if x.charge == 2 else 0

                                # clear all
                                receive.covenant_payment_way_options = ''
                                for pw in x.payment_way.all():
                                    x = "(%s,'%s')," % ( pw.id , pw.name ) # need be a dict
                                    receive.covenant_payment_way_options += x

                            # add occurrence
                            receive.occurrence.add(o)
                            # update m2m
                            receive.save()

            if not event_form.errors:
                messages.success(request, _('Schedule saved successfully'))
                return http.HttpResponseRedirect(redirect_to or '/schedule/')
            else:
                messages.info(request, _(u'Conflito no agendamento.'))
                to_confirm_conflict = True  # show checkbox

    else:
        # mount form or return form errors
        # convert hour:minutes to second to set initial select
        interval_sec = time_delta_total_seconds( timedelta(minutes=int(request.user.get_profile().org_active.time_slot_schedule)) )
        start_sec = time_delta_total_seconds( timedelta(hours=dtstart.hour, minutes=dtstart.minute) )
        end_sec = start_sec + interval_sec

        recurrence_form = recurrence_form_class( request,
                                                 room.place, # start, end hour of place, render select in this range.
                                                 initial = dict(
                                                                dtstart=dtstart,
                                                                day=datetime.strptime(dtstart.strftime("%Y-%m-%d"), "%Y-%m-%d"),
                                                                until=datetime.strptime(dtstart.strftime("%Y-%m-%d"), "%Y-%m-%d"),
                                                                room=room.id,
                                                                start_time_delta=start_sec,
                                                                end_time_delta=end_sec,
                                                            )
        )

        recurrence_form.fields['device'].widget.choices = [(i.id, i) for i in DeviceDetails.objects.active(request.user.get_profile().org_active).filter(Q(room=room) | Q(mobility="2", lendable=True) | Q(place=room.place, mobility="2", lendable=False))]

    return render_to_response(template,
                               dict(
                                        slot_time = request.user.get_profile().org_active.time_slot_schedule,
                                        dtstart = dtstart, 
                                        event_form = event_form, 
                                        recurrence_form = recurrence_form, 
                                        group = ServiceGroup.objects.filter(service__organization = request.user.get_profile().org_active, active=True),
                                        room = room,
                                        object = client,
                                        referral = referral,
                                        room_id = room.id,
                                        disable_check_busy = disable_check_busy,
                                        to_confirm_conflict = to_confirm_conflict,
                                    ),
                                context_instance=RequestContext(request)
    )