Exemplo n.º 1
0
def calculatorView(request):
    if request.method == 'POST':
        form = CalculatorForm(request.POST, extra=request.POST.get('extra_field_count'))
        if form.is_valid():
            print "valid!"
    else:
        form = CalculatorForm()
    return render(request, "calculator.html", { 'form': form })
Exemplo n.º 2
0
def index(request):
    form = CalculatorForm()
    output = None
    cycles = None
    if request.method == 'POST':
        submitted = True
        form = CalculatorForm(request.POST)
        print "posted"
        print form.__dict__
        if form.is_valid():
            output = run_simulation(form)
            cycles = len(output)
    else:
        submitted = False
    return render(request, 'calculator.html', {
        'output': output,
        'cycles': cycles,
        'form': form,
        'submitted': submitted
    })
Exemplo n.º 3
0
def calculator(request):
  visit = None
  visit_stats = None

  if request.method != 'POST':
    calcForm = CalculatorForm()
  else:
    calcForm = CalculatorForm(request.POST)

    if calcForm.is_valid():
      birth_date = calcForm.cleaned_data['birth_date']
      visit_date = calcForm.cleaned_data['visit_date']
      sex = calcForm.cleaned_data['sex']
      weight = calcForm.cleaned_data['weight']
      head_circumference = calcForm.cleaned_data['head_circumference']
      height = calcForm.cleaned_data['height']
      height_position = calcForm.cleaned_data['height_position']

      visit_stats = models.VisitStatistics.get_stats(
                      birth_date, visit_date, sex, weight,
                      head_circumference, height, height_position, False)

      # Make up a visit psuedo-object for visit_stat_table.html
      # To make a real Visit, we'd need a Patient saved in the datastore
      class PsuedoVisit(object):
        def __init__(self, weight, height, head_circumference):
          self.weight = weight
          self.height = height
          self.head_circumference = head_circumference
      visit = PsuedoVisit(weight, height, head_circumference)

  return respond(request, 'calculator.html',
                 { 'calculatorform': calcForm,
                   'visit': visit,
                   'visit_stats'   : visit_stats,
                 })