Esempio n. 1
0
def create_datavalueset(request):
    context = RequestContext(request)
    form = DataValueSetForm()
    if request.method == 'POST':
        form = DataValueSetForm(request.POST)
        if form.is_valid():
            form.save()
            context.success = True
    context.form = form
    return  render_to_response("dvs.html", context_instance=context)
Esempio n. 2
0
def match_datavalueset_to_data_elements(request):
    context = RequestContext(request)
    form = FHDataElementForm()
    context.fde_list = None
    if request.method == 'POST':
        form = FHDataElementForm(request.POST)
        dvs = DataValueSet.objects.get(pk=int(request.POST['dvs']))
        form.set_fh_fields(dvs.service)
        if form.is_valid():
            # form.save()
            de = DataElement.objects.get(pk=form.cleaned_data['data_elements'])
            try:
                fde = FormDataElement()
                fde.data_value_set = dvs
                fde.form_field = form.cleaned_data['fh_fields']
                fde.data_element = de
                fde.save()
            except IntegrityError:
                context.success = False
                context.msg = _(u"Match already saved.")
            else:
                context.success = True
                context.msg = _(u"Successfully saved.")
        else:
            context.success = False
            context.msg = _(u"Failed to save.")
        context.fde_list = list(FormDataElement.objects\
                        .filter(data_value_set=dvs)\
                        .values('data_value_set', 
                                'data_element__name', 'form_field'))
        if request.is_ajax():
            response = {'success': context.success, 'msg': context.msg,
                        'fde_list': context.fde_list}
            return HttpResponse(json.dumps(response))
    context.form = form
    return render_to_response("dvs-to-elements.html", context_instance=context)