[IMP]: implement controllelers for questions, question, ask question and post answer, create history for post
bzr revid: mga@tinyerp.com-20140223071516-h0xyxht4yh3r77el
This commit is contained in:
parent
4258e02bcc
commit
eb36ac6be1
|
@ -35,6 +35,7 @@ from openerp.addons.website.controllers.main import Website as controllers
|
|||
controllers = controllers()
|
||||
|
||||
class website_forum(http.Controller):
|
||||
|
||||
@http.route(['/questions/', '/question/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def questions(self, page=1, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
@ -61,33 +62,54 @@ class website_forum(http.Controller):
|
|||
return request.website.render("website_forum.index", values)
|
||||
|
||||
@http.route(['/question/<model("website.forum.post"):question>/page/<page:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def question_page(self, question, page, **post):
|
||||
def question(self, question, page, **post):
|
||||
values = {
|
||||
'question': question,
|
||||
'main_object': question
|
||||
}
|
||||
return request.website.render(page, values)
|
||||
|
||||
@http.route(['/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
||||
def question_register(self, question, **post):
|
||||
values = {
|
||||
'question': question,
|
||||
'main_object': question,
|
||||
'range': range,
|
||||
}
|
||||
return request.website.render("website_forum.question_description_full", values)
|
||||
# @http.route(['/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
||||
# def question_register(self, question, **post):
|
||||
# values = {
|
||||
# 'question': question,
|
||||
# 'main_object': question,
|
||||
# 'range': range,
|
||||
# }
|
||||
# return request.website.render("website_forum.question_description_full", values)
|
||||
|
||||
@http.route('/question/askquestion/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def add_question(self, question_name="New question", **kwargs):
|
||||
@http.route('/question/postquestion/', type='http', auth="user", multilang=True, website=True)
|
||||
def post_question(self, question_name="New question", **kwargs):
|
||||
#TODO : reply a page that allows user to post a question
|
||||
return self._add_question(question_name, request.context, **kwargs)
|
||||
|
||||
def _add_question(self, question_name=None, context={}, **kwargs):
|
||||
if not question_name:
|
||||
question_name = _("New Question")
|
||||
Question = request.registry.get('website.forum.post')
|
||||
date_begin = datetime.today() + timedelta(days=(14))
|
||||
vals = {
|
||||
'topic': question_name,
|
||||
}
|
||||
question_id = Question.create(request.cr, request.uid, vals, context=context)
|
||||
return request.redirect("/question/%s/?enable_editor=1" % question_id)
|
||||
|
||||
@http.route('/question/new/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def register_question(self, forum_id=1, **question):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
create_context = dict(context)
|
||||
new_question_id = request.registry['blog.post'].create(
|
||||
request.cr, request.uid, {
|
||||
'forum_id': forum_id,
|
||||
'name': question.get('name'),
|
||||
'content': question.get('content'),
|
||||
'tags' : question.get('tags'),
|
||||
'state': 'active',
|
||||
'active': True,
|
||||
}, context=create_context)
|
||||
return werkzeug.utils.redirect("/question/%s" % new_question_id)
|
||||
|
||||
@http.route('/question/new/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def post_answer(self, post_id, forum_id=1, **question):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
create_context = dict(context)
|
||||
new_question_id = request.registry['blog.post'].create(
|
||||
request.cr, request.uid, {
|
||||
'forum_id': forum_id,
|
||||
'parent_id':post_id,
|
||||
'name': question.get('name'),
|
||||
'content': question.get('content'),
|
||||
'tags' : question.get('tags'),
|
||||
'state': 'active',
|
||||
'active': True,
|
||||
}, context=create_context)
|
||||
return werkzeug.utils.redirect("/question/%s" % post_id)
|
|
@ -52,7 +52,7 @@ class Post(osv.Model):
|
|||
'forum_id': fields.many2one('website.forum', 'Forum'),
|
||||
|
||||
'name': fields.char('Topic', size=64),
|
||||
'body': fields.html('Contents', help='Automatically sanitized HTML contents'),
|
||||
'content': fields.html('Contents', help='Automatically sanitized HTML contents'),
|
||||
|
||||
'create_date': fields.datetime('Asked on', select=True, readonly=True),
|
||||
'create_uid': fields.many2one('res.users', 'Asked by', select=True, readonly=True ),
|
||||
|
@ -85,6 +85,37 @@ class Post(osv.Model):
|
|||
'state': 'active',
|
||||
'active': True
|
||||
}
|
||||
|
||||
def create_history(self, cr, uid, ids, vals, context=None):
|
||||
for forum in ids:
|
||||
history = self.pool.get('website.forum.post.history')
|
||||
if vals.get('content'):
|
||||
create_date = vals.get('create_date')
|
||||
res = {
|
||||
'name': 'Update %s - %s' % (create_date, vals.get('name')),
|
||||
'content': vals.get('content', ''),
|
||||
'forum_id': forum
|
||||
}
|
||||
if vals.get('version'):
|
||||
res.update({'version':vals.get('version')})
|
||||
|
||||
if vals.get('tags'):
|
||||
res.update({'tags':vals.get('tags')})
|
||||
|
||||
history.create(cr, uid, res)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
create_context = dict(context, mail_create_nolog=True)
|
||||
post_id = super(Post, self).create(cr, uid, vals, context=create_context)
|
||||
self.create_history(cr, uid, [post_id], vals, context)
|
||||
return post_id
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
result = super(Post, self).write(cr, uid, ids, vals, context)
|
||||
self.create_history(cr, uid, ids, vals, context)
|
||||
return result
|
||||
|
||||
class Users(osv.Model):
|
||||
_inherit = 'res.users'
|
||||
|
@ -112,7 +143,7 @@ class PostHistory(osv.Model):
|
|||
'create_uid': fields.many2one('res.users', 'Created by', select=True, readonly=True),
|
||||
'version': fields.integer('Version'),
|
||||
'name': fields.char('Update Notes', size=64, required=True),
|
||||
'body': fields.html('Contents', help='Automatically sanitized HTML contents'),
|
||||
'content': fields.html('Contents', help='Automatically sanitized HTML contents'),
|
||||
'tags': fields.many2many('website.forum.tag', 'forum_tag_rel', 'forum_id', 'forum_tag_id', 'Tag'),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue