示例#1
0
def save_raw_data(request, filter_num, number_of_rows):
    if request.method == 'POST':
        raw_data_form_set = modelformset_factory(RawData)
        raw_data_form = raw_data_form_set(request.POST)
        if raw_data_form.is_valid():
            raw_data_form.save()
            #update the filter so activity will be calculated again
            update_filter = Filter.objects.get(id=filter_num)
            update_filter.activity_calculated = False
            update_filter.save()
            return HttpResponseRedirect('/Data/CheckData/' + str(filter_num))
        else:
            raw_data_helper = RawDataFormSetHelper()
            raw_data_helper.add_input(Submit("submit", "Save"))
            raw_data_helper.form_action = reverse("saveRawData", args=(filter_num, number_of_rows,))
            return render(request, 'RadNet/addRawDataErrors.html',
                          {'rawDataForm': raw_data_form, 'rawHelper': raw_data_helper, })
    return HttpResponseRedirect('/Data/AddRawData')
示例#2
0
def add_raw_data(request):
    if request.method == 'POST':
        get_number_of_rows = NumberOfRawData(request.POST)
        if get_number_of_rows.is_valid():
            data = get_number_of_rows.cleaned_data
            number_of_rows = int(data['rows'])
            filter_num = data['filters']
            raw_data_form_set = modelformset_factory(RawData, form=RawDataForm, extra=number_of_rows)
            test = RawData.objects.filter(filter=filter_num)
            raw_data_form = raw_data_form_set(queryset=test, initial=[{'filter': filter_num},])
            raw_data_helper = RawDataFormSetHelper()
            raw_data_helper.add_input(Submit("submit", "Save"))
            raw_data_helper.form_action = reverse("saveRawData", args=(filter_num.id, number_of_rows,))
        else:
            raw_data_form = None
            raw_data_helper = None
    else:
        get_number_of_rows = NumberOfRawData()
        raw_data_form = None
        raw_data_helper = None

    return render(request, 'RadNet/addRawData.html',
                  {'getRows': get_number_of_rows, 'rawDataForm': raw_data_form, 'rawHelper': raw_data_helper, })