1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import osv, fields
23 from openerp import SUPERUSER_ID
25 from openerp.tools.translate import _
28 from openerp.addons.website.models.website import slug
33 _inherit = ['event.event','website.seo.metadata']
35 def _get_new_menu_pages(self, cr, uid, event, context=None):
36 context = context or {}
38 (_('Introduction'), 'website_event.template_intro'),
39 (_('Location'), 'website_event.template_location')
41 web = self.pool.get('website')
43 for name,path in todo:
44 name2 = name+' '+event.name
45 newpath = web.new_page(cr, uid, name2, path, ispage=False, context=context)
46 url = "/event/"+slug(event)+"/page/" + newpath
47 result.append((name, url))
50 def _set_show_menu(self, cr, uid, ids, name, value, arg, context=None):
51 menuobj = self.pool.get('website.menu')
52 eventobj = self.pool.get('event.event')
53 for event in self.browse(cr, uid, [ids], context=context):
54 if event.menu_id and not value:
55 menuobj.unlink(cr, uid, [event.menu_id.id], context=context)
56 elif value and not event.menu_id:
57 root = menuobj.create(cr, uid, {
60 tocreate = self._get_new_menu_pages(cr, uid, event, context)
61 tocreate.append((_('Register'), '/event/%s/register' % slug(event)))
63 for name,url in tocreate:
64 menuobj.create(cr, uid, {
71 eventobj.write(cr, uid, [event.id], {'menu_id': root}, context=context)
74 def _get_show_menu(self, cr, uid, ids, field_name, arg, context=None):
75 res = dict.fromkeys(ids, '')
76 for event in self.browse(cr, uid, ids, context=context):
77 res[event.id] = bool(event.menu_id)
80 def _website_url(self, cr, uid, ids, field_name, arg, context=None):
81 res = dict.fromkeys(ids, '')
82 for event in self.browse(cr, uid, ids, context=context):
83 res[event.id] = "/event/" + slug(event)
86 def _default_hashtag(self, cr, uid, context={}):
87 name = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name
88 return re.sub("[- \\.\\(\\)\\@\\#\\&]+", "", name).lower()
91 'twitter_hashtag': fields.char('Twitter Hashtag'),
92 'website_published': fields.boolean('Visible in Website', copy=False),
93 # TDE TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
94 'website_message_ids': fields.one2many(
95 'mail.message', 'res_id',
97 '&', ('model', '=', self._name), ('type', '=', 'comment')
99 string='Website Messages',
100 help="Website communication history",
102 'website_url': fields.function(_website_url, string="Website url", type="char"),
103 'show_menu': fields.function(_get_show_menu, fnct_inv=_set_show_menu, type='boolean', string='Dedicated Menu'),
104 'menu_id': fields.many2one('website.menu', 'Event Menu'),
108 'twitter_hashtag': _default_hashtag
111 def google_map_img(self, cr, uid, ids, zoom=8, width=298, height=298, context=None):
112 event = self.browse(cr, uid, ids[0], context=context)
114 return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_img()
117 def google_map_link(self, cr, uid, ids, zoom=8, context=None):
118 event = self.browse(cr, uid, ids[0], context=context)
120 return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_link()