def test_displays_only_items_for_that_list(self):
        correct_list = List()
        db_session.add(correct_list)
        db_session.commit()
        item_01 = Item(text='itemey 1', list=correct_list.id)
        item_02 = Item(text='itemey 2', list=correct_list.id)
        db_session.add(item_01)
        db_session.add(item_02)
        db_session.commit()

        other_list = List()
        db_session.add(other_list)
        db_session.commit()
        other_item_01 = Item(text='다른 목록 아이템 1', list=other_list.id)
        other_item_02 = Item(text='다른 목록 아이템 2', list=other_list.id)

        with app.test_request_context('/lists/%d' % correct_list.id):
            res = view_list(list_id=correct_list.id)
            assert item_01.text in res
            assert item_02.text in res
            assert other_item_01.text not in res
            assert other_item_02.text not in res
            Item.query.filter(Item.list == correct_list.id).delete()
            Item.query.filter(Item.list == other_list.id).delete()
            db_session.commit()
            List.query.filter(List.id == correct_list.id).delete()
            List.query.filter(List.id == other_list.id).delete()
            db_session.commit()
예제 #2
0
 def removeAssociation(self, server_url, handle):
     try:
         return OpenIDAssociation.query.filter(
             (OpenIDAssociation.server_url == server_url)
             & (OpenIDAssociation.handle == handle)).delete()
     finally:
         db_session.commit()
예제 #3
0
def create():
    category_id = None
    preview = None
    print "1111111111111111"
    if 'category' in request.args:
        rv = Category.query.filter_by(slug=request.args['category']).first()
        if rv is not None:
            category_id = rv.id
    if request.method == 'POST':
        print "5555555"
        category_id = request.form.get('category', type=int)
        if 'preview' in request.form:
            preview = format_creole(request.form['body'])
        else:
            title = request.form['title']
            body = request.form['body']
            print "22222222222"
            if not body:
                flash(u'Error: you have to enter a snippet')
            else:
                category = Category.query.get(category_id)
                if category is not None:
                    posts = Post(g.user, category, title, body, category)
                    db_session.add(posts)
                    db_session.commit()
                    flash(u'Your snippet was added')
                    print "tttttttttttt"
                    return redirect(posts.url)
    return render_template('blog/create.html',
                           categories=Category.query.order_by(
                               Category.name).all(),
                           active_category=category_id,
                           preview=preview)
예제 #4
0
def delete_category(id):
    category = Category.query.get(id)
    if category is None:
        abort(404)
    if request.method == 'POST':
        if 'cancel' in request.form:
            flash(u'Deletion was aborted')
            return redirect(url_for('.manage_categories'))
        move_to_id = request.form.get('move_to', type=int)
        if move_to_id:
            move_to = Category.query.get(move_to_id)
            if move_to is None:
                flash(u'Category was removed in the meantime')
            else:
                for post in category.posts.all():
                    post.category = move_to
                db_session.delete(category)
                flash(u'Category %s deleted and entries moved to %s.' %
                      (category.name, move_to.name))
        else:
            category.posts.delete()
            db_session.delete(category)
            flash(u'Category %s deleted' % category.name)
        db_session.commit()
        return redirect(url_for('.manage_categories'))
    return render_template('posts/delete_category.html',
                           category=category,
                           other_categories=Category.query.filter(
                               Category.id != category.id).all())
예제 #5
0
def new():
    category_id = None
    preview = None
    if 'category' in request.args:
        rv = Category.query.filter_by(slug=request.args['category']).first()
        if rv is not None:
            category_id = rv.id
    if request.method == 'POST':
        category_id = request.form.get('category', type=int)
        if 'preview' in request.form:
            preview = format_creole(request.form['body'])
        else:
            title = request.form['title']
            body = request.form['body']
            if not body:
                flash(u'Error: you have to enter a post')
            else:
                category = Category.query.get(category_id)
                if category is not None:
                    post = Post(g.user, title, body, category)
                    db_session.add(post)
                    db_session.commit()
                    flash(u'Your post was added')
                    return redirect(post.url)
    return render_template('posts/new.html',
                           categories=Category.query.order_by(
                               Category.name).all(),
                           active_category=category_id,
                           preview=preview)
