1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- from itertools import chain
- from django.shortcuts import render
- from .models import Service, Cost, Good, CostUse, GoodUse
- def index(request):
- return render(request, 'costs/index.html')
- def list_services(request):
- context = {
- 'services': Service.objects.all(),
- }
- return render(request, 'costs/services_list.html', context)
- def list_resources(request):
- context = {
- 'goods': Good.objects.all(),
- 'costs': Cost.objects.all(),
- }
- return render(request, 'costs/resources_list.html', context)
- def detail_service(request, pk):
- service = Service.objects.get(pk=pk)
- costs_uses = CostUse.objects.filter(service=service)
- goods_uses = GoodUse.objects.filter(service=service)
- total_costs_price = sum(chain(
- (i.monthly_provision_share() for i in goods_uses),
- (i.cost_share() for i in costs_uses),
- ))
- if service.subscriptions_count == 0:
- unit_costs_price = 0
- else:
- unit_costs_price = total_costs_price/service.subscriptions_count
- context = {
- 'service': service,
- 'costs_uses': costs_uses,
- 'goods_uses': goods_uses,
- 'total_costs_price': total_costs_price,
- 'unit_costs_price': unit_costs_price,
- }
- return render(request, 'costs/service_detail.html', context)
|