Exemple #1
0
def save_xml_data_to_db(request):
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=form_data_id)

    form_id = request.session['form_id']
    root_element = SchemaElement.objects.get(pk=form_id)

    xml_renderer = XmlRenderer(root_element)
    xml_string = xml_renderer.render()

    template_id = form_data.template

    # Parse data from form
    form = SaveDataForm(request.POST)
    if not form.data['title'].lower().endswith('.xml'):
        form.data['title'] += ".xml"

    if not form.is_valid():
        return HttpResponseBadRequest('Invalid form name')

    if xml_string == "" or xml_string is None:
        return HttpResponseBadRequest('No XML data found')

    try:
        # update data if id is present
        if form_data.xml_data_id is not None:
            XMLdata.update_content(form_data.xml_data_id,
                                   content=xml_string,
                                   title=form.data['title'])
            #Specific MDCS
            XMLdata.update_publish(form_data.xml_data_id)
        else:
            # create new data otherwise
            xml_data = XMLdata(schemaID=template_id,
                               xml=xml_string,
                               title=form.data['title'],
                               iduser=str(request.user.id))
            xml_data_id = xml_data.save()
            XMLdata.update_publish(xml_data_id)

        print 'SchemaID====', template_id
        print 'xml_data_id====', xml_data_id
        request.session['xml_data_id'] = str(xml_data_id)
        print 'request.session-xml_data_id', request.session['xml_data_id']

        if form_data.schema_element_root is not None:
            delete_branch_from_db(form_data.schema_element_root.pk)

        form_data.delete()

        return HttpResponse('ok')
    except Exception, e:
        message = e.message.replace('"', '\'')
        return HttpResponseBadRequest(message)
def save_xml_data_to_db(request):
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=form_data_id)
    form_id = request.session['form_id']
    root_element = SchemaElement.objects.get(pk=form_id)
    xml_renderer = XmlRenderer(root_element)
    xml_string = xml_renderer.render()
    template_id = form_data.template

    # Parse data from form
    form = SaveDataForm(request.POST)
    if not form.data['title'].lower().endswith('.xml'):
        form.data['title'] += ".xml"

    if not form.is_valid():
        return HttpResponseBadRequest('Invalid form name')

    if xml_string == "" or xml_string is None:
        return HttpResponseBadRequest('No XML data found')

    try:
        # update form data if id is present
        if form_data.xml_data_id is not None:
            if not form_data.isNewVersionOfRecord:
                #Update the record
                XMLdata.update_content(form_data.xml_data_id,
                                       xml_string,
                                       title=form.data['title'])
                #Delete form_data
                if form_data.schema_element_root is not None:
                    delete_branch_from_db(form_data.schema_element_root.pk)
                form_data.delete()
            else:
                form_data.xml_data = xml_string
                form_data.save()
        else:
            # create new data otherwise
            xml_data = XMLdata(schemaID=template_id,
                               xml=xml_string,
                               title=form.data['title'],
                               iduser=str(request.user.id))
            xml_data.save()
            #Delete form_data because we just create an XmlData and we don't need anymore the formdata
            if form_data.schema_element_root is not None:
                delete_branch_from_db(form_data.schema_element_root.pk)
            form_data.delete()

        return HttpResponse('ok')
    except Exception, e:
        message = e.message.replace('"', '\'')
        return HttpResponseBadRequest(message)
def save_xml_data_to_db(request):
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=form_data_id)

    form_id = request.session['form_id']
    root_element = SchemaElement.objects.get(pk=form_id)

    xml_renderer = XmlRenderer(root_element)
    xml_string = xml_renderer.render()

    # xmlString = request.session['xmlString']
    # template_id = request.session['currentTemplateID']
    template_id = form_data.template

    # Parse data from form
    form = SaveDataForm(request.POST)
    if not form.data['title'].lower().endswith('.xml'):
        form.data['title'] += ".xml"

    if not form.is_valid():
        return HttpResponseBadRequest('Invalid form name')

    if xml_string == "" or xml_string is None:
        return HttpResponseBadRequest('No XML data found')

    try:
        # update data if id is present
        if form_data.xml_data_id is not None:
            XMLdata.update_content(
                form_data.xml_data_id,
                xml_string,
                title=form.data['title']
            )
        else:
            # create new data otherwise
            xml_data = XMLdata(
                schemaID=template_id,
                xml=xml_string,
                title=form.data['title'],
                iduser=str(request.user.id)
            )
            xml_data.save()

        form_data.delete()

        return HttpResponse('ok')
    except Exception, e:
        message = e.message.replace('"', '\'')
        return HttpResponseBadRequest(message)
Exemple #4
0
def curate_view_data(request):
    template = loader.get_template('curate/curate_view_data.html')

    # get form data from the database
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=ObjectId(form_data_id))

    owner = UserProfile.objects.get(user=User.objects.get(id=request.user.id))
    if not form_data.name.lower().endswith('.xml'):
        form_data.name += ".xml"
    form_name = form_data.name

    # detect if new document, or editing
    if form_data.xml_data_id is not None:
        edit = True
    else:
        edit = False

    context = RequestContext(
        request, {
            'form_save': SaveDataForm({"title": form_name}),
            'edit': edit,
            'myGroup': dataGroup.objects.filter(owner=owner.id),
            'otherGroup': owner.get_group()
        })
    if 'currentTemplateID' not in request.session:
        return redirect('/curate/select-template')
    else:
        return HttpResponse(template.render(context))
Exemple #5
0
def save_xml_data_to_db(request):
    xmlString = request.session['xmlString']
    templateID = request.session['currentTemplateID']

    form = SaveDataForm(request.POST)

    if form.is_valid():
        if xmlString != "":
            try:
                # get form data from the database
                form_data_id = request.session['curateFormData']
                form_data = FormData.objects.get(pk=ObjectId(form_data_id))
                if not form.data['title'].lower().endswith('.xml'):
                    form.data['title'] += ".xml"
                # update data if id is present
                if form_data.xml_data_id is not None:
                    XMLdata.update_content(form_data.xml_data_id, xmlString, title=form.data['title'])
                else:
                    #create new data otherwise
                    newJSONData = XMLdata(schemaID=templateID, xml=xmlString, title=form.data['title'], iduser=str(request.user.id))
                    newJSONData.save()
                # delete form data
                try:
                    form_data = FormData.objects().get(pk=form_data_id)
                    # cascade delete references
                    for form_element_id in form_data.elements.values():
                        try:
                            form_element = FormElement.objects().get(pk=form_element_id)
                            if form_element.xml_element is not None:
                                try:
                                    xml_element = XMLElement.objects().get(pk=str(form_element.xml_element.id))
                                    xml_element.delete()
                                except:
                                    # raise an exception when element not found
                                    pass
                            form_element.delete()
                        except:
                            # raise an exception when element not found
                            pass
                    form_data.delete()
                except Exception, e:
                    return HttpResponseBadRequest('Unable to save data.')
                return HttpResponse('ok')
            except Exception, e:
                message = e.message.replace('"', '\'')
                return HttpResponseBadRequest(message)
Exemple #6
0
def curate_view_data(request):
    template = loader.get_template('curate/curate_view_data.html')

    # get form data from the database
    form_data_id = request.session['curateFormData']
    form_data = FormData.objects.get(pk=ObjectId(form_data_id))
    if not form_data.name.lower().endswith('.xml'):
        form_data.name += ".xml"
    form_name = form_data.name

    context = RequestContext(request, {
        'form_save': SaveDataForm({"title": form_name}),
    })
    if 'currentTemplateID' not in request.session:
        return redirect('/curate/select-template')
    else:
        return HttpResponse(template.render(context))