예제 #1
0
 def post(self, request):
     form_instance = BookmarkForm(request.POST)
     hashids = Hashids()
     if form_instance.is_valid():
         url_object = form_instance.save()
         hashid = hashids.encode(url_object.id)
         url_object.output_url=hashid
         url_object.save()
         bookmarks = Bookmark.objects.all()
     return render(request, 'index.html', {"bookmarks":bookmarks,
                                             'url': url_object})
예제 #2
0
def edit_bookmark(bookmark_id):
    bookmark = Bookmark.query.get_or_404(bookmark_id)
    if current_user != bookmark.user:
        abort(403)
    form = BookmarkForm(obj=bookmark)  # fill form with the data from the database
    if form.validate_on_submit():
        form.populate_obj(bookmark)  # copy form data into bookmark
        db.session.commit()            # bookmark object is already in the session since we made a get
        flash('Stored "{}"'.format(bookmark.description))
        return redirect(url_for('user', username=current_user.username))
    return render_template('bookmark_form.html', form=form, title= "Edit bookmark")
예제 #3
0
def add():
    # if get, form is empty, but if post, form has data
    form = BookmarkForm()
    # if request.method == "POST":
    if form.validate_on_submit():
        # url = request.form['url']
        url = form.url.data
        description = form.description.data
        bm = Bookmark(user=current_user, url=url, description=description)
        db.session.add(bm)
        db.session.commit()
        flash('Stored {0}'.format(description))
        return redirect(url_for('index'))
    return render_template("add.html", form=form)
예제 #4
0
파일: app_tests.py 프로젝트: marcusti/links
 def test_empty_link_form(self):
     form = BookmarkForm(csrf_enabled=False)
     form.process()
     form.validate()
     assert 'url' in form.errors
     assert 'name' in form.errors
예제 #5
0
파일: app_tests.py 프로젝트: marcusti/links
 def test_link_form(self):
     form = BookmarkForm(csrf_enabled=False)
     form.process(name=u'example', url=u'http://www.example.com/')
     form.validate()
     assert form.errors == {}