(request)
| 11 | |
| 12 | @expose("/") |
| 13 | def 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>") |
nothing calls this directly
no test coverage detected