MCPcopy
hub / github.com/pallets/werkzeug / new

Function new

examples/couchy/views.py:13–36  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

11
12@expose("/")
13def new(request):
14 error = url = ""
15 if request.method == "POST":
16 url = request.form.get("url")
17 alias = request.form.get("alias")
18 if not validate_url(url):
19 error = "I'm sorry but you cannot shorten this URL."
20 elif alias:
21 if len(alias) > 140:
22 error = "Your alias is too long"
23 elif "/" in alias:
24 error = "Your alias might not include a slash"
25 elif URL.load(alias):
26 error = "The alias you have requested exists already"
27 if not error:
28 url = URL(
29 target=url,
30 public="private" not in request.form,
31 shorty_id=alias if alias else None,
32 )
33 url.store()
34 uid = url.id
35 return redirect(url_for("display", uid=uid))
36 return render_template("new.html", error=error, url=url)
37
38
39@expose("/display/<uid>")

Callers

nothing calls this directly

Calls 8

storeMethod · 0.95
redirectFunction · 0.90
loadMethod · 0.80
validate_urlFunction · 0.70
URLClass · 0.70
url_forFunction · 0.70
render_templateFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected