Exemplo n.º 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)
Exemplo n.º 2
0
def update_publish(request):
    XMLdata.update_publish(request.GET['result_id'])
    resource = XMLdata.get(request.GET['result_id'])

    # Send mail to the user and the admin
    context = {'URI': MDCS_URI,
               'title': resource['title'],
               'publicationdate': resource['publicationdate'],
               'user': request.user.username}

    send_mail_to_managers(subject='Resource Published',
                                pathToTemplate='dashboard/email/resource_published.html',
                                context=context)
    return HttpResponse(json.dumps({}), content_type='application/javascript')
Exemplo n.º 3
0
def update_publish(request):
    XMLdata.update_publish(request.GET['result_id'])
    resource = XMLdata.get(request.GET['result_id'])

    # Send mail to the user and the admin
    context = {
        'URI': MDCS_URI,
        'title': resource['title'],
        'publicationdate': resource['publicationdate'],
        'user': request.user.username
    }

    send_mail_to_managers(
        subject='Resource Published',
        pathToTemplate='dashboard/email/resource_published.html',
        context=context)
    return HttpResponse(json.dumps({}), content_type='application/javascript')
Exemplo n.º 4
0
def update_publish(request):
    XMLdata.update_publish(request.GET['result_id'])
    return HttpResponse(json.dumps({}), content_type='application/javascript')