def eval(request, event_id): my_template_data = dict() #TODO: put in authentication stuff #get champ_info for this event champ_info = ChampInfo.objects.get(event=event_id) #find which program areas this event has program_areas = ProgramArea.objects.filter(programlink__champ_info=champ_info) formgroup = FormGroup() #add all forms for selected program areas for i,pa in enumerate(program_areas): form = Empty() form.groupname = pa.name form.program_area = pa field_group = pa.eval_model form.subform = FieldGroupForm(request.POST or None, field_group=field_group, owner = champ_info.value_owner) formgroup.add_form(form) my_template_data["formgroup"] = formgroup.forms #validate fields if request.POST:#formgroup.is_valid(): # check if fields validated valid = False #TODO... do not trust user entered data... should verify correctness here #loop thru formgroup and save stuff for form in formgroup.forms: if form.subform.is_valid(): #process the subform for this program group from form.subform.save() else: valid = False # return HttpResponseRedirect(domain + reverse(events) ) # Redirect after POST if valid: return HttpResponseRedirect(domain ) # Redirect after POST return render_to_response('champ2/event.html', my_template_data, context_instance=RequestContext(request))
def base_group_metrics_ajax(request, group_slug, date_range_slug, metric_prog_area_id, is_goal): my_template_data = dict() mvs_type = MatriceValueSet.MEASUREMENT_TYPE if is_goal: mvs_type = MatriceValueSet.GOAL_TYPE matrice_date = MatriceDate.objects.get(slug=date_range_slug) base_group = BaseGroup.objects.get(slug=group_slug) matrice_value_set = None try: matrice_value_set = MatriceValueSet.objects.get(base_group=base_group, matrice_date=matrice_date, type=mvs_type) except(ObjectDoesNotExist): matrice_value_set = MatriceValueSet() matrice_value_set.base_group = BaseGroup.objects.get(slug=group_slug) matrice_value_set.matrice_date = matrice_date matrice_value_set.type = mvs_type matrice_value_set.save() mpa = MatriceProgramArea.objects.get(id=metric_prog_area_id) pa_context = Empty() pa_context.name = mpa.title pa_context.id = mpa.id pa_context.form = MatriceProgramAreaForm(request=request.POST or None, matrice_value_set=matrice_value_set, matrice_program_area=mpa) #save if valid if request.POST and pa_context.form.is_valid(): pa_context.form.save() my_template_data["pa"] = pa_context print repr(request.POST) #my_template_data["debug"] = repr(request.POST) + " matrice1_1-9 = [" + request.POST["matrice1_1-9"] + "]" return render_to_response('champ2/matrices_form_ajax.html', my_template_data, context_instance=RequestContext(request))
def matrices_group(request, group_slug): my_template_data = dict() base_group = BaseGroup.objects.get(slug=group_slug) dates = MatriceDate.objects.all() sets = list() for date in dates: set = Empty() set.date = date #find any GOAL matrice value sets for the date and group try: vs = MatriceValueSet.objects.get(base_group=base_group, matrice_date=date, type=MatriceValueSet.GOAL_TYPE) set.goal = vs except(ObjectDoesNotExist): set.goal = None #find any MEASURE matrice value sets for the date and group try: vs = MatriceValueSet.objects.get(base_group=base_group, matrice_date=date, type=MatriceValueSet.MEASUREMENT_TYPE) set.measurement = vs except(ObjectDoesNotExist): set.measurement = None if set.goal: # set.invalid_goal_count = matrice_value_set_invalid_count(set.goal) #this doesn't currently make sense because no invalid values can be stored set.incomplete_goal_count = matrice_value_set_incomplete_count(set.goal) if set.measurement: # set.invalid_measurement_count = matrice_value_set_invalid_count(set.measurement) #this doesn't currently make sense because no invalid values can be stored set.incomplete_measurement_count = matrice_value_set_incomplete_count(set.measurement) sets.append(set) my_template_data["sets"] = sets return render_to_response('champ2/matrices_group.html', my_template_data, context_instance=RequestContext(request))
def matrices_group_date(request, group_slug, date_range_slug, is_goal): my_template_data = dict() matrice_date = MatriceDate.objects.get(slug=date_range_slug) base_group = BaseGroup.objects.get(slug=group_slug) mvs_type = MatriceValueSet.MEASUREMENT_TYPE if is_goal: mvs_type = MatriceValueSet.GOAL_TYPE matrice_value_set = None try: matrice_value_set = MatriceValueSet.objects.get(base_group=base_group, matrice_date=matrice_date, type=mvs_type) except(ObjectDoesNotExist): matrice_value_set = MatriceValueSet() matrice_value_set.base_group = BaseGroup.objects.get(slug=group_slug) matrice_value_set.matrice_date = matrice_date matrice_value_set.type = mvs_type matrice_value_set.save() mall = Empty() #data object we will add stuff to. stands for matrice (m), all mall.groups = list() mall.base_group_name = base_group.name mall.matrice_date = matrice_date #loop thru matrice groups matrice_groups = MatriceGroup.objects.all() for mg in matrice_groups: mg_context = Empty() mg_context.name = mg.title mg_context.program_areas = list() #loop thru program areas for groups for mpa in mg.program_areas.all(): pa_context = Empty() #add form to context pa_context.name = mpa.title pa_context.id = mpa.id pa_context.form = MatriceProgramAreaForm(request=request.POST or None, matrice_value_set=matrice_value_set, matrice_program_area=mpa) pa_context.metrics_incomplete = matrice_program_area_incomplete_count(mpa, matrice_value_set) #save if valid if request.POST and pa_context.form.is_valid(): pa_context.form.save() #add program area to program areas list mg_context.program_areas.append(pa_context) #add group to groups list mall.groups.append(mg_context) #TODO: the URL to post new using AJAX is HARD CODED!!!! BAD! my_template_data["matrice_date"] = matrice_date my_template_data["base_group"] = base_group my_template_data["matrice_value_set"] = matrice_value_set my_template_data["is_goal"] = is_goal my_template_data["matrice_all"] = mall return render_to_response('champ2/matrices_form.html', my_template_data, context_instance=RequestContext(request))
def base_group_goals(request, group_slug): my_template_data = dict() network = BaseGroup.objects.get(slug=group_slug) #get current matching date range date_range = DateRange.objects.filter(start__lte=datetime.date.today(), end__gte=datetime.date.today())[0] #TODO: can we guarantee non overlapping? #TODO: if the date range fails... should email someone saying... put this in! values_owner = None #get Goal object for this network or create it if it does not exist try: goal = Goal.objects.get(date_range=date_range, base_group=network) values_owner = goal.values_owner except(ObjectDoesNotExist): goal = Goal() goal.date_range = date_range goal.base_group = network values_owner = AnyValueOwner() values_owner.save() goal.values_owner = values_owner goal.save() #show goals for all the goal forms #allow them to select which program types this event belongs to program_areas = ProgramArea.objects.all() formgroup = FormGroup() #add all forms for selected program areas for i,pa in enumerate(program_areas): form = Empty() form.groupname = pa.name field_group = pa.goal_model #the model to render form.subform = FieldGroupForm(request.POST or None, field_group=field_group, owner = values_owner, calc_base_group=network, calc_parent_class=ProgramArea) form.plan = FieldGroupForm(request.POST or None, field_group=field_group, owner = values_owner, calc_base_group=network, calc_parent_class=ProgramArea, calc_mode=FieldGroupForm.CALC_MODE_PLAN, extra_prefix="planz") form.eval = FieldGroupForm(request.POST or None, field_group=field_group, owner = values_owner, calc_base_group=network, calc_parent_class=ProgramArea, calc_mode=FieldGroupForm.CALC_MODE_EVAL, extra_prefix="evals") formgroup.add_form(form) my_template_data["formgroup"] = formgroup.forms #validate fields if request.POST:#formgroup.is_valid(): # check if fields validated valid = False #TODO... do not trust user entered data... should verify correctness here #loop thru formgroup and save stuff for form in formgroup.forms: if form.subform.is_valid(): #process the subform for this program group from form.subform.save() # return HttpResponseRedirect(domain + reverse(events) ) # Redirect after POST if valid: return HttpResponseRedirect(domain ) # Redirect after POST return render_to_response('champ2/goal.html', my_template_data, context_instance=RequestContext(request))