added status to blog post
This commit is contained in:
26
cao_blogr/alembic/versions/20220518_6da5ee6785ff.py
Normal file
26
cao_blogr/alembic/versions/20220518_6da5ee6785ff.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""init
|
||||
|
||||
Revision ID: 6da5ee6785ff
|
||||
Revises: a35fa375a82f
|
||||
Create Date: 2022-05-18 10:33:38.599975
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6da5ee6785ff'
|
||||
down_revision = 'a35fa375a82f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('entries', sa.Column('status', sa.Unicode(length=50), nullable=True))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('entries', 'status')
|
||||
# ### end Alembic commands ###
|
||||
@@ -1,4 +1,4 @@
|
||||
from wtforms import Form, StringField, TextAreaField, SelectField
|
||||
from wtforms import Form, StringField, TextAreaField, SelectField, RadioField
|
||||
from wtforms import IntegerField, PasswordField
|
||||
from wtforms.validators import InputRequired, Length, Email
|
||||
from wtforms.widgets import HiddenInput
|
||||
@@ -13,6 +13,7 @@ class BlogCreateForm(Form):
|
||||
tag = SelectField('Sous-rubrique')
|
||||
author = StringField('Auteur', validators=[InputRequired(), Length(min=1, max=50)],
|
||||
filters=[strip_filter])
|
||||
status = SelectField('Statut', choices=[('brouillon','Brouillon'),('publié','Publié')])
|
||||
|
||||
|
||||
class BlogUpdateForm(BlogCreateForm):
|
||||
|
||||
@@ -26,6 +26,7 @@ class BlogRecord(Base):
|
||||
topic = relationship('Topics', backref='topic_pages')
|
||||
tag = Column(Unicode(25))
|
||||
author = Column(Unicode(50), default='')
|
||||
status = Column(Unicode(50), default='brouillon')
|
||||
|
||||
@property
|
||||
def slug(self):
|
||||
|
||||
@@ -11,6 +11,9 @@ class BlogRecordService(object):
|
||||
def by_topic(cls, request, topic, tag):
|
||||
# get posts by topic
|
||||
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id == topic)
|
||||
if request.authenticated_userid == None:
|
||||
# if user is anonym, display only published posts
|
||||
query = query.filter(BlogRecord.status == 'publié')
|
||||
if tag != '':
|
||||
query = query.filter(BlogRecord.tag == tag)
|
||||
query = query.order_by(BlogRecord.tag, BlogRecord.title).all()
|
||||
@@ -32,13 +35,16 @@ class BlogRecordService(object):
|
||||
def get_last_created(cls, request):
|
||||
# gest the last created posts
|
||||
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id != 'ADM')
|
||||
if request.authenticated_userid == None:
|
||||
# if user is anonym, display only published posts
|
||||
query = query.filter(BlogRecord.status == 'publié')
|
||||
query = query.order_by(sa.desc(BlogRecord.created)).limit(5).all()
|
||||
return query
|
||||
|
||||
@classmethod
|
||||
def get_activities(cls, request):
|
||||
# gest the Activities section
|
||||
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id != 'ADM' and BlogRecord.tag != 'Activities')
|
||||
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id == 'ADM' and BlogRecord.tag == 'Activities')
|
||||
query = query.order_by(sa.desc(BlogRecord.created)).first()
|
||||
return query
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
{{ form.author(class_='form-control') }}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="required-field" for="status">{{ form.status.label }}</label>
|
||||
{{ form.status(class_='form-control') }}
|
||||
</div>
|
||||
|
||||
<p>
|
||||
Topic : <strong>{{ entry.topic_id }}</strong>
|
||||
{% if blog_id != '0' %}
|
||||
|
||||
@@ -111,17 +111,23 @@
|
||||
<br>
|
||||
<h5 class="text-center">DERNIERES PUBLICATIONS</h5>
|
||||
|
||||
<ul>
|
||||
<table id="users_list" class="table table-condensed">
|
||||
{% for entry in last_five %}
|
||||
<li>
|
||||
<a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}">
|
||||
{{ entry.title }}
|
||||
</a>
|
||||
— {{ entry.author }}, {{ entry.created.strftime("%d-%m-%Y") }}
|
||||
</li>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}">{{ entry.title }}</a>
|
||||
</td>
|
||||
<td>{{ entry.author }}</td>
|
||||
<td>{{ entry.created.strftime("%d-%m-%Y") }}</td>
|
||||
{% if entry.status == 'brouillon' %}
|
||||
<td><span class="label label-danger">{{ entry.status }}</span></td>
|
||||
{% else %}
|
||||
<td> </td>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -27,15 +27,24 @@
|
||||
</p>
|
||||
{% endif%}
|
||||
|
||||
<ul>
|
||||
{% for item in items %}
|
||||
<li>
|
||||
{{ item.edited.strftime("%d-%m-%Y") }}
|
||||
<a href="{{ request.route_url('blog', id=item.id, slug=item.slug) }}">
|
||||
<span class="glyphicon glyphicon-menu-right"></span> {{ item.title }}</a>
|
||||
</li>
|
||||
<table id="users_list" class="table table-condensed">
|
||||
{% for entry in items %}
|
||||
<tr>
|
||||
<td>{{ entry.tag }}</td>
|
||||
<td>
|
||||
<a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}">{{ entry.title }}</a>
|
||||
</td>
|
||||
<td>{{ entry.author }}</td>
|
||||
<td>{{ entry.created.strftime("%d-%m-%Y") }}</td>
|
||||
{% if entry.status == 'brouillon' %}
|
||||
<td><span class="label label-danger">{{ entry.status }}</span></td>
|
||||
{% else %}
|
||||
td> </td>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
</p>
|
||||
{% endif%}
|
||||
|
||||
|
||||
{{ liste | safe }}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -150,12 +150,16 @@ def topic(request):
|
||||
# lire toutes les docs du topic
|
||||
items = BlogRecordService.by_topic(request, topic, tag.tag)
|
||||
if items:
|
||||
liste += '<ul>'
|
||||
liste += '<ul><table class="table table-condensed">'
|
||||
for item in items:
|
||||
liste += '<li><a href="{0}">{1}</a> — {2}, {3}</li>'.format(
|
||||
request.route_url('blog', id=item.id, slug=item.slug), item.title, item.author,
|
||||
item.created.strftime("%d-%m-%Y"))
|
||||
liste += '</ul>'
|
||||
liste += '<tr>'
|
||||
liste += '<td><a href="%s">%s</a></td>' % (request.route_url('blog', id=item.id, slug=item.slug), item.title)
|
||||
liste += '<td>%s</td>' % item.author
|
||||
liste += '<td>%s</td>' % item.created.strftime("%d-%m-%Y")
|
||||
if item.status == 'brouillon':
|
||||
liste += '<td><span class="label label-danger">%s</span></td>' % item.status
|
||||
liste += '</tr>'
|
||||
liste += '</table></ul>'
|
||||
else:
|
||||
liste += '<ul><li> </li></ul>'
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user