@register.inclusion_tag('org/box_plache.html')
def box_plache(diarys, user):
    """summarize paid, unpaid time for given period of diaries"""
    list = {}  # Hash<author.username, hours unpaid>
    paylist = {} 	# Hash<author.username, hours paid>
    billable_hours = 0  # total paid time, in hours
    total_hours = 0	 # total paid+unpaid time, in hours
    sum = 0	 # total to be paid (= total paid time * tariff)

    # pupulate list, paylist from diaries
    for o in diarys:
        a = o.author.username
        if a in list:
            list[a] += o.length.hour
        else:
            list[a] = o.length.hour
            paylist[a] = 0
        total_hours += o.length.hour

        # paid projects are dezuranje (22) and tehnicarjenje (23)
        # they must reference an event that requires a technician, also
        if ((o.task.id == 22) or (o.task.id == 23 and o.event != None and (o.event.require_technician or o.event.require_video))):
            paylist[a] += o.length.hour
            billable_hours += o.length.hour

    # compute per-person summaries
    tariff = 3.50   # EUR/hour
    objects = []				# List<Hash<String, Object>> - summaries per person
    for o in list:				# for every author.username
        a = {}					# his summary
        a['name'] = o
        a['time'] = list[o]			# unpaid time in hours
        a['paytime'] = paylist[o]		# paid time in hours
        a['money'] = paylist[o] * tariff  # paid time * tariff (3.13eur/h currently)
        objects.append(a)

        # add to totals
        sum += (paylist[o] * tariff)

    # sort by a['money']
    objects.sort(lambda a, b: int(b['money'] - a['money']))

    return {'objects': objects,
            'user': user,
            'billable_hours': billable_hours,
            'total_hours': total_hours,
            'sum': sum}
dataset/ETHPy150Open kiberpipa/Intranet/intranet/org/templatetags/box.py/box_plache/original