Ejemplo n.º 1
0
def new(request):
    error = url = ''
    if request.method == 'POST':
        url = request.form.get('url')
        alias = request.form.get('alias')
        if not validate_url(url):
            error = "I'm sorry but you cannot shorten this URL."
        elif alias:
            if len(alias) > 140:
                error = 'Your alias is too long'
            elif '/' in alias:
                error = 'Your alias might not include a slash'
            elif URL.query.get(alias):
                error = 'The alias you have requested exists already'
        if not error:
            uid = URL(url, 'private' not in request.form, alias).uid
            session.commit()
            return redirect(url_for('display', uid=uid))
    return render_template('new.html', error=error, url=url)
Ejemplo n.º 2
0
def new(request):
    error = url = ''
    if request.method == 'POST':
        url = request.form.get('url')
        alias = request.form.get('alias')
        if not validate_url(url):
            error = "I'm sorry but you cannot shorten this URL."
        elif alias:
            if len(alias) > 140:
                error = 'Your alias is too long'
            elif '/' in alias:
                error = 'Your alias might not include a slash'
            elif URL.query.get(alias):
                error = 'The alias you have requested exists already'
        if not error:
            uid = URL(url, 'private' not in request.form, alias).uid
            session.commit()
            return redirect(url_for('display', uid=uid))
    return render_template('new.html', error=error, url=url)
Ejemplo n.º 3
0
 def short_url(self):
     return url_for('link', uid=self.uid, _external=True)
Ejemplo n.º 4
0
 def short_url(self):
     return url_for('link', uid=self.uid, _external=True)