コード例 #1
0
ファイル: views.py プロジェクト: nguyeant/labgeeksrpg
def create_default_schedule(request):
    if request.method == 'POST':
        form = CreateDailyScheduleForm(request.POST)
        if form.is_valid():

            # Grab the data from the form
            timeperiod = TimePeriod.objects.get(name=form.cleaned_data['timeperiods'])
            location = Location.objects.get(name=form.cleaned_data['location'])

            # TODO add timeperiod with a default shift instead of looking up start date / end date.
            start_date = timeperiod.start_date
            end_date = timeperiod.end_date
            
            x_axis = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
            y_axis = []

            # y_axis - The time scale
            counter = datetime(1,1,1,7,0)
            
            while counter.hour != 1:
                y_axis.append(counter.time().strftime('%I:%M %p').lower())
                counter += timedelta(minutes=30)
            
            shifts = []
            for day in x_axis:
                data = {'day': day,'shifts':y_axis,'location':location}
                shifts.append(data)

            schedule_class = "visible"
            #import pdb; pdb.set_trace()
    else:
        schedule_class ="hidden"
        form = CreateDailyScheduleForm()
    
    return render_to_response('create_schedule.html', locals(), context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: qnnwp/labgeeksrpg
def create_base_schedule(request):
    '''
    This view will allow users to create a schedule from scratch.
    '''

    if request.method == 'POST':
        form = CreateDailyScheduleForm(request.POST)
        if form.is_valid():

            # Grab the data from the form
            timeperiod = TimePeriod.objects.get(name=form.cleaned_data['timeperiods'])
            location = Location.objects.get(name=form.cleaned_data['location'])

            days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

            # Create a schedule dictionary to hold the data.
            schedule = []

            # Grab the closed hours and default shifts used in a timeperiod.
            base_shifts = BaseShift.objects.filter(location=location, timeperiod=timeperiod)
            time_in = time(7, 45)
            time_out = time(11, 45)

            shift_types = ShiftType.objects.all()

            base_shift_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }
            for shift in base_shifts:
                day = shift.day
                in_time = shift.in_time
                out_time = shift.out_time
                column = shift.column
                hours = []

                current = datetime(1, 1, 1, in_time.hour, in_time.minute)

                while current.time() != out_time:
                    hours.append(current.time())
                    current += timedelta(minutes=30)
                if shift.shift_type:
                    base_shift_ranges[day].append({'hours': hours, 'name': shift.shift_type.name, 'column': column})
                else:
                    base_shift_ranges[day].append({'hours': hours, 'name': 'Open_Shift', 'column': column})

            # TODO: For now, create an arbitrary size for the schedule. Consider changing it in the future.
            schedule_length = [0] * 10
            for day in days:
                base_shift_range = base_shift_ranges[day]
                times = []
                base_times = []
                counter = datetime(1, 1, 1, 7, 45)

                # Loop through the time and start appending the rows to each time.
                while counter.hour != 0:
                    base_row = []
                    # Fill in the shift hours.
                    count = 1
                    for shift in base_shift_range:
                        if counter.time() in shift['hours']:
                            while count < shift['column']:
                                base_row.append({'class': count, 'name': None})
                                count += 1

                            base_row.append({'class': count, 'name': shift['name']})
                            count += 1
                    for i in range(len(schedule_length) - count + 1):
                        base_row.append({'class': count + i, 'name': None})

                    # Append the row and time
                    base_times.append({'time': counter.time().strftime('%I:%M %p').lower(), 'row': base_row})

                    # Increment by 30 minutes
                    counter += timedelta(minutes=30)

                # Append the time row to the schedule.
                schedule.append({'times': base_times, 'day': day})
            schedule_class = "visible"

            # Determine if the user can edit the schedule.
            if request.user.has_perm('schedule.add_defaultshift'):
                can_edit_schedule = True
            else:
                can_edit_scehdule = False
    else:
        # There is no schedule to display.
        schedule_class = "hidden"
        form = CreateDailyScheduleForm()

    return render_to_response('create_base_schedule.html', locals(), context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: abztrakt/labgeeksrpg
def create_default_schedule(request):
    '''
    This view will allow users to create a schedule from scratch.
    '''

    if request.method == 'POST':
        form = CreateDailyScheduleForm(request.POST)
        if form.is_valid():

            # Grab the data from the form
            timeperiod = TimePeriod.objects.get(name=form.cleaned_data['timeperiods'])
            location = Location.objects.get(name=form.cleaned_data['location'])

            days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

            # Create a schedule dictionary to hold the data.
            base_schedule = []
            schedule = []

            # Grab the closed hours and default shifts used in a timeperiod.
            closing_hours = ClosedHour.objects.filter(location=location, timeperiod=timeperiod)
            default_shifts = DefaultShift.objects.filter(location=location, timeperiod=timeperiod)
            base_shifts = BaseShift.objects.filter(location=location, timeperiod=timeperiod)
            time_in = time(7, 45)
            time_out = time(11, 45)

            Shift_Types = []
            closing_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }

            shift_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }

            base_shift_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }
            base_shift_hours = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }
            # TODO: Form a less redundant way of doing the hour ranges.
            # Find out which hours were closing hours
            ''' going to use base shifts to determine closing hours when changing the schedule now
            for closing_hour in closing_hours:
                day = closing_hour.day
                in_time = closing_hour.in_time
                out_time = closing_hour.out_time
                hours = []

                current = datetime(1,1,1,in_time.hour,in_time.minute)

                while current.time() != out_time:
                    hours.append(current.time())
                    current += timedelta(minutes=30)
                hours.append(current.time())

                closing_ranges[day] += hours
            '''
            for shift in base_shifts:
                day = shift.day
                in_time = shift.in_time
                out_time = shift.out_time
                hours = []

                current = datetime(1, 1, 1, in_time.hour, in_time.minute)

                while current.time() != out_time:
                    hours.append(current.time())
                    current += timedelta(minutes=30)
                base_shift_hours[day] += hours
                if shift.shift_type:
                    groups = ''
                    count = 0
                    users = []
                    for group in shift.shift_type.allowed_groups.get_query_set():
                        if count == 0:
                            groups += group.name
                        else:
                            groups += ', ' + group.name
                        count = 1
                        count1 = 0
                        for user in group.user_set.values():
                                users.append(user['username'])
                    if not {'name': shift.shift_type.name, 'users': users} in Shift_Types:
                        Shift_Types.append({'name': shift.shift_type.name, 'users': users})
                    base_shift_ranges[day].append({'hours': hours, 'name': shift.shift_type.name})
                else:
                    base_shift_ranges[day].append({'hours': hours, 'name': 'Open_Shift'})

            for day in base_shift_hours:
                if len(base_shift_hours[day]) > 0:
                    in_time = time(7, 45)
                    out_time = time(23, 45)
                    hours = []
                    while base_shift_hours[day].count(in_time) == 0:
                        hours.append(in_time)
                        if in_time.minute == 45:
                            in_time = in_time.replace(hour=in_time.hour + 1, minute=15)
                        elif in_time.minute == 15:
                            in_time = in_time.replace(minute=45)
                    while base_shift_hours[day].count(out_time) == 0:
                        if hours.count(out_time) == 0:
                            hours.append(out_time)
                        if out_time.minute == 45:
                            out_time = out_time.replace(minute=15)
                        elif out_time.minute == 15:
                            out_time = out_time.replace(hour=out_time.hour - 1, minute=45)
                    closing_ranges[day] += hours
            # Find out which hours were shift hours.
            for shift in default_shifts:
                #currently does nothing if there is no person set to the shift
                if shift.person:
                    day = shift.day
                    in_time = shift.in_time
                    out_time = shift.out_time
                    hours = []

                    current = datetime(1, 1, 1, in_time.hour, in_time.minute)

                    while current.time() != out_time:
                        hours.append(current.time())
                        current += timedelta(minutes=30)

                    shift_ranges[day].append({'hours': hours, 'user': shift.person.username})
            # TODO: For now, create an arbitrary size for the schedule. Consider changing it in the future.
            schedule_length = [0] * 10

            # Now append append the hours to each day in the schedule.
            for day in days:
                closing_range = closing_ranges[day]
                shift_range = shift_ranges[day]
                base_shift_range = base_shift_ranges[day]
                times = []
                base_times = []
                counter = datetime(1, 1, 1, 7, 45)

                # Loop through the time and start appending the rows to each time.
                while counter.hour != 0:
                    row = []
                    base_row = []
                    if counter.time() in closing_range:
                        # Fill in the closing hours
                        for i in range(len(schedule_length)):
                            row.append({'class': 'closed_hours', 'user': '******'})
                            base_row.append({'class': 'closed_hours', 'user': '******'})
                    else:
                        # Fill in the shift hours.
                        count = 0
                        for shift in base_shift_range:

                            if counter.time() in shift['hours']:
                                count += 1
                                base_row.append({'class': None, 'name': shift['name']})

                        for i in range(len(schedule_length) - count):
                            base_row.append({'class': None, 'user': None})
                        count = 0
                        for shift in shift_range:

                            if counter.time() in shift['hours']:
                                count += 1
                                row.append({'class': None, 'user': shift['user']})

                        for i in range(len(schedule_length) - count):
                            row.append({'class': None, 'user': None})

                    # Append the row and time
                    times.append({'time': counter.time().strftime('%I:%M %p').lower(), 'row': row})
                    base_times.append({'time': counter.time().strftime('%I:%M %p').lower(), 'row': base_row})

                    # Increment by 30 minutes
                    counter += timedelta(minutes=30)

                # Append the time row to the schedule.
                schedule.append({'times': times, 'day': day})
                base_schedule.append({'times': base_times, 'day': day})

            schedule_class = "visible"

            # Determine if the user can edit the schedule.
            if request.user.has_perm('schedule.add_defaultshift'):
                can_edit_schedule = True
            else:
                can_edit_scehdule = False
    else:
        # There is no schedule to display.
        schedule_class = "hidden"
        form = CreateDailyScheduleForm()

    return render_to_response('create_schedule.html', locals(), context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: sjeong/labgeeksrpg
def create_default_schedule(request):
    '''
    This view will allow users to create a schedule from scratch.
    '''
    if request.method == 'POST':
        form = CreateDailyScheduleForm(request.POST)
        if form.is_valid():

            # Grab the data from the form
            timeperiod = TimePeriod.objects.get(name=form.cleaned_data['timeperiods'])
            location = Location.objects.get(name=form.cleaned_data['location'])
            
            days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']

            # Create a schedule dictionary to hold the data.
            schedule = []

            # Grab the closed hours and default shifts used in a timeperiod.
            closing_hours = ClosedHour.objects.filter(location=location, timeperiod=timeperiod)
            default_shifts = DefaultShift.objects.filter(location=location, timeperiod=timeperiod);
            closing_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }

            shift_ranges = {
                'Monday': [],
                'Tuesday': [],
                'Wednesday': [],
                'Thursday': [],
                'Friday': [],
                'Saturday': [],
                'Sunday': [],
            }

            # TODO: Form a less redundant way of doing the hour ranges.
            # Find out which hours were closing hours
            for closing_hour in closing_hours:
                day = closing_hour.day
                in_time = closing_hour.in_time
                out_time = closing_hour.out_time
                hours = []

                current = datetime(1,1,1,in_time.hour,in_time.minute)

                while current.time() != out_time:
                    hours.append(current.time())
                    current += timedelta(minutes=30)
                hours.append(current.time())

                closing_ranges[day] += hours

            # Find out which hours were shift hours.
            for shift in default_shifts:
                day = shift.day
                in_time = shift.in_time
                out_time = shift.out_time
                hours = []

                current = datetime(1,1,1,in_time.hour,in_time.minute)

                while current.time() != out_time:
                    hours.append(current.time())
                    current += timedelta(minutes=30)
                hours.append(current.time())

                shift_ranges[day].append({'hours': hours, 'user': shift.person.username})

            # TODO: For now, create an arbitrary size for the schedule. Consider changing it in the future.
            schedule_length = [0]*10
        
            # Now append append the hours to each day in the schedule.
            for day in days:
                closing_range = closing_ranges[day]
                shift_range = shift_ranges[day] 
                times = []
                counter = datetime(1,1,1,7,0)
    
                # Loop through the time and start appending the rows to each time.
                while counter.hour != 0:
                    row = []
                     
                    if counter.time() in closing_range:
                        # Fill in the closing hours
                        for i in range(len(schedule_length)):
                            row.append({'class': 'closed_hours', 'user': '******'})
                    else:
                        # Fill in the shift hours.
                        count = 0
                        for shift in shift_range:

                            if counter.time() in shift['hours']:
                                count += 1
                                row.append({'class':None, 'user': shift['user']})

                        for i in range(len(schedule_length)-count):
                            row.append({'class': None, 'user': None})
                    
                    # Append the row and time
                    times.append({'time': counter.time().strftime('%I:%M %p').lower(), 'row': row})

                    # Increment by 30 minutes
                    counter += timedelta(minutes=30)

                # Append the time row to the schedule.
                schedule.append({'times': times, 'day': day})

            schedule_class = "visible"

            # Determine if the user can edit the schedule.
            if request.user.has_perm('schedule.add_defaultshift'):
                can_edit_schedule = True
            else:
                can_edit_scehdule = False
    else:

        # There is no schedule to display.
        schedule_class ="hidden"
        form = CreateDailyScheduleForm()
    
    return render_to_response('create_schedule.html', locals(), context_instance=RequestContext(request))