Browse Source

[PEP8] make code comply with PEP8

pull/1/head
houssine 6 years ago
parent
commit
3a8f60cc79
  1. 50
      easy_my_coop/controllers/main.py

50
easy_my_coop/controllers/main.py

@ -10,12 +10,18 @@ from openerp import http, SUPERUSER_ID
from openerp.http import request
from openerp.tools.translate import _
_TECHNICAL = ['view_from', 'view_callback'] # Only use for behavior, don't stock it
_BLACKLIST = ['id', 'create_uid', 'create_date', 'write_uid', 'write_date', 'user_id', 'active'] # Allow in description
# Only use for behavior, don't stock it
_TECHNICAL = ['view_from', 'view_callback']
# Allow in description
_BLACKLIST = ['id', 'create_uid', 'create_date', 'write_uid', 'write_date',
'user_id', 'active']
class WebsiteSubscription(http.Controller):
@http.route(['/page/become_cooperator','/become_cooperator'], type='http', auth="public", website=True)
@http.route(['/page/become_cooperator',
'/become_cooperator'],
type='http', auth="public", website=True)
def display_become_cooperator_page(self, **kwargs):
values = {}
if request.env.user.login != 'public':
@ -31,7 +37,9 @@ class WebsiteSubscription(http.Controller):
values.update(kwargs=kwargs.items())
return request.website.render("easy_my_coop.becomecooperator", values)
@http.route(['/page/become_company_cooperator','/become_company_cooperator'], type='http', auth="public", website=True)
@http.route(['/page/become_company_cooperator',
'/become_company_cooperator'],
type='http', auth="public", website=True)
def display_become_company_cooperator_page(self, **kwargs):
values = {}
@ -151,16 +159,23 @@ class WebsiteSubscription(http.Controller):
langs = request.env['res.lang'].sudo().search([])
return langs
@http.route(['/subscription/get_share_product'], type='json', auth="public", methods=['POST'], website=True)
@http.route(['/subscription/get_share_product'],
type='json',
auth="public",
methods=['POST'], website=True)
def get_share_product(self, share_product_id, **kw):
product = request.env['product.template'].sudo().browse(int(share_product_id))
return {product.id: {'list_price': product.list_price, 'min_qty': product.minimum_quantity, 'force_min_qty': product.force_min_qty}}
@http.route(['/subscription/subscribe_share'], type='http', auth="public", website=True)
@http.route(['/subscription/subscribe_share'],
type='http',
auth="public", website=True)
def share_subscription(self, **kwargs):
user_obj = request.env['res.users']
post_file = [] # List of file to add to ir_attachment once we have the ID
post_description = [] # Info to add after the message
# List of file to add to ir_attachment once we have the ID
post_file = []
# Info to add after the message
post_description = []
values = {}
for field_name, field_value in kwargs.items():
@ -168,7 +183,8 @@ class WebsiteSubscription(http.Controller):
post_file.append(field_value)
elif field_name in request.registry['subscription.request']._fields and field_name not in _BLACKLIST:
values[field_name] = field_value
elif field_name not in _TECHNICAL: # allow to add some free fields or blacklisted field like ID
# allow to add some free fields or blacklisted field like ID
elif field_name not in _TECHNICAL:
post_description.append("%s: %s" % (field_name, field_value))
logged = kwargs.get("logged") == 'on'
@ -188,9 +204,10 @@ class WebsiteSubscription(http.Controller):
values["is_company"] = is_company
if not kwargs.has_key('g-recaptcha-response') or not request.website.is_captcha_valid(kwargs['g-recaptcha-response']):
if 'g-recaptcha-response' not in kwargs or not request.website.is_captcha_valid(kwargs['g-recaptcha-response']):
values = self.fill_values(values, is_company)
values["error_msg"] = _("the captcha has not been validated, please fill in the captcha")
values["error_msg"] = _("the captcha has not been validated,"
" please fill in the captcha")
return request.website.render(redirect, values)
@ -199,11 +216,13 @@ class WebsiteSubscription(http.Controller):
if user:
values = self.fill_values(values, is_company)
values.update(kwargs)
values["error_msg"] = _("There is an existing account for this mail address. Please login before fill in the form")
values["error_msg"] = _("There is an existing account for this"
" mail address. Please login before "
"fill in the form")
return request.website.render(redirect, values)
# fields validation : Check that required field from model subscription_request exists
# Check that required field from model subscription_request exists
required_fields = request.env['subscription.request'].sudo().get_required_field()
error = set(field for field in required_fields if not values.get(field))
@ -214,7 +233,7 @@ class WebsiteSubscription(http.Controller):
return request.website.render(kwargs.get("view_from", redirect), values)
if kwargs.get("already_cooperator") == 'on':
already_cooperator = True
values["already_cooperator"] = True
lastname = kwargs.get("lastname").upper()
firstname = kwargs.get("firstname").title()
@ -261,7 +280,6 @@ class WebsiteSubscription(http.Controller):
'datas': base64.encodestring(field_value.read()),
'datas_fname': field_value.filename,
}
request.registry['ir.attachment'].create(request.cr, SUPERUSER_ID, attachment_value, context=request.context)
request.registry['ir.attachment'].sudo().create(attachment_value)
return self.get_subscription_response(values, kwargs)
Loading…
Cancel
Save