added topic_edit.jinja2

This commit is contained in:
2022-05-10 21:29:32 +02:00
parent cd5651ac62
commit 4f5bb3350e
16 changed files with 179 additions and 143 deletions

Binary file not shown.

View File

@@ -1,62 +0,0 @@
"""init
Revision ID: 07fa8fad6cc3
Revises:
Create Date: 2022-05-01 10:48:25.244455
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '07fa8fad6cc3'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('tags',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('topic', sa.Unicode(length=25), nullable=True),
sa.Column('tag', sa.Unicode(length=25), nullable=True),
sa.Column('tag_name', sa.Unicode(length=25), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_tags'))
)
op.create_index('topic_index', 'tags', ['topic', 'tag'], unique=False)
op.create_table('topics',
sa.Column('topic', sa.Unicode(length=25), nullable=False),
sa.Column('topic_name', sa.Unicode(length=25), nullable=False),
sa.PrimaryKeyConstraint('topic', name=op.f('pk_topics'))
)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.Unicode(length=255), nullable=False),
sa.Column('password', sa.Unicode(length=255), nullable=False),
sa.Column('last_logged', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id', name=op.f('pk_users')),
sa.UniqueConstraint('name', name=op.f('uq_users_name'))
)
op.create_table('entries',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.Unicode(length=255), nullable=False),
sa.Column('body', sa.UnicodeText(), nullable=True),
sa.Column('body_html', sa.UnicodeText(), nullable=True),
sa.Column('created', sa.DateTime(), nullable=True),
sa.Column('edited', sa.DateTime(), nullable=True),
sa.Column('topic_id', sa.Unicode(length=25), nullable=False),
sa.ForeignKeyConstraint(['topic_id'], ['topics.topic'], name=op.f('fk_entries_topic_id_topics')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_entries')),
sa.UniqueConstraint('title', name=op.f('uq_entries_title'))
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('entries')
op.drop_table('users')
op.drop_table('topics')
op.drop_index('topic_index', table_name='tags')
op.drop_table('tags')
# ### end Alembic commands ###

View File

@@ -1,26 +0,0 @@
"""init
Revision ID: 1a99bede8b76
Revises: 1c62fb741d2f
Create Date: 2022-05-01 16:50:53.674187
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '1a99bede8b76'
down_revision = '1c62fb741d2f'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('entries', sa.Column('title_url', sa.Unicode(length=255), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('entries', 'title_url')
# ### end Alembic commands ###

View File

@@ -1,30 +0,0 @@
"""init
Revision ID: 5ad5927ad64d
Revises: 1a99bede8b76
Create Date: 2022-05-05 15:49:10.984878
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '5ad5927ad64d'
down_revision = '1a99bede8b76'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('entries', sa.Column('author', sa.UnicodeText(), nullable=True))
op.drop_column('entries', 'title_url')
op.drop_column('entries', 'body_html')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('entries', sa.Column('body_html', sa.TEXT(), nullable=True))
op.add_column('entries', sa.Column('title_url', sa.VARCHAR(length=255), nullable=True))
op.drop_column('entries', 'author')
# ### end Alembic commands ###

View File

@@ -1,8 +1,8 @@
"""init """init
Revision ID: 1c62fb741d2f Revision ID: a35fa375a82f
Revises: 07fa8fad6cc3 Revises:
Create Date: 2022-05-01 11:16:29.476581 Create Date: 2022-05-10 08:28:42.146580
""" """
from alembic import op from alembic import op
@@ -10,17 +10,17 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '1c62fb741d2f' revision = 'a35fa375a82f'
down_revision = '07fa8fad6cc3' down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
def upgrade(): def upgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.add_column('entries', sa.Column('tag', sa.Unicode(length=25), nullable=True)) op.add_column('topics', sa.Column('topic_quote', sa.Unicode(length=255), nullable=True))
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_column('entries', 'tag') op.drop_column('topics', 'topic_quote')
# ### end Alembic commands ### # ### end Alembic commands ###

View File

@@ -32,3 +32,13 @@ class ContactForm(Form):
filters=[strip_filter]) filters=[strip_filter])
comments = TextAreaField('Message', validators=[InputRequired(), Length(min=1)], comments = TextAreaField('Message', validators=[InputRequired(), Length(min=1)],
filters=[strip_filter]) filters=[strip_filter])
class TopicForm(Form):
topic = StringField('Rubrique', validators=[InputRequired(), Length(min=1, max=25)],
filters=[strip_filter])
topic_name = StringField('Intitulé', validators=[InputRequired(), Length(min=1, max=25)],
filters=[strip_filter])
topic_quote = TextAreaField('Citation', validators=[InputRequired(), Length(min=1)],
filters=[strip_filter])

View File

@@ -20,13 +20,12 @@ class BlogRecord(Base):
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
title = Column(Unicode(255), unique=True, nullable=False) title = Column(Unicode(255), unique=True, nullable=False)
body = Column(UnicodeText, default='') body = Column(UnicodeText, default='')
author = Column(Unicode(30), default='')
created = Column(DateTime, default=datetime.datetime.now) created = Column(DateTime, default=datetime.datetime.now)
edited = Column(DateTime, default=datetime.datetime.now) edited = Column(DateTime, default=datetime.datetime.now)
topic_id = Column(ForeignKey('topics.topic'), nullable=False) topic_id = Column(ForeignKey('topics.topic'), nullable=False)
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='')
@property @property
def slug(self): def slug(self):
@@ -41,6 +40,7 @@ class Topics(Base):
__tablename__ = 'topics' __tablename__ = 'topics'
topic = Column(Unicode(25), primary_key=True) topic = Column(Unicode(25), primary_key=True)
topic_name = Column(Unicode(25), nullable=False) topic_name = Column(Unicode(25), nullable=False)
topic_quote = Column(Unicode(255), default='')
class Tags(Base): class Tags(Base):
__tablename__ = 'tags' __tablename__ = 'tags'

View File

@@ -9,6 +9,8 @@ def includeme(config):
config.add_route('logout', '/logout') config.add_route('logout', '/logout')
config.add_route('settings', '/settings') config.add_route('settings', '/settings')
config.add_route('topic', '/topic/{topic}') config.add_route('topic', '/topic/{topic}')
config.add_route('topic_edit', '/topic_edit/{topic}')
config.add_route('topics', '/topics')
config.add_route('users', '/users') config.add_route('users', '/users')
config.add_route('user_add', '/user_add/{name}') config.add_route('user_add', '/user_add/{name}')
config.add_route('user_pwd', '/user_pwd/{name}') config.add_route('user_pwd', '/user_pwd/{name}')

View File

@@ -43,10 +43,16 @@ class BlogRecordService(object):
return query return query
@classmethod @classmethod
def get_topic_name(cls, request, id): def get_topic_byTopic(cls, request, id):
# gest the name of a given topic # get the name of a given topic
query = request.dbsession.query(Topics).filter(Topics.topic == id).first() query = request.dbsession.query(Topics).filter(Topics.topic == id).first()
return query.topic_name.upper() return query
@classmethod
def get_topics(cls, request):
# get all topics
query = request.dbsession.query(Topics).order_by(Topics.topic).all()
return query
@classmethod @classmethod
def delete(cls, request, id): def delete(cls, request, id):

View File

@@ -54,16 +54,16 @@
<div class="container"> <div class="container">
<div align="center"> <div align="center">
<span class="menu-item"> <span class="menu-item">
<a href="{{ request.route_url('topic', topic='FR1') }}">Enseignement</a>&nbsp; <a href="{{ request.route_url('topic', topic='FR1') }}">ENSEIGNEMENT</a>&nbsp;
</span> </span>
<span class="menu-item"> <span class="menu-item">
<a href="{{ request.route_url('topic', topic='FR2') }}">Pratique</a>&nbsp; <a href="{{ request.route_url('topic', topic='FR2') }}">PRATIQUE</a>&nbsp;
</span> </span>
<span class="menu-item"> <span class="menu-item">
<a href="{{ request.route_url('topic', topic='FR3') }}">Qi Gong</a>&nbsp; <a href="{{ request.route_url('topic', topic='FR3') }}">Qi GONG</a>&nbsp;
</span> </span>
<span class="menu-item"> <span class="menu-item">
<a href="{{ request.route_url('topic', topic='FR4') }}">Sciences</a>&nbsp; <a href="{{ request.route_url('topic', topic='FR4') }}">SCIENCES</a>&nbsp;
</span> </span>
</div> </div>

View File

@@ -11,7 +11,7 @@
</div> </div>
{% endif %} {% endif %}
<div class="col-sm-3"> <div class="col-sm-3">
<a href=" {{request.route_url('users')}} "><span class="glyphicon glyphicon-user icone-big"></span> <a href=" {{request.route_url('topics')}} "><span class="glyphicon glyphicon-list icone-big"></span>
<h4>TOPICS / TAGS</h4> <h4>TOPICS / TAGS</h4>
</a> </a>
</div> </div>

View File

@@ -2,12 +2,16 @@
{% block content %} {% block content %}
{{ topic_quote | safe }}
<br />
{% if request.authenticated_userid %} {% if request.authenticated_userid %}
<p><a href="{{ request.route_url('blog_edit', topic=topic, id='0') }}" class="btn btn-success" role="button"> <p><a href="{{ request.route_url('blog_edit', topic=topic, id='0') }}" class="btn btn-success" role="button">
<span class="glyphicon glyphicon-plus"></span> Nouveau</a> <span class="glyphicon glyphicon-plus"></span> Nouveau</a>
</p> </p>
{% endif%} {% endif%}
{{ liste | safe }} {{ liste | safe }}
{% endblock %} {% endblock %}

View File

@@ -0,0 +1,43 @@
{% extends "cao_blogr:templates/layout.jinja2" %}
{% block content %}
<form action="{{ url }}" method="post" class="form">
{% for error in form.topic.errors %}
<div class="error">{{ error }}</div>
{% endfor %}
<div class="form-group">
<label class="required-field" for="topic">{{form.topic.label}}</label>
{{form.topic(class_='form-control')}}
</div>
{% for error in form.topic_name.errors %}
<div class="error">{{error}}</div>
{% endfor %}
<div class="form-group">
<label class="required-field" for="topic_name">{{form.topic_name.label}}</label>
{{form.topic_name(class_='form-control')}}
</div>
{% for error in form.topic_quote.errors %}
<div class="error">{{ error }}</div>
{% endfor %}
<div class="form-group">
<label class="required-field" for="topic_quote">{{ form.topic_quote.label }}</label>
{{ form.topic_quote(class_='form-control', cols="35", rows="5") }}
</div>
<div class="form-group">
<a class="btn btn-default" href="{{ request.route_url('topics') }}">
<span class="glyphicon glyphicon-chevron-left"></span> Retour</a>
<button class="btn btn-primary" type="submit" name="form.submitted">
<span class="glyphicon glyphicon-ok"></span> Enregistrer</button>
</div>
</form>
{% endblock %}

View File

@@ -0,0 +1,30 @@
{% extends "layout.jinja2" %}
{% block content %}
<p>
<a href="{{ request.route_url('settings') }}" class="btn btn-default" role="button">
<span class="glyphicon glyphicon-chevron-left"></span> Retour</a>
<a href="{{ request.route_url('user_add', name='new') }}" class="btn btn-success" role="button">
<span class="glyphicon glyphicon-plus"></span> Nouvel utilisateur</a>
</p>
<table id="users_list" class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Rubrique</th>
<th>Nom</th>
</tr>
</thead>
{% for entry in topics %}
<tr>
<td>{{ entry.topic }}</td>
<td>
<a href="{{ request.route_url('topic_edit', topic=entry.topic) }}">
{{ entry.topic_name }}
</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@@ -32,8 +32,7 @@ def blog(request):
@view_config(route_name='blog_edit', @view_config(route_name='blog_edit',
renderer='cao_blogr:templates/blog_edit.jinja2', renderer='cao_blogr:templates/blog_edit.jinja2', permission='view')
permission='view')
def blog_edit(request): def blog_edit(request):
# get post parameters from request # get post parameters from request
topic = request.matchdict['topic'] topic = request.matchdict['topic']
@@ -49,6 +48,7 @@ def blog_edit(request):
entry.topic_id = topic entry.topic_id = topic
form = BlogCreateForm(request.POST, entry) form = BlogCreateForm(request.POST, entry)
form.tag.choices = [(row.tag, row.tag_name) for row in tags] form.tag.choices = [(row.tag, row.tag_name) for row in tags]
page_title = 'Nouvelle page'
else: else:
# modify post # modify post
@@ -58,6 +58,7 @@ def blog_edit(request):
return HTTPFound(location=request.route_url('home')) return HTTPFound(location=request.route_url('home'))
form = BlogUpdateForm(request.POST, entry) form = BlogUpdateForm(request.POST, entry)
form.tag.choices = [(row.tag, row.tag_name) for row in tags] form.tag.choices = [(row.tag, row.tag_name) for row in tags]
page_title = 'Modifier : ' + entry.title
if 'form.submitted' in request.params and form.validate(): if 'form.submitted' in request.params and form.validate():
if blog_id == '0': if blog_id == '0':
@@ -79,7 +80,7 @@ def blog_edit(request):
return HTTPFound(location=request.route_url('topic', topic=topic)) return HTTPFound(location=request.route_url('topic', topic=topic))
return { return {
'page_title': entry.title, 'page_title': page_title,
'url': url, 'url': url,
'form': form, 'form': form,
'blog_id': blog_id, 'blog_id': blog_id,
@@ -112,8 +113,12 @@ def blog_search(request):
def topic(request): def topic(request):
topic = request.matchdict['topic'] topic = request.matchdict['topic']
# get the topic_name # get the topic record
topic_name = BlogRecordService.get_topic_name(request, topic) topic_record = BlogRecordService.get_topic_byTopic(request, topic)
# convertir mardown en HTML
markdowner = Markdown()
topic_quote = markdowner.convert(topic_record.topic_quote)
# get all the tags of this topic # get all the tags of this topic
tags = BlogRecordService.get_tags_byTopic(request, topic) tags = BlogRecordService.get_tags_byTopic(request, topic)
@@ -133,7 +138,8 @@ def topic(request):
else: else:
liste += '<ul><li> </li></ul>' liste += '<ul><li> </li></ul>'
return { return {
'page_title': topic_name, 'page_title': topic_record.topic_name,
'topic': topic, 'topic': topic,
'topic_quote': topic_quote,
'liste': liste, 'liste': liste,
} }

View File

@@ -9,8 +9,9 @@ from pyramid_mailer.message import Message
from ..services.user import UserService from ..services.user import UserService
from ..services.blog_record import BlogRecordService from ..services.blog_record import BlogRecordService
from ..forms import UserCreateForm, ContactForm from ..forms import UserCreateForm, TopicForm
from ..models.user import User from ..models.user import User
from ..models.blog_record import Topics
@view_config(route_name='home', @view_config(route_name='home',
@@ -155,7 +156,7 @@ def user_add(request):
return HTTPFound(location=request.route_url('users')) return HTTPFound(location=request.route_url('users'))
return { return {
'page_title': 'Nouvel utilsateur', 'page_title': 'Nouvel utilisateur',
'form': form, 'form': form,
'name': name, 'name': name,
} }
@@ -188,3 +189,55 @@ def user_pwd(request):
'page_title': "Utilisateur : %s" %(entry.name), 'page_title': "Utilisateur : %s" %(entry.name),
'entry': entry, 'entry': entry,
} }
@view_config(route_name='topics',
renderer='cao_blogr:templates/topics.jinja2', permission='manage')
def topics(request):
# get all topics
topics = BlogRecordService.get_topics(request)
return {
'page_title': "Liste des topics",
'topics': topics
}
@view_config(route_name='topic_edit',
renderer='cao_blogr:templates/topic_edit.jinja2', permission='manage')
def topic_edit(request):
# get topic parameters from request
topic = request.matchdict['topic']
url = request.route_url('topic_edit',topic=topic)
# get the list of tags of this topic
tags = BlogRecordService.get_tags_byTopic(request, topic)
if topic == '0':
# create a new topic
entry = Topics()
form = TopicForm(request.POST, entry)
page_title = "Nouvelle rubrique"
else:
# modify post
entry = BlogRecordService.get_topic_byTopic(request, topic)
if not entry:
request.session.flash(u"Topic non trouvé : %s" % topic, 'warning')
return HTTPFound(location=request.route_url('topics'))
form = TopicForm(request.POST, entry)
page_title = entry.topic_name
if 'form.submitted' in request.params and form.validate():
if topic == '0':
form.populate_obj(entry)
request.dbsession.add(entry)
return HTTPFound(location=request.route_url('topic', topic=topic))
else:
del form.topic # SECURITY: prevent overwriting of primary key
form.populate_obj(entry)
return HTTPFound(location=request.route_url('topics'))
return {
'page_title': page_title,
'url': url,
'form': form,
}