finalize topic template

This commit is contained in:
2022-05-03 19:24:51 +02:00
parent cd7e21bb53
commit e7bebbe5e4
13 changed files with 101 additions and 65 deletions

View File

@@ -12,8 +12,8 @@ def blog(request):
blog_id = request.matchdict['id']
entry = BlogRecordService.by_id(request, blog_id)
if not entry:
request.session.flash(u"Page non trouvée : %s" % blog_id, 'warning')
return HTTPFound(location=request.route_url('home'))
request.session.flash(u"Page non trouvée : %s" % blog_id, 'warning')
return HTTPFound(location=request.route_url('home'))
# just created ? convert body to html
if entry.body_html == '':
@@ -29,18 +29,21 @@ def blog(request):
renderer='cao_blogr:templates/blog_edit.jinja2',
permission='view')
def blog_edit(request):
# get post id from request
# get post parameters from request
topic = request.matchdict['topic']
blog_id = request.matchdict['id']
url = request.route_url('blog_edit',id=blog_id)
url = request.route_url('blog_edit',topic=topic, id=blog_id)
# get the list of tags of this topic
tags = BlogRecordService.get_tags_byTopic(request, topic)
if blog_id == '0':
# create a new post
entry = BlogRecord()
# set default values
entry.tag = 'pyramid'
entry.topic = 'blog'
entry.topic_id = topic
form = BlogCreateForm(request.POST, entry)
form.tag.choices = [(row.tag, row.title) for row in BlogRecordService.tags]
form.tag.choices = [(row.tag, row.tag_name) for row in tags]
else:
# modify post
entry = BlogRecordService.by_id(request, blog_id)
@@ -48,15 +51,17 @@ def blog_edit(request):
request.session.flash(u"Page non trouvée : %s" % blog_id, 'warning')
return HTTPFound(location=request.route_url('home'))
form = BlogUpdateForm(request.POST, entry)
form.tag.choices = [(row.tag, row.tag_name) for row in tags]
if 'form.submitted' in request.params and form.validate():
if blog_id == '0':
form.populate_obj(entry)
entry.title_url = entry.slug
entry.topic_id = topic
request.dbsession.add(entry)
return HTTPFound(location=request.route_url('home'))
return HTTPFound(location=request.route_url('topic', topic=topic))
else:
del form.id # SECURITY: prevent overwriting of primary key
form.populate_obj(entry)
@@ -69,7 +74,8 @@ def blog_edit(request):
return {
'page_title': entry.title,
'url': url,
'form': form,
'form': form,
'blog_id': blog_id,
'entry': entry,
}
@@ -101,12 +107,25 @@ def topic(request):
# get the topic_name
topic_name = BlogRecordService.get_topic_name(request, topic)
# lire toutes les docs du topic
items = BlogRecordService.by_topic(request, topic)
# get all the tags of this topic
tags = BlogRecordService.get_tags_byTopic(request, topic)
# generate the items list group by tag
liste = ''
for tag in tags:
liste += '<h3>' + tag.tag_name + '</h3>'
# lire toutes les docs du topic
items = BlogRecordService.by_topic(request, topic, tag.tag)
if items:
liste += '<ul>'
for item in items:
liste += '<li>{0} <a href="{1}"><span class="glyphicon glyphicon-menu-right"></span>{2}</a></li>'.format(
item.edited.strftime("%d-%m-%Y"), request.route_url('blog', id=item.id, slug=item.slug), item.title)
liste += '</ul>'
else:
liste += '<ul><li> </li></ul>'
return {
'page_title': topic_name,
'topic': topic,
'items': items,
'liste': liste,
}