예제 #1
0
 def edit(self, bookmark_id):
     if not users.get_current_user():
         webapp2.abort(401)
     bookmark = db.get(db.Key.from_path('Bookmark', int(bookmark_id)))
     form = BookmarkForm(self.get_locale(), self.request.POST, bookmark)
     if self.request.POST and form.validate():
         form.populate_obj(bookmark)
         bookmark.date = datetime.now()
         bookmark.put()
         return self.redirect('/bookmark/list')
     self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark', 'id': bookmark.key().id()})
예제 #2
0
def add_bookmark():
    if not session.get('logged_in'):
        abort(401)
    form = BookmarkForm(request.form)
    if request.method == 'POST' and form.validate():
        if form.url.data and form.description.data:
            author = User.query.filter_by(username=session.get('username')).first()
            bookmark = Bookmark(form.url.data, form.description.data, datetime.utcnow(), author)
            db.session.add(bookmark)
            db.session.commit()
            flash('New bookmark saved successfully')
        else:
            flash('URL is required.')
    return redirect(url_for('show_bookmarks'))
예제 #3
0
 def create(self, parent_id=None):
     if not users.get_current_user():
         webapp2.abort(401)
     form = BookmarkForm(self.get_locale(), self.request.POST, None)
     if self.request.POST and form.validate():
         parent = None
         if form.reference_id.data:
             parent = db.get(db.Key.from_path('Bookmark', int(form.reference_id.data)))
         bookmark = Bookmark(author=users.get_current_user(), reference=parent, title=form.title.data, url=form.url.data)
         bookmark.date = datetime.now()
         bookmark.put()
         return self.redirect('/bookmark/list')
     else:
         if parent_id:
             form.reference_id.data = parent_id
     self.render_template('form.html', {'title': _('Bookmark'), 'form': form, 'name': 'bookmark'})