added status to blog post

This commit is contained in:
2022-05-18 14:38:30 +02:00
parent 7fa1595f0a
commit 62371401c5
9 changed files with 85 additions and 28 deletions

View 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 ###

View File

@@ -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 import IntegerField, PasswordField
from wtforms.validators import InputRequired, Length, Email from wtforms.validators import InputRequired, Length, Email
from wtforms.widgets import HiddenInput from wtforms.widgets import HiddenInput
@@ -13,6 +13,7 @@ class BlogCreateForm(Form):
tag = SelectField('Sous-rubrique') tag = SelectField('Sous-rubrique')
author = StringField('Auteur', validators=[InputRequired(), Length(min=1, max=50)], author = StringField('Auteur', validators=[InputRequired(), Length(min=1, max=50)],
filters=[strip_filter]) filters=[strip_filter])
status = SelectField('Statut', choices=[('brouillon','Brouillon'),('publié','Publié')])
class BlogUpdateForm(BlogCreateForm): class BlogUpdateForm(BlogCreateForm):

View File

@@ -26,6 +26,7 @@ class BlogRecord(Base):
topic = relationship('Topics', backref='topic_pages') topic = relationship('Topics', backref='topic_pages')
tag = Column(Unicode(25)) tag = Column(Unicode(25))
author = Column(Unicode(50), default='') author = Column(Unicode(50), default='')
status = Column(Unicode(50), default='brouillon')
@property @property
def slug(self): def slug(self):

View File

@@ -11,6 +11,9 @@ class BlogRecordService(object):
def by_topic(cls, request, topic, tag): def by_topic(cls, request, topic, tag):
# get posts by topic # get posts by topic
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id == 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 != '': if tag != '':
query = query.filter(BlogRecord.tag == tag) query = query.filter(BlogRecord.tag == tag)
query = query.order_by(BlogRecord.tag, BlogRecord.title).all() query = query.order_by(BlogRecord.tag, BlogRecord.title).all()
@@ -32,13 +35,16 @@ class BlogRecordService(object):
def get_last_created(cls, request): def get_last_created(cls, request):
# gest the last created posts # gest the last created posts
query = request.dbsession.query(BlogRecord).filter(BlogRecord.topic_id != 'ADM') 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() query = query.order_by(sa.desc(BlogRecord.created)).limit(5).all()
return query return query
@classmethod @classmethod
def get_activities(cls, request): def get_activities(cls, request):
# gest the Activities section # 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() query = query.order_by(sa.desc(BlogRecord.created)).first()
return query return query

View File

@@ -30,6 +30,11 @@
{{ form.author(class_='form-control') }} {{ form.author(class_='form-control') }}
</div> </div>
<div class="form-group">
<label class="required-field" for="status">{{ form.status.label }}</label>
{{ form.status(class_='form-control') }}
</div>
<p> <p>
Topic : <strong>{{ entry.topic_id }}</strong> Topic : <strong>{{ entry.topic_id }}</strong>
{% if blog_id != '0' %} {% if blog_id != '0' %}

View File

@@ -111,17 +111,23 @@
<br> <br>
<h5 class="text-center">DERNIERES PUBLICATIONS</h5> <h5 class="text-center">DERNIERES PUBLICATIONS</h5>
<ul> <table id="users_list" class="table table-condensed">
{% for entry in last_five %} {% for entry in last_five %}
<li> <tr>
<a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}"> <td>
{{ entry.title }} <a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}">{{ entry.title }}</a>
</a> </td>
&nbsp;—&nbsp;{{ entry.author }}, {{ entry.created.strftime("%d-%m-%Y") }} <td>{{ entry.author }}</td>
</li> <td>{{ entry.created.strftime("%d-%m-%Y") }}</td>
{% if entry.status == 'brouillon' %}
{% endfor %} <td><span class="label label-danger">{{ entry.status }}</span></td>
</ul> {% else %}
<td> </td>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
</div> </div>

View File

@@ -27,15 +27,24 @@
</p> </p>
{% endif%} {% endif%}
<ul> <table id="users_list" class="table table-condensed">
{% for item in items %} {% for entry in items %}
<li> <tr>
{{ item.edited.strftime("%d-%m-%Y") }}&nbsp;&nbsp; <td>{{ entry.tag }}</td>
<a href="{{ request.route_url('blog', id=item.id, slug=item.slug) }}"> <td>
<span class="glyphicon glyphicon-menu-right"></span>&nbsp;&nbsp;{{ item.title }}</a> <a href="{{ request.route_url('blog', id=entry.id, slug=entry.slug) }}">{{ entry.title }}</a>
</li> </td>
{% endfor %} <td>{{ entry.author }}</td>
</ul> <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 %}
</table>
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -11,7 +11,6 @@
</p> </p>
{% endif%} {% endif%}
{{ liste | safe }} {{ liste | safe }}
{% endblock %} {% endblock %}

View File

@@ -150,12 +150,16 @@ def topic(request):
# lire toutes les docs du topic # lire toutes les docs du topic
items = BlogRecordService.by_topic(request, topic, tag.tag) items = BlogRecordService.by_topic(request, topic, tag.tag)
if items: if items:
liste += '<ul>' liste += '<ul><table class="table table-condensed">'
for item in items: for item in items:
liste += '<li><a href="{0}">{1}</a> — {2}, {3}</li>'.format( liste += '<tr>'
request.route_url('blog', id=item.id, slug=item.slug), item.title, item.author, liste += '<td><a href="%s">%s</a></td>' % (request.route_url('blog', id=item.id, slug=item.slug), item.title)
item.created.strftime("%d-%m-%Y")) liste += '<td>%s</td>' % item.author
liste += '</ul>' 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: else:
liste += '<ul><li> </li></ul>' liste += '<ul><li> </li></ul>'
return { return {