Ejemplo n.º 1
0
def branches(request, branch):
	errors=[]
	graph=''
	branch_data=[]
	current_date=str(datetime.date.today()).split('-')
	smonth=int(current_date[1])
	emonth=int(current_date[1])
	syear=int(current_date[0])
	eyear=int(current_date[0])
	if request.method == 'POST':
		form=dateSelect(request.POST)
		if form.is_valid():
			smonth=int(form.cleaned_data['smonth'])
			syear=int(form.cleaned_data['syear'])
			emonth=int(form.cleaned_data['emonth'])
			eyear=int(form.cleaned_data['eyear'])
			branch=str(form.cleaned_data['branch'])
			if syear>eyear or ((syear==eyear) and (emonth<smonth)):errors.append('Your date range is invalid!')
	else:form=dateSelect(initial={'smonth':smonth, 'syear':syear, 'emonth':emonth, 'eyear':eyear})
	if errors: return render_to_response('selfcheck/branches.html',{'form':form, 'errors':errors}, context_instance=RequestContext(request))
	data=DataStuff()
	branch_data=data.BranchStats(smonth, syear, emonth, eyear, branch)
	monthly_data=branch_data[0]
	graph=branch_data[1]
	return render_to_response('selfcheck/branches.html', {'branch': branch, 'monthly_data': monthly_data, 'form':form, 'errors':errors, 'graph':graph}, context_instance=RequestContext(request))
	

		
Ejemplo n.º 2
0
def index(request):
	errors=[]
	graph=''
	system_data={}
	current_date=str(datetime.date.today()).split('-')
	smonth=int(current_date[1])
	emonth=int(current_date[1])
	syear=int(current_date[0])
	eyear=int(current_date[0])
	if request.method == 'POST':
		form=dateSelect(request.POST)
		if form.is_valid():
			smonth=int(form.cleaned_data['smonth'])
			syear=int(form.cleaned_data['syear'])
			emonth=int(form.cleaned_data['emonth'])
			eyear=int(form.cleaned_data['eyear'])
			if syear>eyear or ((syear==eyear) and (emonth<smonth)):errors.append('Your date range is invalid!')
	else: 
		form=dateSelect(initial={'smonth':smonth, 'syear':syear, 'emonth':emonth, 'eyear':eyear})
		for each in System.objects.all():
			each.update()
	if errors: return render_to_response('selfcheck/index.html',{'form':form, 'errors':errors}, context_instance=RequestContext(request))
	data=DataStuff()
	system_data=data.system_selfcheck_stats(smonth, syear, emonth, eyear)
	graph=[]
	graph.append(data.graphTotals(smonth, syear, emonth, eyear))
	graph.append(data.graphBranches(smonth, syear, emonth, eyear))
	return render_to_response('selfcheck/index.html', {'system_data': system_data, 'form':form, 'errors':errors, 'graph':graph}, context_instance=RequestContext(request))