Exemple #1
0
def add_external_resource(req):
    url = req.POST.get("url")
    try:
        # check if url already in models
        resource = ExternalResource.objects.get(url=url)
        log_to_file("resource %s chosen" % resource.filename)
    except:
        # else create resource
        resource = ExternalResource(url=url)
        resource.save()
        log_to_file("resource %s created" % resource.filename)
    return HttpResponse(
        simplejson.dumps(
            {"id": resource.id, "url": resource.url, "filename": resource.filename, "extension": resource.extension}
        ),
        mimetype="application/javascript",
    )
Exemple #2
0
def add_external_resource(req):
    " add external url "
    url = req.POST.get('url')
    if not url:
        return HttpResponseNotAllowed('Please provide url')
    try:
        # check if url already in models
        resource = ExternalResource.objects.get(url=url)
        #log_to_file('resource %s chosen' % resource.filename)
    except:
        # else create resource
        resource = ExternalResource(url=url)
        resource.save()
        #log_to_file('resource %s created' % resource.filename)

    return HttpResponse(simplejson.dumps({
            'id': resource.id,
            'url': resource.url,
            'filename': resource.filename,
            'extension': resource.extension
        }), mimetype="application/json")