summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2012-12-14 11:43:29 +0100
committerRaphael Collet <rco@openerp.com>2012-12-14 11:43:29 +0100
commit34100dd535bb77dc442cbecc3d8ff2fde169faf0 (patch)
tree13461f472499847974781e504a23e66e627eb137
parentcc8025387b62318af86c94d7b884e4e899131bcb (diff)
[IMP] auth_signup: improve code that makes a signup url by using urlencode instead of manual stuff
bzr revid: rco@openerp.com-20121214104329-jhflp8vxwy4wzc10
-rw-r--r--addons/auth_signup/res_users.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/addons/auth_signup/res_users.py b/addons/auth_signup/res_users.py
index 5fd7917f444..cc7c3722540 100644
--- a/addons/auth_signup/res_users.py
+++ b/addons/auth_signup/res_users.py
@@ -20,8 +20,8 @@
##############################################################################
from datetime import datetime, timedelta
import random
-import urllib
-import urlparse
+from urllib import urlencode
+from urlparse import urljoin
from openerp.osv import osv, fields
from openerp.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
@@ -62,25 +62,27 @@ class res_partner(osv.Model):
if context and context.get('signup_valid') and not partner.user_ids:
self.signup_prepare(cr, uid, [partner.id], context=context)
- action_template = None
- params = {
- 'action': urllib.quote(action),
- 'db': urllib.quote(cr.dbname),
- }
+ # the parameters to encode for the query and fragment part of url
+ query = {'db': cr.dbname}
+ fragment = {'action': action}
+
if partner.signup_token:
- action_template = "?db=%(db)s#action=%(action)s&token=%(token)s"
- params['token'] = urllib.quote(partner.signup_token)
+ fragment['token'] = partner.signup_token
elif partner.user_ids:
- action_template = "?db=%(db)s#action=%(action)s&db=%(db)s&login=%(login)s"
- params['login'] = urllib.quote(partner.user_ids[0].login)
- if action_template:
- if view_type:
- action_template += '&view_type=%s' % urllib.quote(view_type)
- if menu_id:
- action_template += '&menu_id=%s' % urllib.quote(str(menu_id))
- if res_id:
- action_template += '&id=%s' % urllib.quote(str(res_id))
- res[partner.id] = urlparse.urljoin(base_url, action_template % params)
+ fragment['db'] = cr.dbname
+ fragment['login'] = partner.user_ids[0].login
+ else:
+ continue # no signup token, no user, thus no signup url!
+
+ if view_type:
+ fragment['view_type'] = view_type
+ if menu_id:
+ fragment['menu_id'] = menu_id
+ if res_id:
+ fragment['id'] = res_id
+
+ res[partner.id] = urljoin(base_url, "?%s#%s" % (urlencode(query), urlencode(fragment)))
+
return res
def _get_signup_url(self, cr, uid, ids, name, arg, context=None):