Esempio n. 1
0
def admin_check_availability(request):
    """ Respond to the "/admin/check_availability" URL.

        We let the user enter a name, and see if that name is available.
    """
    if not auth_controller.is_logged_in(request):
        return HttpResponseRedirect(auth_controller.get_login_url())

    if request.method == "GET":
        # We're showing the form for the first time -> prepare our form
        # parameters.
        name     = ""
        response = None
    elif request.method == "POST":
        if request.POST['submit'] == "check":
            name = request.POST['name']
            response = None # initially.

            if name == "":
                response = "You must enter a name to check!"

            if response == None:
                if nameChecker.is_available(name):
                    response = "That name is available."
                else:
                    response = "Sorry, that name is taken."
        elif request.POST['submit'] == "done":
            return HttpResponseRedirect("/admin")

    # If we get here, show the "check availability" page to the user.

    return render(request, "website/check_availability.html",
                  {'name'     : name,
                   'response' : response})
Esempio n. 2
0
def is_reserved(request, name):
    """ Implement the 'api/is_reserved' endpoint.
    """
    available = nameChecker.is_available(name)

    if available:
        response = {'reserved' : False}
    else:
        response = {'reserved' : True}

    return HttpResponse(json.dumps(response),
                        content_type="application/json")