def generate_report(*args, **kwargs): to_excel = [] date = kwargs['date'] length = kwargs['length'] email = kwargs['email'] for variable in Variable.objects.all(): qs = Measurement.objects.exclude(value=None).filter(variable=variable) values = get_data(qs, date, length) data = prepare_data(values) to_excel.append({ 'variable': variable, 'real': data, 'simulate': random_data(data) }) xls = create_excel(to_excel) path = 'resume.xls' xls.save(path) print 'Email sent to %s' % kwargs['email'] email_data = { 'email': email, 'subject': 'Resume for date: %s' % date, 'body': '', 'path': path } Email.send_email_attach(**email_data)
def form_valid(self, form): data = form.cleaned_data date = data['date'] length = data['length'] variable = data['variable'] qs = Measurement.objects.filter(variable=variable).exclude(value=None) values = get_data(qs, date, length) context = { 'real_data': prepare_data(values), 'variable': variable, 'length': len(values) } context['simulate_data'] = random_data(context['real_data']) params = ('main/report.html', context, RequestContext(self.request)) return render_to_response(*params)