[IMP] survey: public url

bzr revid: chm@openerp.com-20130221111406-trgb8vpxm2wn87x3
This commit is contained in:
Christophe Matthieu
2013-02-21 12:14:06 +01:00
parent e80f146a6c
commit da78f7f6ca
4 changed files with 35 additions and 20 deletions
+20
View File
@@ -20,6 +20,8 @@
##############################################################################
import copy
from urllib import urlencode
from urlparse import urljoin
from datetime import datetime
from openerp.osv import fields, osv
from openerp.tools.translate import _
@@ -64,6 +66,23 @@ class survey(osv.osv):
res[id] = sur_res_obj.search(cr, uid, [('survey_id', '=', id), ('state', '=', 'done')], context=context, count=True)
return res
def _get_public_url(self, cr, uid, ids, name, arg, context=None):
""" Compute if the message is unread by the current user. """
res = dict((id, 0) for id in ids)
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'survey', 'action_complete')
for id in ids:
query = {
'db': cr.dbname
}
fragment = {
'active_id': id,
'action': model_id[1],
}
res[id] = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
return res
_columns = {
'title': fields.char('Survey Title', size=128, required=1),
'page_ids': fields.one2many('survey.page', 'survey_id', 'Page'),
@@ -81,6 +100,7 @@ class survey(osv.osv):
'type': fields.many2one('survey.type', 'Type'),
'color': fields.integer('Color Index'),
'response_ids': fields.one2many('survey.response', 'survey_id', 'Responses', readonly=1),
'public_url': fields.function(_get_public_url, string="Public url", type="char"),
}
_defaults = {
'state': "draft",
+6 -1
View File
@@ -47,7 +47,10 @@
</group>
<group>
<field name="max_response_limit" attrs="{'readonly':[('state','=','close')]}"/>
<field name="send_response" attrs="{'readonly':[('state','=',['close','cancel'])]}"/>
<field name="send_response" attrs="{'readonly':[('state','in',['close','cancel'])]}"/>
</group>
<group colspan="4">
<field name="public_url" attrs="{'invisible':[('open_options','=','restricted')]}"/>
</group>
</group>
<field name="page_ids" colspan="4" mode="tree" attrs="{'readonly':[('state','=','close')]}">
@@ -273,6 +276,8 @@
<field name="responsible_id"/>
<field name="color"/>
<field name="state"/>
<field name="open_options"/>
<field name="public_url"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_survey">
+1 -1
View File
@@ -33,7 +33,7 @@
<field name="target">new</field>
</record>
<record id="action_answer_survey" model="ir.actions.act_window">
<record id="action_complete" model="ir.actions.act_window">
<field name="type">ir.actions.act_window</field>
<field name="res_model">survey.question.wiz</field>
<field name="view_type">form</field>
@@ -20,8 +20,6 @@
##############################################################################
import re
from urllib import urlencode
from urlparse import urljoin
from openerp.osv import osv
from openerp.osv import fields
from datetime import datetime
@@ -57,12 +55,12 @@ class survey_mail_compose_message(osv.TransientModel):
emails_split = re.compile(r"[;,\n\r]+")
survey_response_obj = self.pool.get('survey.response')
survey_obj = self.pool.get('survey')
partner_obj = self.pool.get('res.partner')
mail_mail_obj = self.pool.get('mail.mail')
mail_message_obj = self.pool.get('mail.message')
base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
def create_response_and_send_mail(wizard, token, partner_id, email):
def create_response_and_send_mail(wizard, token, partner_id, email, public_url):
""" Create one mail by recipients and replace __URL__ by link with identification token
"""
# create response with token
@@ -77,23 +75,12 @@ class survey_mail_compose_message(osv.TransientModel):
'email': email,
})
# create url
query = {
'db': cr.dbname
}
fragment = {
'active_id': wizard.res_id,
'params': token,
'action': 'survey.action_answer_survey',
}
url = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
# post the message
values = {
'model': 'survey',
'res_id': wizard.res_id or False,
'subject': wizard.subject,
'body': wizard.body.replace("__URL__", url),
'body': wizard.body.replace("__URL__", "%s&params=%s" % (public_url, token)),
'parent_id': None,
'partner_ids': partner_id and [(4, partner_id)] or None,
'notified_partner_ids': partner_id and [(4, partner_id)] or None,
@@ -134,13 +121,16 @@ class survey_mail_compose_message(osv.TransientModel):
if not len(emails_checked) and not len(wizard.partner_ids):
raise osv.except_osv(_('Warning!'), _("Please enter at least one recipient."))
publi_url = survey_obj.browse(cr, uid, wizard.res_id, context=context).public_url
for email in emails_checked:
partner_id = partner_obj.search(cr, uid, [('email', '=', email)], context=context)
partner_id = partner_id and partner_id[0] or None
create_response_and_send_mail(wizard, token, partner_id, email)
token = create_token(wizard, partner_id, email)
create_response_and_send_mail(wizard, token, partner_id, email, publi_url)
for partner in wizard.partner_ids:
token = create_token(wizard, partner.id, partner.email)
create_response_and_send_mail(wizard, token, partner.id, partner.email)
create_response_and_send_mail(wizard, token, partner.id, partner.email, publi_url)
return {'type': 'ir.actions.act_window_close'}