[IMP] Performance improvement: improved cache with context, better get_object
bzr revid: fp@tinyerp.com-20131130154659-uqis34x2cemmocly
This commit is contained in:
parent
56eb2c0607
commit
ed7623fc45
|
@ -260,10 +260,9 @@ class res_users(osv.Model):
|
|||
# send email to users with their signup url
|
||||
template = False
|
||||
if context.get('create_user'):
|
||||
try:
|
||||
template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'set_password_email')
|
||||
except ValueError:
|
||||
pass
|
||||
template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'set_password_email')
|
||||
if not template.exists():
|
||||
template = False
|
||||
if not bool(template):
|
||||
template = self.pool.get('ir.model.data').get_object(cr, uid, 'auth_signup', 'reset_password_email')
|
||||
assert template._name == 'email.template'
|
||||
|
|
|
@ -55,7 +55,7 @@ class res_partner(osv.osv, EDIMixin):
|
|||
res_partner_bank_type = self.pool.get('res.partner.bank.type')
|
||||
try:
|
||||
return self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'bank_normal', context=context).code
|
||||
except ValueError:
|
||||
except:
|
||||
pass
|
||||
# second option: create a new custom type for EDI or use it if already created, as IBAN type is
|
||||
# not always appropriate: we need a free-form bank type for max flexibility (users can correct
|
||||
|
|
|
@ -461,9 +461,8 @@ class mail_thread(osv.AbstractModel):
|
|||
|
||||
posted = False
|
||||
for subtype in subtypes:
|
||||
try:
|
||||
subtype_rec = self.pool.get('ir.model.data').get_object(cr, uid, subtype.split('.')[0], subtype.split('.')[1], context=context)
|
||||
except ValueError, e:
|
||||
subtype_rec = self.pool.get('ir.model.data').get_object(cr, uid, subtype.split('.')[0], subtype.split('.')[1], context=context)
|
||||
if not subtype_rec.exists():
|
||||
_logger.debug('subtype %s not found, giving error "%s"' % (subtype, e))
|
||||
continue
|
||||
message = format_message(subtype_rec.description if subtype_rec.description else subtype_rec.name, tracked_values)
|
||||
|
|
|
@ -94,13 +94,11 @@ class publisher_warranty_contract(osv.osv):
|
|||
# old behavior based on res.log; now on mail.message, that is not necessarily installed
|
||||
IMD = self.pool['ir.model.data']
|
||||
user = self.pool['res.users'].browse(cr, SUPERUSER_ID, SUPERUSER_ID)
|
||||
try:
|
||||
poster = IMD.get_object(cr, SUPERUSER_ID, 'mail', 'group_all_employees')
|
||||
except ValueError:
|
||||
# Cannot found group, post the message on the wall of the admin
|
||||
poster = user
|
||||
poster = IMD.get_object(cr, SUPERUSER_ID, 'mail', 'group_all_employees')
|
||||
if not poster.exists():
|
||||
return True
|
||||
if not user.exists():
|
||||
return True
|
||||
poster = user
|
||||
for message in result["messages"]:
|
||||
try:
|
||||
poster.message_post(body=message, subtype='mt_comment', partner_ids=[user.partner_id.id])
|
||||
|
|
|
@ -87,12 +87,9 @@ Example: 10% for retailers, promotion of 5 EUR on this product, etc."""),
|
|||
user = self.pool.get('res.users').browse(cr, uid, uid, context)
|
||||
res['time_unit'] = user.company_id.project_time_mode_id.id
|
||||
else:
|
||||
try:
|
||||
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
|
||||
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
|
||||
if product.exists():
|
||||
res['time_unit'] = product.uom_id.id
|
||||
except ValueError:
|
||||
# keep default value in that case
|
||||
_logger.warning("Product with xml_id 'product.product_product_consultant' not found")
|
||||
return res
|
||||
|
||||
def _get_default_time_unit(self, cr, uid, context=None):
|
||||
|
@ -108,10 +105,10 @@ Example: 10% for retailers, promotion of 5 EUR on this product, etc."""),
|
|||
wizard = self.browse(cr, uid, ids)[0]
|
||||
|
||||
if wizard.time_unit:
|
||||
try:
|
||||
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
|
||||
product = ir_model_data.get_object(cr, uid, 'product', 'product_product_consultant')
|
||||
if product.exists():
|
||||
product.write({'uom_id': wizard.time_unit.id, 'uom_po_id': wizard.time_unit.id})
|
||||
except ValueError:
|
||||
else:
|
||||
_logger.warning("Product with xml_id 'product.product_product_consultant' not found, UoMs not updated!")
|
||||
|
||||
if wizard.module_project and wizard.time_unit:
|
||||
|
|
|
@ -27,8 +27,10 @@ class stock_fill_inventory(osv.osv_memory):
|
|||
_description = "Import Inventory"
|
||||
|
||||
def _default_location(self, cr, uid, ids, context=None):
|
||||
location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock')
|
||||
if not location.exists():
|
||||
return False
|
||||
try:
|
||||
location = self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'stock_location_stock')
|
||||
location.check_access_rule('read', context=context)
|
||||
location_id = location.id
|
||||
except (ValueError, orm.except_orm), e:
|
||||
|
|
|
@ -25,7 +25,7 @@ class ir_http(orm.AbstractModel):
|
|||
def _auth_method_public(self):
|
||||
if not request.session.uid:
|
||||
request.uid = request.registry['website'].get_public_user(
|
||||
request.cr, openerp.SUPERUSER_ID, request.context).id
|
||||
request.cr, openerp.SUPERUSER_ID, request.context)
|
||||
else:
|
||||
request.uid = request.session.uid
|
||||
|
||||
|
|
|
@ -69,6 +69,10 @@ def urlplus(url, params):
|
|||
))
|
||||
|
||||
class website(osv.osv):
|
||||
def _get_public_user(self, cr, uid, ids, name='public_user', arg=(), context=None):
|
||||
ref = self.get_public_user(cr, uid, context=context)
|
||||
return dict( map(lambda x: (x, ref), ids) )
|
||||
|
||||
_name = "website" # Avoid website.website convention for conciseness (for new api). Got a special authorization from xmo and rco
|
||||
_description = "Website"
|
||||
_columns = {
|
||||
|
@ -82,9 +86,9 @@ class website(osv.osv):
|
|||
'social_linkedin': fields.char('LinkedIn Account'),
|
||||
'social_youtube': fields.char('Youtube Account'),
|
||||
'social_googleplus': fields.char('Google+ Account'),
|
||||
'public_user': fields.function(_get_public_user, relation='res.users', type='many2one', string='Public User', store=True)
|
||||
}
|
||||
|
||||
public_user = None
|
||||
def new_page(self, cr, uid, name, template='website.default_page', ispage=True, context=None):
|
||||
context=context or {}
|
||||
# completely arbitrary max_length
|
||||
|
@ -133,11 +137,8 @@ class website(osv.osv):
|
|||
return False
|
||||
|
||||
def get_public_user(self, cr, uid, context=None):
|
||||
if not self.public_user:
|
||||
uid = openerp.SUPERUSER_ID
|
||||
ref = self.pool['ir.model.data'].get_object_reference(cr, uid, 'website', 'public_user')
|
||||
self.public_user = self.pool[ref[0]].browse(cr, uid, ref[1])
|
||||
return self.public_user
|
||||
uid = openerp.SUPERUSER_ID
|
||||
return self.pool['ir.model.data'].get_object_reference(cr, uid, 'website', 'public_user')[1]
|
||||
|
||||
def get_current_website(self, cr, uid, context=None):
|
||||
# TODO: Select website, currently hard coded
|
||||
|
@ -147,7 +148,6 @@ class website(osv.osv):
|
|||
def redirect(url):
|
||||
return werkzeug.utils.redirect(url_for(url))
|
||||
request.redirect = redirect
|
||||
is_public_user = request.uid == self.get_public_user(cr, uid, context).id
|
||||
|
||||
user = self.pool['res.users'].browse(cr, uid, uid, context=context)
|
||||
website_publisher_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_website_publisher')[1]
|
||||
|
@ -156,10 +156,9 @@ class website(osv.osv):
|
|||
lang = request.context['lang']
|
||||
is_master_lang = lang == request.website.default_lang_id.code
|
||||
request.context.update({
|
||||
'is_public_user': is_public_user,
|
||||
'is_master_lang': is_master_lang,
|
||||
'editable': is_website_publisher,
|
||||
'translatable': not is_public_user and not is_master_lang,
|
||||
'translatable': not is_master_lang,
|
||||
})
|
||||
|
||||
def get_template(self, cr, uid, ids, template, context=None):
|
||||
|
@ -333,7 +332,7 @@ class website(osv.osv):
|
|||
"""
|
||||
router = request.httprequest.app.get_db_router(request.db)
|
||||
# Force enumeration to be performed as public user
|
||||
uid = self.get_public_user(cr, uid, context=context).id
|
||||
uid = self.get_public_user(cr, uid, context=context)[1].id
|
||||
for rule in router.iter_rules():
|
||||
if not self.rule_is_enumerable(rule):
|
||||
continue
|
||||
|
|
|
@ -215,21 +215,20 @@
|
|||
|
||||
<!-- Options: Blog Post: user can reply -->
|
||||
<template id="opt_blog_post_complete_comment" name="Allow Comments"
|
||||
inherit_option_id="website_blog.blog_post_complete" inherit_id="website_blog.blog_post_complete">
|
||||
inherit_option_id="website_blog.blog_post_complete" inherit_id="website_blog.blog_post_complete"
|
||||
groups="website_mail.group_comment">
|
||||
<xpath expr="//ul[@id='comments-list']" position="after">
|
||||
<t t-if="not is_public_user">
|
||||
<section groups="group_website_blog_reply" class="mb32">
|
||||
<form id="comment" t-attf-action="/blogpost/#{blog_post.id}/#{ path_filter }/comment"
|
||||
method="POST">
|
||||
<img class="img pull-left img-rounded" t-att-src="'/website/image?model=res.partner&field=image_small&id='+str(user_id.partner_id.id)" style="width: 50px; margin-right: 10px;"/>
|
||||
<div class="pull-left mb32" style="width: 75%%">
|
||||
<textarea rows="3" name="comment" class="form-control" placeholder="Write a comment..."></textarea>
|
||||
<button type="submit" class="btn btn-primary mt8">Post</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<div class="clearfix"/>
|
||||
</t>
|
||||
<section class="mb32">
|
||||
<form id="comment" t-attf-action="/blogpost/#{blog_post.id}/#{ path_filter }/comment"
|
||||
method="POST">
|
||||
<img class="img pull-left img-rounded" t-att-src="'/website/image?model=res.partner&field=image_small&id='+str(user_id.partner_id.id)" style="width: 50px; margin-right: 10px;"/>
|
||||
<div class="pull-left mb32" style="width: 75%%">
|
||||
<textarea rows="3" name="comment" class="form-control" placeholder="Write a comment..."></textarea>
|
||||
<button type="submit" class="btn btn-primary mt8">Post</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<div class="clearfix"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@ class WebsiteCrmPartnerAssign(http.Controller):
|
|||
|
||||
# format displayed membership lines domain
|
||||
base_partner_domain = [('is_company', '=', True)]
|
||||
if request.context['is_public_user']:
|
||||
base_partner_domain += [('website_published', '=', True)]
|
||||
partner_domain = list(base_partner_domain)
|
||||
if grade_id and grade_id != "all":
|
||||
partner_domain += [('grade_id', '=', int(grade_id))] # try/catch int
|
||||
|
@ -93,10 +91,7 @@ class WebsiteCrmPartnerAssign(http.Controller):
|
|||
@website.route(['/partners/<int:partner_id>/'], type='http', auth="public", multilang=True)
|
||||
def partners_ref(self, partner_id=0, **post):
|
||||
partner_obj = request.registry['res.partner']
|
||||
if request.context['is_public_user']:
|
||||
partner_ids = partner_obj.search(request.cr, request.uid, [('website_published', '=', True), ('id', '=', partner_id)], context=request.context)
|
||||
else:
|
||||
partner_ids = partner_obj.search(request.cr, request.uid, [('id', '=', partner_id)], context=request.context)
|
||||
partner_ids = partner_obj.search(request.cr, request.uid, [('id', '=', partner_id)], context=request.context)
|
||||
if not partner_ids:
|
||||
return self.members(post)
|
||||
|
||||
|
|
|
@ -26,11 +26,6 @@ class google_map(http.Controller):
|
|||
domain_public = domain + [('website_published', '=', True)]
|
||||
partner_ids = partner_obj.search(request.cr, openerp.SUPERUSER_ID,
|
||||
domain_public, context=request.context)
|
||||
if not request.context['is_public_user']:
|
||||
partner_ids += partner_obj.search(request.cr, request.uid, domain,
|
||||
context=request.context)
|
||||
partner_ids = list(set(partner_ids))
|
||||
|
||||
return partner_obj.google_map_json(request.cr, openerp.SUPERUSER_ID,
|
||||
partner_ids, request.context)
|
||||
|
||||
|
@ -42,14 +37,13 @@ class google_map(http.Controller):
|
|||
latitude = post.get('latitude') and float(post['latitude'])
|
||||
longitude = post.get('longitude') and float(post['longitude'])
|
||||
|
||||
if not request.context['is_public_user'] and partner_id and (latitude or longitude):
|
||||
values = {
|
||||
'partner_latitude': latitude,
|
||||
'partner_longitude': longitude,
|
||||
'date_localization': datetime.now().strftime('%Y-%m-%d'),
|
||||
}
|
||||
partner_obj.write(request.cr, request.uid, [partner_id], values,
|
||||
request.context)
|
||||
values = {
|
||||
'partner_latitude': latitude,
|
||||
'partner_longitude': longitude,
|
||||
'date_localization': datetime.now().strftime('%Y-%m-%d'),
|
||||
}
|
||||
partner_obj.write(request.cr, request.uid, [partner_id], values,
|
||||
request.context)
|
||||
|
||||
|
||||
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
'depends': ['website', 'mail'],
|
||||
'data': [
|
||||
'views/website_mail.xml',
|
||||
'security/website_mail.xml',
|
||||
],
|
||||
'css': [
|
||||
'static/src/css/website_mail.css',
|
||||
|
|
|
@ -32,7 +32,7 @@ class WebsiteMail(http.Controller):
|
|||
partner_obj = request.registry['res.partner']
|
||||
user_obj = request.registry['res.users']
|
||||
partner_ids = []
|
||||
if request.context['is_public_user'] and email and email != u'false': # post contains stringified booleans
|
||||
if email and email != u'false': # post contains stringified booleans
|
||||
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", email)], context=request.context)
|
||||
if not partner_ids:
|
||||
partner_ids = [partner_obj.name_create(request.cr, SUPERUSER_ID, email, request.context)]
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="group_comment" model="res.groups">
|
||||
<field name="name">Website Comments</field>
|
||||
<field name="comment">Allows website visitors to post comments on blogs, etc.</field>
|
||||
</record>
|
||||
|
||||
<record id="base.group_user" model="res.groups">
|
||||
<field name="implied_ids" eval="[(4, ref('website_mail.group_comment'))]"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -31,9 +31,7 @@ class TestControllers(TestMail):
|
|||
# print request
|
||||
|
||||
cr, uid = self.cr, self.uid
|
||||
# context = {
|
||||
# 'is_public_user': True,
|
||||
# }
|
||||
# context = { }
|
||||
# email = 'Marcel Dupuis <marcel.dupuis@example.com>'
|
||||
# website_mail = WebsiteMail()
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="input-group js_follow" t-att-data-id="object.id"
|
||||
t-att-data-object="object._name"
|
||||
t-att-data-follow="object.id and object.message_is_follower and 'on' or 'off'">
|
||||
<input t-if="is_public_user"
|
||||
<input
|
||||
type="email" name="email"
|
||||
class="js_follow_email form-control"
|
||||
t-att-value="email or ''"
|
||||
|
|
|
@ -312,10 +312,12 @@ class Ecommerce(http.Controller):
|
|||
fill_hole = product_obj.search(request.cr, request.uid, domain, limit=step, offset=pager['offset']+step, order=self._order, context=request.context)
|
||||
|
||||
styles = []
|
||||
if not request.context['is_public_user']:
|
||||
try:
|
||||
style_obj = request.registry.get('website.product.style')
|
||||
style_ids = style_obj.search(request.cr, request.uid, [], context=request.context)
|
||||
styles = style_obj.browse(request.cr, request.uid, style_ids, context=request.context)
|
||||
except:
|
||||
pass
|
||||
|
||||
values = {
|
||||
'Ecommerce': self,
|
||||
|
@ -520,7 +522,7 @@ class Ecommerce(http.Controller):
|
|||
checkout = values['checkout']
|
||||
error = values['error']
|
||||
|
||||
if not context['is_public_user']:
|
||||
if not request.uid == self.pool.get('website').get_public_user(cr, uid, context):
|
||||
partner = orm_user.browse(cr, uid, uid, context).partner_id
|
||||
partner_info = info.from_partner(partner)
|
||||
checkout.update(partner_info)
|
||||
|
@ -596,7 +598,7 @@ class Ecommerce(http.Controller):
|
|||
billing_info = dict(checkout)
|
||||
billing_info['parent_id'] = company_id
|
||||
|
||||
if not context['is_public_user']:
|
||||
if not request.uid == self.pool.get('website').get_public_user(cr, uid, context):
|
||||
partner_id = orm_user.browse(cr, uid, uid, context=context).partner_id.id
|
||||
orm_parter.write(cr, uid, [partner_id], billing_info, context=context)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue