added topic_edit.jinja2
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user