So I have 2 views: the first one generates the html on request, the second view generates the chart to display for the first view.
HTML View
def activation_signupcount(request):
if 'datestart' not in request.GET:
return render_to_response('activation/activation_signupcount.html', {'datestart':''})
else:
datestart = request.GET['datestart']
dateend = request.GET['dateend']
return render_to_response('activation/activation_signupcount.html', {'datestart':datestart, 'dateend':dateend})#
CHART VIEW
def activation_signupcount_graph(request):
datestart = request.GET['datestart'] #this doesnt work
dateend = request.GET['dateend'] #this doesnt work
print datestart,dateend
# open sql connection
cursor = connection.cursor()
# execute query
cursor.execute("SELECT COUNT(1), JoinDate FROM users WHERE JoinDate BETWEEN '"+ datestart +"' AND '"+ dateend +"' GROUP BY JoinDate;")
# close connection
data = cursor.fetchall()
cursor.close()
connection.close()
fig = Figure()
ax = fig.add_subplot(111)
x = []
y = []
x = [k[1] for k in data]
y = [k[0] for k in data]
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
So on the page activation/activation_signupcount.html
, I have 2 date fields, start and end, which submits a GET request. So my question is, how can I parse these 2 date variables to my function activation_signupcount_graph
to get the start/end dates to generate the chart?
I hope that was clear!