예제 #6
0
 def cleanupNonces(self):
     try:
         return OpenIDUserNonce.query.filter(
             OpenIDUserNonce.timestamp <= int(time() -
                                              nonce.SKEW)).delete()
     finally:
         db_session.commit()
예제 #7
0
def edit_comment(id):
    comment = Comment.query.get(id)
    if comment is None:
        abort(404)
    form = dict(title=comment.title, text=comment.text)
    if request.method == 'POST':
        if 'delete' in request.form:
            db_session.delete(comment)
            db_session.commit()
            flash(u'Comment was deleted.')
            return redirect(comment.post.url)
        elif 'cancel' in request.form:
            return redirect(comment.post.url)
        form['title'] = request.form['title']
        form['text'] = request.form['text']
        if not form['text']:
            flash(u'Error: comment text is required.')
        else:
            comment.title = form['title']
            comment.text = form['text']
            db_session.commit()
            flash(u'Comment was updated.')
            return redirect(comment.post.url)
    return render_template('posts/edit_comment.html',
                           form=form,
                           comment=comment)
예제 #8
0
def new_list():
    list_ = List()
    db_session.add(list_)
    db_session.commit()
    item = Item(text=request.form['item_text'], list=list_.id)
    db_session.add(item)
    db_session.commit()
    return redirect(url_for('base.view_list', list_id=list_.id))
예제 #9
0
 def storeAssociation(self, server_url, association):
     assoc = OpenIDAssociation(server_url=server_url,
                               handle=association.handle,
                               secret=association.secret.encode('base64'),
                               issued=association.issued,
                               lifetime=association.lifetime,
                               assoc_type=association.assoc_type)
     db_session.add(assoc)
     db_session.commit()
예제 #10
0
def addpost():
    if request.method == 'POST':
        db_session.add(
            Post(title=request.form['title'],
                 body=request.form['content'],
                 category_id=request.form['category'],
                 post_name=request.form['postname']))
        db_session.commit()
        return render_template('blog/create2.html',
                               content=request.form['content'])
예제 #11
0
def delete_post(post_id):
    try:
        post = dao.query(Post).filter_by(id=post_id).one()
        dao.delete(post)
        dao.commit()
        return redirect(url_for('index'))
    except NoResultFound:
        abort(404)
    except MultipleResultsFound:
        abort(404)
예제 #12
0
def delete_comment(post_id, comment_id):
    try:
        comment = Comment.query.filter_by(id=comment_id).one()
        dao.delete(comment)
        dao.commit()
        return redirect(url_for('read_post', post_id=post_id))
    except NoResultFound:
        abort(404)
    except MultipleResultsFound:
        abort(404)
 def test_redirects_after_post(self):
     with app.test_client() as client:
         rv = client.post('/lists/new', data=dict(item_text='신규 작업 아이템'))
         # print(rv) <Response streamed [302 FOUND]>
         # print(type(rv)) <class 'flask.wrappers.Response'>
         assert rv.status_code == 302
         assert '/lists/' in rv.location
         assert request.path == '/lists/new'
         Item.query.filter(Item.text == '신규 작업 아이템').delete()
         db_session.commit()
         assert Item.query.filter(Item.text == '신규 작업 아이템').count() == 0
예제 #14
0
def manage_categories():
    categories = Category.query.order_by(Category.name).all()
    if request.method == 'POST':
        for category in categories:
            category.name = request.form['name.%d' % category.id]
            category.slug = request.form['slug.%d' % category.id]
        db_session.commit()
        flash(u'Categories updated')
        return redirect(url_for('.manage_categories'))
    return render_template('posts/manage_categories.html',
                           categories=categories)
