Beispiel #1
0
def newlink():
	form = NewLinkForm()
	form.folder.choices = [(f.id, f.label) for f in g.user.folders.all()]
	if form.url.data:
		if form.validate_on_submit():
			url_raw = form.url.data
			if url_raw[0:7] == 'http://' or url_raw[0:8] == 'https://':
				url_clean = url_raw
			else:
				url_clean = 'http://' + url_raw
			title = form.title.data
			annotation = form.annotation.data
			try:
				folder = int(form.folder.data)
			except ValueError:
				folder = g.user.folders.all()[0].id
			timestamp = datetime.utcnow()
			user_id = g.user.id
			link = Link(title = title,
				url = url_clean,
				annotation = annotation, 
				timestamp = timestamp,
				folder_id = folder, 
				user_id = user_id)
			db.session.add(link)
			db.session.commit()
			flash('Link added.')
			return redirect(url_for('index'))
		flash('The form didn\'t validate.  Make sure you have both a title and URL.')
	return render_template('newlink.html', user = g.user, form = form)
Beispiel #2
0
def index():
    form = NewLinkForm()
    if form.validate_on_submit():
        session['source_url'] = form.source_url.data
        return redirect(url_for('new_poster'))
    session.pop('source_url', None)
    return render_template('index.html', form=form, upload_form=UploadForm())
Beispiel #3
0
def new_url(request):
    if request.method == "POST":
        form = NewLinkForm(request.POST)
        if form.is_valid():
            link = form.save()
            url = "http://localhost:9000/link/%s" % link.key
            return HttpResponseRedirect(url)
    else:
        form = NewLinkForm()

    return locals()
Beispiel #4
0
def home(request):
    if request.method == 'POST':
        form = NewLinkForm(request.POST)
        if form.is_valid():
            form.save()

    form = NewLinkForm()

    links = Link.objects.all()

    data = {
        'links': links,
        'form': form
    }

    return render(request, 'home.html', data)
Beispiel #5
0
def upload():
    form = UploadForm()
    if form.validate_on_submit():
        upload_result = cloudinary_upload(form.file.data)
        session['source_url'] = upload_result['secure_url']
        flash('Your poster has been successfully uploaded!')
        return redirect(url_for('new_poster'))
    return render_template('index.html', form=NewLinkForm(), upload_form=form)
Beispiel #6
0
def home(request):
    if request.method == 'POST':
        form = NewLinkForm(request.POST)
        if form.is_valid():
            form.save()

    form = NewLinkForm()

    links = Link.objects.all()

    data = {'links': links, 'form': form}

    return render(request, 'home.html', data)
Beispiel #7
0
def new_url(request):
    if request.method == 'POST':
        form = NewLinkForm(request.POST)
        if form.is_valid():
            link = form.save()
            url = "http://localhost:9000/link/%s" % link.key
            return HttpResponseRedirect(url)
    else:
        form = NewLinkForm()

    return locals()