def shrink_url(url: str): # Check if url is legal if not _validate_url(url): print('Url is not valid!') return None # Check if url exists in db and return hash if it does query_result = db.get_shrinked_hash(url) if query_result is not None: return query_result # Generate new short url shrinked_hash = _generate_shrinked_hash() # Insert into db db.insert_url(url, shrinked_hash) return shrinked_hash
def on_new_url(self, request): error = None if request.method == "POST": url = request.form["url"] if not is_valid_url(url): error = "URL is not valide" else: url_id = insert_url(self.redis, url) return redirect("/%s_details" % url_id) return self.render_template("new_url.html", error=error)
def on_new_url(self, request): error = None url = "" if request.method == "POST": url = request.form["url"] if not is_valid_url(url): error = "Invalid url" else: short_id = insert_url(self.redis, url) return redirect('/%s_details' % short_id) return self.render_template("new_url.html", error=error, url=url)
def on_new_url(self, request): error = None url = "" if request.method == 'POST': url = request.form['url'] if not is_valid_url(url): error = 'invalid url' else: id = insert_url(self.redis, url) return redirect(b'/%s_details' % id) return self.render_template("new_url.html", error=error, url=url)
def on_new_url(self, request): error = None url = "" if request.method == 'POST': url = request.form['url'] if is_valid_url(url): url_id = insert_url(self.redis, url) return redirect('%s/detail' % url_id.decode('utf-8')) error = 'URL is not valid' return self.render_template("new_url.html", error=error, url=url)
def on_new_url(self, request): error = None url = "" if request.method == "POST": url = request.form['url'] if not is_valid_url(url): error = 'invalid url' else: id = insert_url(self.redis, url) if type(id) == bytes: return redirect('%s_details' % id.decode('utf-8')) return redirect('/%s_details' % id) return self.render_template("new_url.html", error=error, url=url)
def on_new_url(self, request): error = None url = '' if request.method == 'POST': url = request.form['url'] if(is_valid_url(url) == False): error = 'Not valid url' else: id = insert_url(self.redis,url) return redirect('%s'%id) return self.render_template("new_url.html", error=error, url=url)
def on_new_url(self, request): error = None url = "" if request.method == "POST": url = request.form['url'] if not is_valid_url(url): error = 'invalid url' else: id = insert_url(self.redis, url) return redirect('/%s_details' % str(id)) # TODO: Проверить что метод для создания новой ссылки "POST" # Проверить валидность ссылки используя is_valid_url # Если ссылка верна - создать запись в базе и # отправить пользователя на детальную информацию # Если неверна - написать ошибку return self.render_template("new_url.html", error=error, url=url)
def index(session): userId = session.get('id') url = request.forms.get('url') if len(url) > 200: return template('/var/bottle/template/user', username=username, errors='url too long', captcha='') captcha = request.forms.get('captcha') captcha = db.md5(captcha)[0:4] if captcha != session.get('captcha'): return bottle.redirect('/path?path=/user') username = db.find_user(userId) if (username): url_status = db.insert_url(userId, url) if (url_status == 1): return template('/var/bottle/template/success') if (url_status == 0): return template('/var/bottle/template/user', username=username, errors='submit failed', captcha='') else: return 'you are not login'