def embed (request): """ Receives a request with parameters URL and filter. Returns a JSON containing content of the embed. """ url = request.REQUEST.get("url") # ALLOW (authorized users) to trigger a resource to be added... if url.startswith("http://"): # TODO: REQUIRE LOGIN TO ACTUALLY ADD... add_resource(url, RDF_MODEL, request) ### APPLY FILTERS (if any) pipeline = request.REQUEST.get("filter", "embed").strip() filters = {} for filter_ in AAFilter.__subclasses__(): filters[filter_.name] = filter_ stdin = { 'original_url': url, 'local_url': Resource.objects.get(url=url).get_local_url(), 'local_path': Resource.objects.get(url=url).get_local_file(), 'output': 'None', 'extra_css': [], 'extra_js': [], 'script': "", } for command in [x.strip() for x in pipeline.split("|")]: if ":" in command: (filter_, arguments) = command.split(":", 1) filter_.strip() command.strip() else: (filter_, arguments) = (command.strip(), None) try: stdin = filters[filter_](arguments, stdin).stdout except KeyError: stdin['output'] = """The "%s" filter doesn't exist""" % filter_ break browseurl = reverse("aa-browse") + "?" + urllib.urlencode({'uri': url}) ret = """ <div class="aa_embed"> <div class="links"> <a class="directlink" href="%(url)s">URL</a> <a class="browselink" target="browser" href="%(browseurl)s">metadata</a> </div> <div class="body">%(embed)s</div> </div>""".strip() content = ret % {'url': url, 'browseurl': browseurl, 'embed': stdin['output']} return HttpResponse(json.dumps({"ok": True, "content": content, 'extra_css': stdin['extra_css'], 'extra_js': stdin['extra_js'], 'script': stdin['script']}), mimetype="application/json");
def handle(self, *args, **options): for arg in args: add_resource(arg)
def browse(request): """ Provides an interface to browse the RDF metadata of a :model:`aacore.Resource`. Creates the :model:`aacore.Resource` if the given URI isn't indexed yet. **Context** ``RequestContext`` ``resource`` An instance of :model:`aacore.Resource`. ``literal`` the current browsed litteral if any. Is loaded with an empty string if the browsed expression is a uri. ``uri`` the current browsed URI if any. ``namespaces`` A queryset of all :model:`aacore.Namespace`. ``links_as_rel`` To be documentated ``links_in`` To be documentated ``links_out`` To be documentated ``node_stats`` To be documentated **Template:** :template:`aacore/browse.html` """ uri = request.REQUEST.get("uri", "") # Avoids browsing an internal URL if is_local_url(uri): return HttpResponseRedirect(uri) scheme = urlparse(uri).scheme submit = request.REQUEST.get("_submit", "") if submit == "reload": add_resource(uri, RDF_MODEL, request, reload=True) else: # force every (http) resource to be added if scheme in ("file", "http", "https"): # TODO: REQUIRE LOGIN TO ACTUALLY ADD... add_resource(uri, RDF_MODEL, request) # RDF distinguishes URI and literals... literal = None if not scheme in ("file", "http", "https"): literal = uri context = {} context["namespaces"] = Namespace.objects.all() context["uri"] = uri context["literal"] = literal if literal: (node_stats, links_out, links_in, as_rel) = rdfutils.load_links(RDF_MODEL, context, literal=uri) else: (node_stats, links_out, links_in, as_rel) = rdfutils.load_links(RDF_MODEL, context, uri=uri) context["node_stats"] = node_stats context["links_out"] = links_out context["links_in"] = links_in context["links_as_rel"] = as_rel if not literal: try: resource = Resource.objects.get(url=uri) context["resource"] = resource except Resource.DoesNotExist: pass return render_to_response("aacore/browse.html", context, context_instance=RequestContext(request))