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

View File

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

View File

@@ -9,8 +9,9 @@ from pyramid_mailer.message import Message
from ..services.user import UserService
from ..services.blog_record import BlogRecordService
from ..forms import UserCreateForm, ContactForm
from ..forms import UserCreateForm, TopicForm
from ..models.user import User
from ..models.blog_record import Topics
@view_config(route_name='home',
@@ -155,7 +156,7 @@ def user_add(request):
return HTTPFound(location=request.route_url('users'))
return {
'page_title': 'Nouvel utilsateur',
'page_title': 'Nouvel utilisateur',
'form': form,
'name': name,
}
@@ -188,3 +189,55 @@ def user_pwd(request):
'page_title': "Utilisateur : %s" %(entry.name),
'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,
}