Ejemplo n.º 1
0
def create(request):
    """ Given the json representation of a bookmark, creates it
    
    The bookmark must have been from "to_json", and must be the "obj" POST value.
    
    If it succeeds it returns a JSON object with "obj" being the JSON representation of the bookmark, "type" which
    is always "bookmark" and "id" which is the id of the newly created bookmark.
    """
    if "obj" not in request.POST:
        raise SuspiciousOperation
    
    try:
        bm = Bookmark.from_json(request.POST.get("obj"), request.user)
    except Exception:
        raise SuspiciousOperation
    
    out = {}
    out["type"] = "bookmark"
    out["obj"] = bm.to_json()
    out["id"] = bm.pk
    
    return HttpResponse(json.dumps(out), content_type="application/json")