Ejemplo n.º 1
0
def load(request):
  if request.method != "POST": return INDEX
  form = LoadForm(request.POST)
  result = {"load_form":form, "query_form": QueryForm()}
  if form.is_valid():
    load_type = form.cleaned_data.get("load_type")
    rdf_content = form.cleaned_data.get("rdf_content")
    if not rdf_content: 
      messages.add_message(request, messages.ERROR, "Please enter some content!")
      return result
    try:
      storage = RDFStorage()
      storage.storeData(rdf_content, load_type)
      messages.add_message(request, messages.INFO, "New RDFStorage could be successfully created!")
    except Exception, e:
      result.update({"exception": e})
Ejemplo n.º 2
0
def query(request):
  if request.method != "POST": return INDEX

  form = QueryForm(request.POST)
  result = {"load_form":LoadForm(), "query_form": form}
  if form.is_valid():
    rdf_query = form.cleaned_data.get("rdf_query")
    format = form.cleaned_data.get("output_type", "xml")

    if not rdf_query:
      messages.add_message(request, messages.ERROR, "Please enter a query!")
      return result
    try:
      queryResult = RDFStorage().query(rdf_query)
      stringResult = queryResult.serialize(format = format)
      if format == "xml":
        xml = minidom.parseString(stringResult)
        stringResult = xml.toprettyxml()
      elif format == "json":
        stringResult = json.dumps(json.loads(stringResult), sort_keys = False, indent = 4)
      result.update({"result" : stringResult, "format":format})
    except Exception, e:
      result.update({"exception" : e})