예제 #15
0
def create_post():
    title = request.form.get('title', None)
    created_at = datetime.now()
    content = request.form.get('content', None)
    new_post = Post(title, created_at, content)
    try:
        dao.add(new_post)
        dao.commit()
        return redirect(url_for('read_post', post_id=new_post.id))
    except:
        return redirect(url_for('index'))
    def test_can_save_a_post_request_to_an_existing_list(self):
        other_list = List()
        correct_list = List()

        db_session.add(other_list)
        db_session.add(correct_list)
        db_session.commit()

        with app.test_client() as client:
            client.post('/lists/%d/add_item' % (correct_list.id, ),
                        data=dict(item_text='기존 목록에 신규 아이템'))
    def test_saving_a_post_request(self):
        with app.test_client() as client:
            keyword = '포스트 저장용'
            client.post('/lists/new', data=dict(item_text=keyword))
            items = Item.query.filter(Item.text == '포스트 저장용').all()

            # 마지막에 추가된 레코드
            assert items[0].text == keyword
            Item.query.filter(Item.text == '포스트 저장용').delete()
            db_session.commit()
            assert Item.query.filter(Item.text == '포스트 저장용').count() == 0
예제 #18
0
def profile():
    name = g.user.name
    if request.method == 'POST':
        name = request.form['name'].strip()
        if not name:
            flash(u'Error: a name is required')
        else:
            g.user.name = name
            db_session.commit()
            flash(u'User profile updated')
            return redirect(url_for('.index'))
    return render_template('general/profile.html', name=name)
예제 #19
0
def show(id):
    snippet = Snippet.query.get(id)
    if snippet is None:
        abort(404)
    if request_wants_json():
        return jsonify(snippet=snippet.to_json())
    if request.method == 'POST':
        title = request.form['title']
        text = request.form['text']
        if text:
            db_session.add(Comment(snippet, g.user, title, text))
            db_session.commit()
            flash(u'Your comment was added')
            return redirect(snippet.url)
    return render_template('snippets/show.html', snippet=snippet)
예제 #20
0
def update_post(post_id):
    try:
        post = dao.query(Post).filter_by(id=post_id).one()
        title = request.form.get('title', None)
        content = request.form.get('content', None)
        post.title = title
        post.content = content
        dao.commit()
        return redirect(url_for('read_post', post_id=post_id))
    except NoResultFound:
        abort(404)
    except MultipleResultsFound:
        abort(404)
    except:
        return redirect(url_for('index'))
예제 #21
0
def create_or_login(resp):
    session['openid'] = resp.identity_url
    user = g.user or User.query.filter_by(openid=resp.identity_url).first()
    if user is None:
        return redirect(
            url_for('.first_login',
                    next=oid.get_next_url(),
                    name=resp.fullname or resp.nickname))
    if user.openid != resp.identity_url:
        user.openid = resp.identity_url
        db_session.commit()
        flash(u'OpenID identity changed')
    else:
        flash(u'Successfully signed in')
    return redirect(oid.get_next_url())
예제 #22
0
 def useNonce(self, server_url, timestamp, salt):
     if abs(timestamp - time()) > nonce.SKEW:
         return False
     rv = OpenIDUserNonce.query.filter(
         (OpenIDUserNonce.server_url == server_url)
         & (OpenIDUserNonce.timestamp == timestamp)
         & (OpenIDUserNonce.salt == salt)).first()
     if rv is not None:
         return False
     rv = OpenIDUserNonce(server_url=server_url,
                          timestamp=timestamp,
                          salt=salt)
     db_session.add(rv)
     db_session.commit()
     return True
예제 #23
0
def first_login():
    if g.user is not None or 'openid' not in session:
        return redirect(url_for('.login'))
    if request.method == 'POST':
        if 'cancel' in request.form:
            del session['openid']
            flash(u'Login was aborted')
            return redirect(url_for('general.login'))
        db_session.add(User(request.form['name'], session['openid']))
        db_session.commit()
        flash(u'Successfully created profile and logged in')
        return redirect(oid.get_next_url())
    return render_template('general/first_login.html',
                           next=oid.get_next_url(),
                           openid=session['openid'])
