|
|
"""Heuristic
* public, no visitor: not participating as we have no information;
* check only confirmed and attended registrations, a draft registration
does not make the attendee participating;
* public and visitor: check visitor is linked to a registration. As
visitors are merged on the top parent, current visitor check is
sufficient even for successive visits;
* logged, no visitor: check partner is linked to a registration. Do
not check the email as it is not really secure;
* logged as visitor: check partner or visitor are linked to a
registration;
"""
current_visitor = self.env['website.visitor']._get_visitor_from_request(force_create=False)
base_domain = [('event_id', 'in', self.ids), ('state', 'in', ['open', 'done'])]
if self.env.user._is_public() and not current_visitor:
events = self.env['event.event']
elif self.env.user._is_public():
events = self.env['event.registration'].sudo().search(
expression.AND([base_domain, [('visitor_id', '=', current_visitor.id)]])
).event_id
else:
if current_visitor:
domain = [
'|',
('partner_id', '=', self.env.user.partner_id.id),
('visitor_id', '=', current_visitor.id)
]
else:
domain = [('partner_id', '=', self.env.user.partner_id.id)]
events = self.env['event.registration'].sudo().search(
expression.AND([base_domain, domain])
).event_id
for event in self:
event.is_participating = event in events
|
|