Compare commits
No commits in common. "44a49e5aeefff4ad29134ecf0b34e24b6e04cb67" and "39243beff486901dfc02f5dff0c6f1c810ffd15f" have entirely different histories.
44a49e5aee
...
39243beff4
6 changed files with 3 additions and 92 deletions
|
|
@ -8,7 +8,7 @@ def create_app(test_config=None):
|
||||||
app.config.from_mapping(
|
app.config.from_mapping(
|
||||||
SECRET_KEY='dev',
|
SECRET_KEY='dev',
|
||||||
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
|
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
|
||||||
ALLOW_REGISTER=True,
|
ALLOW_REGISTER=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
app.wsgi_app = ProxyFix(
|
app.wsgi_app = ProxyFix(
|
||||||
|
|
|
||||||
|
|
@ -28,23 +28,6 @@ def index():
|
||||||
posts.append(post)
|
posts.append(post)
|
||||||
return render_template('blog/index.html', posts=posts)
|
return render_template('blog/index.html', posts=posts)
|
||||||
|
|
||||||
@bp.route('/firehose')
|
|
||||||
def firehose():
|
|
||||||
db = get_db()
|
|
||||||
db_posts = db.execute(
|
|
||||||
'SELECT p.id, title, body, created, author_id, username'
|
|
||||||
' FROM post p JOIN user u ON p.author_id = u.id'
|
|
||||||
' ORDER BY created DESC'
|
|
||||||
).fetchall()
|
|
||||||
posts = []
|
|
||||||
for post in db_posts:
|
|
||||||
if post['created'] > datetime.datetime.utcnow():
|
|
||||||
continue
|
|
||||||
post = dict(post)
|
|
||||||
post['body'] = markdown.markdown(post['body'])
|
|
||||||
posts.append(post)
|
|
||||||
return render_template('blog/firehose.html', posts=posts)
|
|
||||||
|
|
||||||
@bp.route('/create',methods=('GET', 'POST'))
|
@bp.route('/create',methods=('GET', 'POST'))
|
||||||
@login_required
|
@login_required
|
||||||
def create():
|
def create():
|
||||||
|
|
@ -86,12 +69,6 @@ def get_post(id, check_author=True):
|
||||||
|
|
||||||
return post
|
return post
|
||||||
|
|
||||||
@bp.route('/<int:id>/')
|
|
||||||
def individual_post(id):
|
|
||||||
post = dict(get_post(id, False))
|
|
||||||
post['body'] = markdown.markdown(post['body'])
|
|
||||||
return render_template('blog/post.html', post=post)
|
|
||||||
|
|
||||||
@bp.route('/<int:id>/update', methods=('GET', 'POST'))
|
@bp.route('/<int:id>/update', methods=('GET', 'POST'))
|
||||||
@login_required
|
@login_required
|
||||||
def update(id):
|
def update(id):
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block header %}
|
|
||||||
<h1>{% block title %}Posts{% endblock %}</h1>
|
|
||||||
{% if g.user %}
|
|
||||||
<a class="action" href="{{ url_for('blog.create') }}">New</a>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
{% for post in posts %}
|
|
||||||
<article class="post">
|
|
||||||
<header>
|
|
||||||
<div>
|
|
||||||
<h1>{{ post['title'] }}</h1>
|
|
||||||
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
|
||||||
</div>
|
|
||||||
{% if g.user['id'] == post['author_id'] %}
|
|
||||||
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
|
||||||
{% endif %}
|
|
||||||
</header>
|
|
||||||
<p class="body">{{ post['body']|safe }}</p>
|
|
||||||
</article>
|
|
||||||
{% if not loop.last %}
|
|
||||||
<hr>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@ -12,13 +12,14 @@
|
||||||
<article class="post">
|
<article class="post">
|
||||||
<header>
|
<header>
|
||||||
<div>
|
<div>
|
||||||
<h1><a class="action" href="{{ url_for('blog.individual_post', id=post['id']) }}">{{ post['title'] }}</a></h1>
|
<h1>{{ post['title'] }}</h1>
|
||||||
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
||||||
</div>
|
</div>
|
||||||
{% if g.user['id'] == post['author_id'] %}
|
{% if g.user['id'] == post['author_id'] %}
|
||||||
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
|
<p class="body">{{ post['body']|safe }}</p>
|
||||||
</article>
|
</article>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% block header %}
|
|
||||||
<h1>{% block title %}{{ post['title'] }}{% endblock %}</h1>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<article class="post">
|
|
||||||
<header>
|
|
||||||
<div>
|
|
||||||
<div class="about">by {{ post['username'] }} on {{ post['created'].strftime('%Y-%m-%d') }}</div>
|
|
||||||
</div>
|
|
||||||
{% if g.user['id'] == post['author_id'] %}
|
|
||||||
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
|
||||||
{% endif %}
|
|
||||||
</header>
|
|
||||||
<p class="body">{{ post['body']|safe }}</p>
|
|
||||||
</article>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
@ -11,29 +11,9 @@ def test_index(client, auth):
|
||||||
assert b'Log Out' in response.data
|
assert b'Log Out' in response.data
|
||||||
assert b'test title' in response.data
|
assert b'test title' in response.data
|
||||||
assert b'by test on 2018-01-01' in response.data
|
assert b'by test on 2018-01-01' in response.data
|
||||||
assert b'test\nbody' not in response.data
|
|
||||||
assert b'href="/1/update"' in response.data
|
|
||||||
assert b'href="/1/"' in response.data
|
|
||||||
|
|
||||||
def test_firehose(client, auth):
|
|
||||||
response = client.get('/')
|
|
||||||
assert b"Log In" not in response.data
|
|
||||||
assert b"Register" not in response.data
|
|
||||||
|
|
||||||
auth.login()
|
|
||||||
response = client.get('/firehose')
|
|
||||||
assert b'Log Out' in response.data
|
|
||||||
assert b'test title' in response.data
|
|
||||||
assert b'by test on 2018-01-01' in response.data
|
|
||||||
assert b'test\nbody' in response.data
|
assert b'test\nbody' in response.data
|
||||||
assert b'href="/1/update"' in response.data
|
assert b'href="/1/update"' in response.data
|
||||||
|
|
||||||
def test_individual_page(client, auth):
|
|
||||||
response = client.get('/1/')
|
|
||||||
assert b'test title' in response.data
|
|
||||||
assert b'by test on 2018-01-01' in response.data
|
|
||||||
assert b'test\nbody' in response.data
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('path', (
|
@pytest.mark.parametrize('path', (
|
||||||
'/create',
|
'/create',
|
||||||
'/1/update',
|
'/1/update',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue