Ejemplo n.º 1
0
def week(request, year, week, shop):
    """ Machine job history of a week """
    w = week_range(int(year), int(week))

    # update jhistory table reading the log machine
    update_job_history(shop)

    days_job = []
    counter = 0 # line counter
    total_hours_week = 0
    total_minutes_week = 0

    for week_day in w:

        day = datetime.datetime.strftime(week_day, '%A %d %B')
        javascript_day = datetime.datetime.strftime(week_day, '%Y/%m/%d')

        data = []
        total_day_time = datetime.timedelta()

        jobs = Jhistory.objects.filter(shop=shop, start_time__year=week_day.year, start_time__month=week_day.month, start_time__day=week_day.day)

        for j in jobs:

            # retrieve formatted data from the model
            d = j.get_view()

            # increment total time per day
            hours = j.total_time.strftime('%H')
            minutes = j.total_time.strftime('%M')
            temp = datetime.timedelta(hours=int(hours),minutes=int(minutes))
            total_day_time = total_day_time + temp

            # template table row index
            d['id'] = counter
            counter +=1

            data.append(d)

        total_time = str(total_day_time)[:4]

        # retrieve the total time of the week
        ws_time = total_time.split(':')
        total_hours_week = total_hours_week + int(ws_time[0])
        total_minutes_week = total_minutes_week + int(ws_time[1])

        day_url = 'jobhistory' + '/' + week_day.strftime('%Y/%m/%d') + '/' + str(shop)

        days_job.append({'data': data, 'total_time': total_time, 'javascript_day': javascript_day, 'day': day, 'day_url': day_url})


    # total time of the week
    total_minutes = total_minutes_week%60
    total_hours = total_hours_week + total_minutes_week/60


    # navigation url
    navigator = {}
    today = datetime.datetime.today()
    today = today.strftime('%Y/%m/%d')
    url_today = 'jobhistory' + '/' + today + '/' + shop
    navigator['url_today'] = url_today

    url_next = 'jobhistory' + '/' + year + '/' + str(int(week) + 1) + '/' + shop
    navigator['url_next'] = url_next

    url_previous = 'jobhistory' + '/' + year + '/' + str(int(week) - 1) + '/' + shop
    navigator['url_previous'] = url_previous

    monday = w[0]
    monday = monday.strftime('%Y/%m/%d')
    url_monday = 'jobhistory' + '/' + monday + '/' + shop
    navigator['url_monday'] = url_monday

    url_week = 'jobhistory' + '/' + year + '/' + week + '/' + shop
    navigator['url_week'] = url_week

    # to retrieve the month take the first day of the week
    this_month = w[0].strftime('%m')
    navigator['url_this_month'] = 'jobhistory/month' + '/' + year + '/' + this_month + '/' + shop

    datapicker_day = datetime.datetime.today()
    datapicker_day = datapicker_day.strftime('%d/%m/%Y')

    return render_to_response('job_history_week.html', {'data': days_job,
                                                        'navigator':navigator,
                                                        'shop': shop,
                                                        'datapicker_day': datapicker_day,
                                                        'total_time': {'total_hours': total_hours, 'total_minutes': total_minutes},
                                                        'week': week,
                                                        'home_on_server' : settings.HOME_ON_SERVER},
                                                    context_instance=RequestContext(request))
Ejemplo n.º 2
0
def week(request, year, week, shop):
    """
    Week Timer Report
    """

    # get the orders from local table
    wlist = week_range(int(year),int(week))
    monday = wlist[0]
    sunday = wlist[6]
    local_ods = get_timed_product(monday, sunday, shop)
    local_ods = local_ods.order_by('start_time')

    # get the order detail from access db with the id of the local timed order detail
    access_orders = get_access_order(local_ods)

    # definition of the variables for the merging
    date_format = '%A %d %B'
    # the current date has to be iniatialize out of loop with the date of the first order
    current_day = local_ods[0].start_time.strftime(date_format)
    current_day_list = []
    days = {}
    template_data = []

    # merging the two result set
    for od in local_ods:
        ac_order = {}
        for el in access_orders:
            if el['ac_od_id'] == od.ac_od_id:
                ac_order = el
                ac_order['actual'] = od.actual
                ac_order['pause'] = od.pause
                ac_order['total'] = od.pause + od.actual
                ac_order['status'] = od.status
                ac_order['start_time'] = od.start_time.strftime('%Y/%m/%d %H:%M:%S')
                ac_order['class'] = 'product timed'

        if od.start_time.strftime(date_format) == current_day:
            # append the order in the list
            current_day_list.append(ac_order)
        else:
            # append the order in the list, create a new assemble day in the dictionary, clean the temporary variables
            days[current_day] = current_day_list
            template_data.append(days)
            days = {}
            current_day = od.start_time.strftime(date_format)
            current_day_list = [] # empty the current day list
            current_day_list.append(ac_order)

    # last time out the loop
    days[current_day] = current_day_list
    template_data.append(days)
    days = {}

    # navigation url
    nav_dict = {}
    nav_dict['url_template'] = '/records/week/%s/%s/%s/'    
    nav_dict['week_nr'] = week    
    nav_dict['year'] = year    
    nav_dict['shop'] = shop    

    return render_to_response('week_utl_timer.html', 
                                {'week_nr': week,
                                 'week': template_data,
                                 'home_on_server': settings.HOME_ON_SERVER,
                                 'navigation': get_navigation_url(nav_dict),
                                 'shop': shop}, context_instance=RequestContext(request))