예제 #24
0
def show(id):
    post = Post.query.get(id)
    if post is None:
        abort(404)
    if request_wants_json():
        return jsonify(post=post.to_json())
    if request.method == 'POST':
        title = request.form['title']
        text = request.form['text']
        if text:
            db_session.add(Comment(post, g.user, title, text))
            db_session.commit()
            flash(u'Your comment was added')
            return redirect(post.url)
        else:
            flash(u'Your comment was not added')
    return render_template('posts/show.html', post=post)
예제 #25
0
def create_comment(post_id):
    try:
        post = dao.query(Post).filter_by(id=post_id).one()
        name = request.form.get('name', None)
        created_at = datetime.now()
        content = request.form.get('content', None)
        ip = request.remote_addr
        new_comment = Comment(name, created_at, content, post_id, ip=ip)
        dao.add(new_comment)
        dao.commit()
        return redirect(request.referrer
                        or url_for('read_post', post_id=post_id))
    except NoResultFound:
        abort(404)
    except MultipleResultsFound:
        abort(404)
    except:
        pass
예제 #26
0
def edit(id):
    snippet = Snippet.query.get(id)
    if snippet is None:
        abort(404)
    if g.user is None or (not g.user.is_admin and snippet.author != g.user):
        abort(401)
    preview = None
    form = dict(title=snippet.title,
                body=snippet.body,
                category=snippet.category.id)
    if request.method == 'POST':
        form['title'] = request.form['title']
        form['body'] = request.form['body']
        form['category'] = request.form.get('category', type=int)
        if 'preview' in request.form:
            preview = format_creole(request.form['body'])
        elif 'delete' in request.form:
            for comment in snippet.comments:
                db_session.delete(comment)
            db_session.delete(snippet)
            db_session.commit()
            flash(u'Your snippet was deleted')
            return redirect(url_for('snippets.index'))
        else:
            category_id = request.form.get('category', type=int)
            if not form['body']:
                flash(u'Error: you have to enter a snippet')
            else:
                category = Category.query.get(category_id)
                if category is not None:
                    snippet.title = form['title']
                    snippet.body = form['body']
                    snippet.category = category
                    db_session.commit()
                    flash(u'Your snippet was modified')
                    return redirect(snippet.url)
    return render_template('snippets/edit.html',
                           snippet=snippet,
                           preview=preview,
                           form=form,
                           categories=Category.query.order_by(
                               Category.name).all())
    def test_saving_and_retrieving_items(self):
        list_ = List()
        db_session.add(list_)
        db_session.commit()

        first_item = Item(text='첫 번째 아이템', list=list_.id)
        second_item = Item(text='두 번째 아이템', list=list_.id)
        db_session.add(first_item)
        db_session.add(second_item)
        db_session.commit()

        saved_items = Item.query.filter(
            or_(Item.text == '첫 번째 아이템', Item.text == '두 번째 아이템')).all()

        first_saved_item = saved_items[0]
        second_saved_item = saved_items[1]

        assert first_saved_item.text == '첫 번째 아이템'
        assert first_saved_item.list == list_.id
        assert second_saved_item.text == '두 번째 아이템'
        assert second_saved_item.list == list_.id

        Item.query.filter(Item.text == '첫 번째 아이템').delete()
        Item.query.filter(Item.text == '두 번째 아이템').delete()
        List.query.filter(List.id == list_.id).delete()
        db_session.commit()
예제 #28
0
def new_category():
    category = Category(name=request.form['name'])
    db_session.add(category)
    db_session.commit()
    flash(u'Category %s created.' % category.name)
    return redirect(url_for('.manage_categories'))
예제 #29
0
 def create_user(self):
     db_session.add(self)
     db_session.commit()
 def edit_article(self):
     db_session.commit()
     return "Article updated successfully"