added tag_edit
This commit is contained in:
@@ -131,9 +131,9 @@ def topic(request):
|
||||
if items:
|
||||
liste += '<ul>'
|
||||
for item in items:
|
||||
liste += '<li><a href="{0}">{1}</a> — {2}</li>'.format(
|
||||
request.route_url('blog', id=item.id, slug=item.slug), item.title,
|
||||
item.edited.strftime("%d-%m-%Y"))
|
||||
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>'
|
||||
else:
|
||||
liste += '<ul><li> </li></ul>'
|
||||
|
||||
@@ -9,9 +9,9 @@ from pyramid_mailer.message import Message
|
||||
|
||||
from ..services.user import UserService
|
||||
from ..services.blog_record import BlogRecordService
|
||||
from ..forms import UserCreateForm, TopicForm
|
||||
from ..forms import UserCreateForm, TopicForm, TagForm
|
||||
from ..models.user import User
|
||||
from ..models.blog_record import Topics
|
||||
from ..models.blog_record import Topics, Tags
|
||||
|
||||
|
||||
@view_config(route_name='home',
|
||||
@@ -196,7 +196,7 @@ def topics(request):
|
||||
# get all topics
|
||||
topics = BlogRecordService.get_topics(request)
|
||||
return {
|
||||
'page_title': "Liste des topics",
|
||||
'page_title': "Liste des rubriques",
|
||||
'topics': topics
|
||||
}
|
||||
|
||||
@@ -230,14 +230,66 @@ def topic_edit(request):
|
||||
form.populate_obj(entry)
|
||||
request.dbsession.add(entry)
|
||||
|
||||
return HTTPFound(location=request.route_url('topic', topic=topic))
|
||||
return HTTPFound(location=request.route_url('topics'))
|
||||
else:
|
||||
del form.topic # SECURITY: prevent overwriting of primary key
|
||||
form.populate_obj(entry)
|
||||
return HTTPFound(location=request.route_url('topics'))
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
BlogRecordService.topic_delete(request, entry.topic)
|
||||
request.session.flash("La fiche a été supprimée avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('topics'))
|
||||
|
||||
return {
|
||||
'page_title': page_title,
|
||||
'url': url,
|
||||
'form': form,
|
||||
'tags': tags,
|
||||
}
|
||||
|
||||
@view_config(route_name='tag_edit',
|
||||
renderer='cao_blogr:templates/tag_edit.jinja2', permission='manage')
|
||||
def tag_edit(request):
|
||||
# get tag parameters from request
|
||||
topic = request.matchdict['topic']
|
||||
tag_id = request.matchdict['id']
|
||||
url = request.route_url('tag_edit', topic=topic, id=tag_id)
|
||||
|
||||
if tag_id == '0':
|
||||
# create a new tag
|
||||
entry = Tags()
|
||||
form = TagForm(request.POST, entry)
|
||||
page_title = "Nouvelle sous-rubrique"
|
||||
|
||||
else:
|
||||
# modify post
|
||||
entry = BlogRecordService.get_tags_byId(request, tag_id)
|
||||
if not entry:
|
||||
request.session.flash(u"Tag non trouvé : %s" % tag_id, 'warning')
|
||||
return HTTPFound(location=request.route_url('topic_edit', topic=topic))
|
||||
form = TagForm(request.POST, entry)
|
||||
page_title = entry.tag_name
|
||||
|
||||
if 'form.submitted' in request.params and form.validate():
|
||||
if tag_id == '0':
|
||||
form.populate_obj(entry)
|
||||
entry.topic = topic
|
||||
request.dbsession.add(entry)
|
||||
return HTTPFound(location=request.route_url('topic_edit', topic=topic))
|
||||
else:
|
||||
del form.id # SECURITY: prevent overwriting of primary key
|
||||
form.populate_obj(entry)
|
||||
return HTTPFound(location=request.route_url('topic_edit', topic=topic))
|
||||
|
||||
if 'form.deleted' in request.params:
|
||||
BlogRecordService.tag_delete(request, entry.id)
|
||||
request.session.flash("La fiche a été supprimée avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('topic_edit', topic=topic))
|
||||
|
||||
return {
|
||||
'page_title': page_title,
|
||||
'url': url,
|
||||
'form': form,
|
||||
'topic': topic,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user