def add_url(): form = UrlForm() if form.validate_on_submit(): url = Url(original_url=form.original_url.data) db.session.add(url) db.session.commit() return redirect('/index') return render_template('add_url.html', title='Add Url', form=form)
def index(): form = UrlForm() short_url = None base_url = request.url_root if form.validate_on_submit(): existing_url = URL.query.filter_by(url=form.url.data).first() if existing_url: short_url = f'{base_url}{UrlShortner.id_to_url(existing_url.id)}' else: new_url = URL(url=form.url.data) db.session.add(new_url) db.session.commit() short_url = f'{base_url}{UrlShortner.id_to_url(new_url.id)}' return render_template('index.html', form=form, short_url=short_url)
def generate(): form = UrlForm() if form.validate_on_submit(): url = form.url.data host = request.host print(host) link = Links.query.filter_by(full_url=url).first() if link: return render_template('generate.html', short_link=link.short_url) else: code = secrets.token_hex(3) short_url = host + '/' + code link = Links(full_url=url, short_url=short_url) db.session.add(link) db.session.commit() return render_template('generate.html', form=form, short_link=short_url) return render_template('generate.html', form=form)
def urlUnregistered(request): """Process Request of form URL""" if request.method == "POST": form = UrlForm(request.POST) print form if form.is_valid(): url = form.cleaned_data['urlProject'] print url idProject = processStringUrl(url) #http://sarabc.pencilcode.net/load/first print "Project to analyze:", idProject if idProject == "error": d = {'Error': 'id_error'} return d else: try: (pathProject, file) = sendRequestgetJSON(idProject) except: #WHEN YOUR PROJECT DOESN'T EXIST d = {'Error': 'no_exists'} return d try: # pathProject -> /home/sara/drPencilcode-master/uploads/47.json # request -> <WSGIRequest: POST '/selector'> d = analyzeProject(request, pathProject, file) except IndentationError: # FIXME #There is an error with kutz or hairball #We save the project in folder called error_analyzing print "Something went wrong" file.method = 'url/error' file.save() oldPathProject = pathProject newPathProject = pathProject.split("/uploads/")[0] + \ "/error_analyzing/" + \ pathProject.split("/uploads/")[1] shutil.copy(oldPathProject, newPathProject) d = {'Error': 'analyzing'} return d # Redirect to dashboard for unregistered user d['Error'] = 'None' return d else: d = {'Error': 'MultiValueDict'} return d else: return HttpResponseRedirect('/')
def url(): form = UrlForm() dform = DownloadForm() if form.validate_on_submit(): algo = form.algo.data url = form.url.data num = form.sentences.data text = url_extract(url) result = select_algorithm(algo, text, num) return render_template('url_input.html', title='URL', results=result, form=form, dform=dform) return render_template('url_input.html', title='URL', form=form)
def index(): form = UrlForm() # Does all of the form processing work. # Returns true if nothing went wrong retrieving the data. if form.validate_on_submit(): if is_valid_url(form.url.data): shortlink = generate_shortlink() shorturl = ShortUrl(shortlink=shortlink, link=form.url.data) db.session.add(shorturl) db.session.commit() flash('Request to shorten URL {}'.format(form.url.data)) flash('At extension {}'.format(shortlink)) return redirect(url_for('results', link=shortlink)) else: flash('Request to shorten URL {} failed'.format(form.url.data)) return redirect(url_for('results')) return render_template('index.html', form=form)
def index(): form = UrlForm() link = Url() if form.validate_on_submit(): if form.submit.data: tmp = form.url_link.data if re.match( r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tmp): generate_short_link() else: flash('Invalid url') return render_template('index.html', form=form, link=link) elif form.submit2.data: pass link = Url.query.filter_by(url_link=form.url_link.data).all() return render_template( 'index.html', form=form, link=link, )
def urlUnregistered(request): """Process Request of form URL""" if request.method == "POST": form = UrlForm(request.POST) if form.is_valid(): url = form.cleaned_data['urlProject'] idProject = processStringUrl(url) print "Project to analyze:", idProject if idProject == "error": d = {'Error': 'id_error'} return d else: try: (pathProject, file) = sendRequestgetJSON(idProject) except: #WHEN YOUR PROJECT DOESN'T EXIST d = {'Error': 'no_exists'} return d try: d = analyzeProject(request, pathProject) except IndentationError: # FIXME #There ir an error with kutz or hairball #We save the project in folder called error_analyzing print "Something went wrong" file.method = 'url/error' file.save() oldPathProject = pathProject newPathProject = pathProject.split("/uploads/")[0] + \ "/error_analyzing/" + \ pathProject.split("/uploads/")[1] shutil.copy(oldPathProject, newPathProject) d = {'Error': 'analyzing'} return d # Redirect to dashboard for unregistered user d['Error'] = 'None' return d else: d = {'Error': 'MultiValueDict'} return d else: return HttpResponseRedirect('/')
def urlUnregistered(request): """Process Request of form URL""" if request.method == "POST": form = UrlForm(request.POST) if form.is_valid(): url = form.cleaned_data['urlProject'] idProject = processStringUrl(url) if idProject == "error": d = {'Error': 'id_error'} return d else: #WHEN YOUR PROJECT DOESN'T EXIST try: (pathProject, file) = sendRequestgetSB2(idProject) except: d = {'Error': 'no_exists'} return d try: d = analyzeProject(request, pathProject) except: #There ir an error with kutz or hairball #We save the project in folder called error_analyzing file.method = 'url/error' file.save() oldPathProject = pathProject newPathProject = pathProject.split("/uploads/")[0] + \ "/error_analyzing/" + \ pathProject.split("/uploads/")[1] shutil.copy(oldPathProject, newPathProject) d = {'Error': 'analyzing'} return d # Redirect to dashboard for unregistered user d['Error'] = 'None' return d else: d = {'Error': 'MultiValueDict'} return d else: return HttpResponseRedirect('/')
def generate_short_link(): form = UrlForm() username = current_user if current_user.is_authenticated: us_link = Url(url_link=form.url_link.data, user_id=username.id) us_link.create_short_link(form.url_link.data) db.session.add(us_link) db.session.commit() else: us_link = Url(url_link=form.url_link.data) us_link.create_short_link(form.url_link.data) db.session.add(us_link) db.session.commit()