コード例 #1
0
ファイル: namespace.py プロジェクト: dodero/EasyData_Django
def editar_namespace(request, id):
    """
    This view shows a form to edit the info of a namespace, and reload the
    entities and properties
    :param request: the request of the view
    :param id: the primary key of the namespace
    :return: render the form
    """
    try:
        name = NameSpace.objects.get(id=id)
    except Exception:
        return redirect('easydata.views.namespace.listado_namespaces')

    #Obtengo la lista de paises existentes en la base de datos
    if request.POST:
        form = EditNamespaceForm(request.POST, request.FILES, instance=name)

        if form.is_valid():
            form.save()
            try:
                fich = None
                if form.cleaned_data["url"] != '':
                    fich = form.cleaned_data["url"]
                elif form.cleaned_data["archivo"]:
                    fich = form.cleaned_data["archivo"]

                if not fich is None:
                    parser = parser_factory(fich, form.cleaned_data["formato"],
                                            form.instance)

                    parser.parse()
                    parser.update()

                mensaje1 = _("The namespace was updated successfully.")
                mensaje2 = _("The namespace has ")
                mensaje2 += str(form.instance.entidades.all().count())
                mensaje2 += _(" entities and ")
                mensaje2 += str(form.instance.propiedades.all().count())
                mensaje2 += _(" properties")

                messages.info(request, mensaje1)
                messages.info(request, mensaje2)
                return redirect('easydata.views.namespace.listado_namespaces')
            except Exception:
                messages.info(request, _("There was an error, and the \
namespace couldn't be updated"))
        else:
            messages.info(request, _("There are errors in the form, please \
check it and send the form to update the namespace"))

    else:
        form = EditNamespaceForm(instance=name)

    #Renderizo la plantilla con el formulario
    return render_to_response('easydata/namespace/edit.html',
                              {'form': form, },
                              context_instance=RequestContext(request))
コード例 #2
0
def vista_carga_namespace(request):
    """
    This view shows a form to load a new namespace into the application.
    :param request: the request of the view
    :return: render the form
    """

    #Si hay datos en el POST, valido el formulario y creo el nuevo namespace
    if request.POST:
        form = NewNamespaceForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            try:
                if form.cleaned_data["url"] != '':
                    fich = form.cleaned_data["url"]
                else:
                    fich = form.cleaned_data["archivo"]

                parser = parser_factory(fich, form.cleaned_data["formato"],
                                        form.instance)

                parser.parse()
                parser.register()

                mensaje1 = _("The namespace was created successfully.")
                mensaje2 = _("The namespace has ")
                mensaje2 += str(form.instance.entidades.all().count())
                mensaje2 += _(" entities and ")
                mensaje2 += str(form.instance.propiedades.all().count())
                mensaje2 += _(" properties")

                messages.info(request, mensaje1)
                messages.info(request, mensaje2)

                return redirect('easydata.views.namespace.listado_namespaces')
            except Exception:
                form.instance.delete()
                messages.info(
                    request,
                    _("There was an error, and the \
namespace couldn't be created"))
        else:
            messages.info(
                request,
                _("There are errors in the form, please \
check it and send the form to create the namespace"))
    else:
        form = NewNamespaceForm()

    #Renderizo la plantilla con el formulario
    return render_to_response('easydata/namespace/new.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))
コード例 #3
0
ファイル: namespace.py プロジェクト: dodero/EasyData_Django
def vista_carga_namespace(request):
    """
    This view shows a form to load a new namespace into the application.
    :param request: the request of the view
    :return: render the form
    """

    #Si hay datos en el POST, valido el formulario y creo el nuevo namespace
    if request.POST:
        form = NewNamespaceForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            try:
                if form.cleaned_data["url"] != '':
                    fich = form.cleaned_data["url"]
                else:
                    fich = form.cleaned_data["archivo"]

                parser = parser_factory(fich, form.cleaned_data["formato"],
                                        form.instance)

                parser.parse()
                parser.register()

                mensaje1 = _("The namespace was created successfully.")
                mensaje2 = _("The namespace has ")
                mensaje2 += str(form.instance.entidades.all().count())
                mensaje2 += _(" entities and ")
                mensaje2 += str(form.instance.propiedades.all().count())
                mensaje2 += _(" properties")

                messages.info(request, mensaje1)
                messages.info(request, mensaje2)

                return redirect('easydata.views.namespace.listado_namespaces')
            except Exception:
                form.instance.delete()
                messages.info(request, _("There was an error, and the \
namespace couldn't be created"))
        else:
            messages.info(request, _("There are errors in the form, please \
check it and send the form to create the namespace"))
    else:
        form = NewNamespaceForm()

    #Renderizo la plantilla con el formulario
    return render_to_response('easydata/namespace/new.html',
                              {'form': form, },
                              context_instance=RequestContext(request))
コード例 #4
0
def editar_namespace(request, id):
    """
    This view shows a form to edit the info of a namespace, and reload the
    entities and properties
    :param request: the request of the view
    :param id: the primary key of the namespace
    :return: render the form
    """
    try:
        name = NameSpace.objects.get(id=id)
    except Exception:
        return redirect('easydata.views.namespace.listado_namespaces')

    #Obtengo la lista de paises existentes en la base de datos
    if request.POST:
        form = EditNamespaceForm(request.POST, request.FILES, instance=name)

        if form.is_valid():
            form.save()
            try:
                fich = None
                if form.cleaned_data["url"] != '':
                    fich = form.cleaned_data["url"]
                elif form.cleaned_data["archivo"]:
                    fich = form.cleaned_data["archivo"]

                if not fich is None:
                    parser = parser_factory(fich, form.cleaned_data["formato"],
                                            form.instance)

                    parser.parse()
                    parser.update()

                mensaje1 = _("The namespace was updated successfully.")
                mensaje2 = _("The namespace has ")
                mensaje2 += str(form.instance.entidades.all().count())
                mensaje2 += _(" entities and ")
                mensaje2 += str(form.instance.propiedades.all().count())
                mensaje2 += _(" properties")

                messages.info(request, mensaje1)
                messages.info(request, mensaje2)
                return redirect('easydata.views.namespace.listado_namespaces')
            except Exception:
                messages.info(
                    request,
                    _("There was an error, and the \
namespace couldn't be updated"))
        else:
            messages.info(
                request,
                _("There are errors in the form, please \
check it and send the form to update the namespace"))

    else:
        form = EditNamespaceForm(instance=name)

    #Renderizo la plantilla con el formulario
    return render_to_response('easydata/namespace/edit.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))