def delete(short_url): id = saturate(short_url) short_url_db = ShortUrl.query.get(id) if short_url_db is None: flash('Url "{0}" is not registered'.format(short_url)) return redirect(url_for('index')) full_url_db = short_url_db.full_url db.session.delete(short_url_db) db.session.delete(full_url_db) db.session.commit() return redirect(url_for('index'))
def redirect_to(short_url): try: id = saturate(short_url) except: return redirect(url_for('index')) short_url_db = ShortUrl.query.get(id) if short_url_db is None: flash('Url "{0}" not registered'.format(short_url)) return redirect(url_for('index')) full_url_db = short_url_db.full_url if short_url_db.delete_after_first_usage: db.session.delete(short_url_db) db.session.delete(full_url_db) db.session.commit() return redirect(full_url_db.url)