def finance request id company_data Company objects get pk id user req

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def finance(request, id):
company_data = Company.objects.get(pk=id, user=request.user)
if company_data:
period_data = current_quarter()
finance_data = Company_Finance.objects.filter(period_data['db'])
if request.method == 'POST':
form = CompanyFinance(request.POST)
if form.is_valid():
__tmp = {'0':{}, '1':{}, '2':{}, '3':{}}
for i in form:
__tmp[re.sub('^.*?_(\d)', '\\1', i.name)][re.sub('_\d$', '', i.name)] = i.data
for i in __tmp:
instance = Company_Finance(
company=company_data,
period=period_data['def'][int(i)]['Period'],
period_year=period_data['def'][int(i)]['Period_Year'],
receipt=__tmp[i]['receipt'],
asset=__tmp[i]['asset'],
capital_reserve=__tmp[i]['capital_reserve'])
instance.save()
return render_to_response('finance.html', {'form': form, 'period': period_data['web']})
form = CompanyFinance()
return render_to_response('finance.html', {'form': form, 'period': period_data['web']})
else:
return HttpResponseRedirect('/company/new/')