[CLEAN] website_event: migrate models to the new API + some code cleaning.
Updated some code in website_event_track, inheritance with new API. Controllers need a major cleaning, but, hey, they are too creepy.
This commit is contained in:
@@ -1,36 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
import werkzeug.urls
|
||||
from datetime import datetime, timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
import werkzeug.urls
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from openerp import http
|
||||
from openerp import tools
|
||||
from openerp.addons.website.models.website import slug
|
||||
from openerp.http import request
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.website.models.website import slug
|
||||
|
||||
|
||||
class website_event(http.Controller):
|
||||
@http.route(['/event', '/event/page/<int:page>'], type='http', auth="public", website=True)
|
||||
@@ -47,7 +27,8 @@ class website_event(http.Controller):
|
||||
domain_search = {}
|
||||
|
||||
def sdn(date):
|
||||
return date.strftime('%Y-%m-%d 23:59:59')
|
||||
return date.replace(hour=23, minute=59, second=59).strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
|
||||
def sd(date):
|
||||
return date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
today = datetime.today()
|
||||
@@ -59,11 +40,11 @@ class website_event(http.Controller):
|
||||
0],
|
||||
['week', _('This Week'), [
|
||||
("date_end", ">=", sd(today + relativedelta(days=-today.weekday()))),
|
||||
("date_begin", "<", sdn(today + relativedelta(days=6-today.weekday())))],
|
||||
("date_begin", "<", sdn(today + relativedelta(days=6-today.weekday())))],
|
||||
0],
|
||||
['nextweek', _('Next Week'), [
|
||||
("date_end", ">=", sd(today + relativedelta(days=7-today.weekday()))),
|
||||
("date_begin", "<", sdn(today + relativedelta(days=13-today.weekday())))],
|
||||
("date_begin", "<", sdn(today + relativedelta(days=13-today.weekday())))],
|
||||
0],
|
||||
['month', _('This month'), [
|
||||
("date_end", ">=", sd(today.replace(day=1))),
|
||||
@@ -71,7 +52,7 @@ class website_event(http.Controller):
|
||||
0],
|
||||
['nextmonth', _('Next month'), [
|
||||
("date_end", ">=", sd(today.replace(day=1) + relativedelta(months=1))),
|
||||
("date_begin", "<", (today.replace(day=1) + relativedelta(months=2)).strftime('%Y-%m-%d 00:00:00'))],
|
||||
("date_begin", "<", (today.replace(day=1) + relativedelta(months=2)).strftime('%Y-%m-%d 00:00:00'))],
|
||||
0],
|
||||
['old', _('Old Events'), [
|
||||
("date_end", "<", today.strftime('%Y-%m-%d 00:00:00'))],
|
||||
@@ -79,6 +60,7 @@ class website_event(http.Controller):
|
||||
]
|
||||
|
||||
# search domains
|
||||
# TDE note: WTF ???
|
||||
current_date = None
|
||||
current_type = None
|
||||
current_country = None
|
||||
@@ -98,7 +80,7 @@ class website_event(http.Controller):
|
||||
domain_search["country"] = [("country_id", "=", False)]
|
||||
|
||||
def dom_without(without):
|
||||
domain = [('state', "in", ['draft','confirm','done'])]
|
||||
domain = [('state', "in", ['draft', 'confirm', 'done'])]
|
||||
for key, search in domain_search.items():
|
||||
if key != without:
|
||||
domain += search
|
||||
@@ -106,7 +88,7 @@ class website_event(http.Controller):
|
||||
|
||||
# count by domains without self search
|
||||
for date in dates:
|
||||
if date[0] <> 'old':
|
||||
if date[0] != 'old':
|
||||
date[3] = event_obj.search(
|
||||
request.cr, request.uid, dom_without('date') + date[2],
|
||||
count=True, context=request.context)
|
||||
@@ -146,7 +128,7 @@ class website_event(http.Controller):
|
||||
scope=5)
|
||||
|
||||
order = 'website_published desc, date_begin'
|
||||
if searches.get('date','all') == 'old':
|
||||
if searches.get('date', 'all') == 'old':
|
||||
order = 'website_published desc, date_begin desc'
|
||||
obj_ids = event_obj.search(
|
||||
request.cr, request.uid, dom_without("none"), limit=step,
|
||||
@@ -189,7 +171,7 @@ class website_event(http.Controller):
|
||||
target_url = '/event/%s/register' % str(event.id)
|
||||
if post.get('enable_editor') == '1':
|
||||
target_url += '?enable_editor=1'
|
||||
return request.redirect(target_url);
|
||||
return request.redirect(target_url)
|
||||
|
||||
@http.route(['/event/<model("event.event"):event>/register'], type='http', auth="public", website=True)
|
||||
def event_register(self, event, **post):
|
||||
@@ -222,24 +204,24 @@ class website_event(http.Controller):
|
||||
start_date = datetime.strptime(event.date_begin, tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
end_date = datetime.strptime(event.date_end, tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
|
||||
return ('%s %s%s') % (start_date.strftime("%b"), start_date.strftime("%e"), (end_date != start_date and ("-"+end_date.strftime("%e")) or ""))
|
||||
|
||||
|
||||
@http.route('/event/get_country_event_list', type='http', auth='public', website=True)
|
||||
def get_country_events(self ,**post):
|
||||
cr, uid, context, event_ids = request.cr, request.uid, request.context,[]
|
||||
def get_country_events(self, **post):
|
||||
cr, uid, context, event_ids = request.cr, request.uid, request.context, []
|
||||
country_obj = request.registry['res.country']
|
||||
event_obj = request.registry['event.event']
|
||||
country_code = request.session['geoip'].get('country_code')
|
||||
result = {'events':[],'country':False}
|
||||
result = {'events': [], 'country': False}
|
||||
if country_code:
|
||||
country_ids = country_obj.search(cr, uid, [('code', '=', country_code)], context=context)
|
||||
event_ids = event_obj.search(cr, uid, ['|', ('address_id', '=', None),('country_id.code', '=', country_code),('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00')),('state', '=', 'confirm')], order="date_begin", context=context)
|
||||
event_ids = event_obj.search(cr, uid, ['|', ('address_id', '=', None), ('country_id.code', '=', country_code), ('date_begin', '>=', time.strftime('%Y-%m-%d 00:00:00')), ('state', '=', 'confirm')], order="date_begin", context=context)
|
||||
if not event_ids:
|
||||
event_ids = event_obj.search(cr, uid, [('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00')),('state', '=', 'confirm')], order="date_begin", context=context)
|
||||
event_ids = event_obj.search(cr, uid, [('date_begin', '>=', time.strftime('%Y-%m-%d 00:00:00')), ('state', '=', 'confirm')], order="date_begin", context=context)
|
||||
for event in event_obj.browse(cr, uid, event_ids, context=context)[:6]:
|
||||
if country_code and event.country_id.code == country_code:
|
||||
result['country'] = country_obj.browse(cr, uid, country_ids[0], context=context)
|
||||
result['events'].append({
|
||||
"date": self.get_formated_date(event),
|
||||
"event": event,
|
||||
"url": event.website_url})
|
||||
return request.website.render("website_event.country_events_list",result)
|
||||
"date": self.get_formated_date(event),
|
||||
"event": event,
|
||||
"url": event.website_url})
|
||||
return request.website.render("website_event.country_events_list", result)
|
||||
|
||||
@@ -1,112 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import osv, fields
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
# from openerp.osv import osv, fields
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
from openerp.tools.translate import _
|
||||
# from openerp.tools.translate import _
|
||||
import re
|
||||
|
||||
from openerp.addons.website.models.website import slug
|
||||
|
||||
|
||||
class event(osv.osv):
|
||||
class event(models.Model):
|
||||
_name = 'event.event'
|
||||
_inherit = ['event.event','website.seo.metadata']
|
||||
_inherit = ['event.event', 'website.seo.metadata']
|
||||
|
||||
def _get_new_menu_pages(self, cr, uid, event, context=None):
|
||||
context = context or {}
|
||||
twitter_hashtag = fields.Char('Twitter Hashtag', default=lambda self: self._default_hashtag())
|
||||
website_published = fields.Boolean('Visible in Website', copy=False)
|
||||
# TDE TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
||||
website_message_ids = fields.One2many(
|
||||
'mail.message', 'res_id',
|
||||
domain=lambda self: [
|
||||
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
||||
],
|
||||
string='Website Messages',
|
||||
help="Website communication history",
|
||||
)
|
||||
website_url = fields.Char('Website url', compute='_website_url')
|
||||
|
||||
@api.one
|
||||
@api.depends('name')
|
||||
def _website_url(self):
|
||||
self.website_url = "/event/" + slug(self)
|
||||
|
||||
@api.one
|
||||
def _default_hashtag(self):
|
||||
self.twitter_hashtag = re.sub("[- \\.\\(\\)\\@\\#\\&]+", "", self.env.user.company_id.name).lower()
|
||||
|
||||
show_menu = fields.Boolean('Has Dedicated Menu', compute='_get_show_menu', inverse='_set_show_menu')
|
||||
menu_id = fields.Many2one('website.menu', 'Event Menu')
|
||||
|
||||
@api.one
|
||||
def _get_new_menu_pages(self):
|
||||
todo = [
|
||||
(_('Introduction'), 'website_event.template_intro'),
|
||||
(_('Location'), 'website_event.template_location')
|
||||
]
|
||||
web = self.pool.get('website')
|
||||
result = []
|
||||
for name,path in todo:
|
||||
name2 = name+' '+event.name
|
||||
newpath = web.new_page(cr, uid, name2, path, ispage=False, context=context)
|
||||
url = "/event/"+slug(event)+"/page/" + newpath
|
||||
for name, path in todo:
|
||||
complete_name = name + ' ' + self.name
|
||||
newpath = self.env['website'].new_page(complete_name, path, ispage=False)
|
||||
url = "/event/" + slug(self) + "/page/" + newpath
|
||||
result.append((name, url))
|
||||
result.append((_('Register'), '/event/%s/register' % slug(self)))
|
||||
return result
|
||||
|
||||
def _set_show_menu(self, cr, uid, ids, name, value, arg, context=None):
|
||||
menuobj = self.pool.get('website.menu')
|
||||
eventobj = self.pool.get('event.event')
|
||||
for event in self.browse(cr, uid, [ids], context=context):
|
||||
if event.menu_id and not value:
|
||||
menuobj.unlink(cr, uid, [event.menu_id.id], context=context)
|
||||
elif value and not event.menu_id:
|
||||
root = menuobj.create(cr, uid, {
|
||||
'name': event.name
|
||||
}, context=context)
|
||||
tocreate = self._get_new_menu_pages(cr, uid, event, context)
|
||||
tocreate.append((_('Register'), '/event/%s/register' % slug(event)))
|
||||
sequence = 0
|
||||
for name,url in tocreate:
|
||||
menuobj.create(cr, uid, {
|
||||
'name': name,
|
||||
'url': url,
|
||||
'parent_id': root,
|
||||
'sequence': sequence
|
||||
}, context=context)
|
||||
sequence += 1
|
||||
eventobj.write(cr, uid, [event.id], {'menu_id': root}, context=context)
|
||||
return True
|
||||
@api.one
|
||||
def _set_show_menu(self):
|
||||
if self.menu_id and not self.show_menu:
|
||||
self.menu_id.unlink()
|
||||
elif self.show_menu and not self.menu_id:
|
||||
root_menu = self.env['website.menu'].create({'name': self.name})
|
||||
to_create_menus = self._get_new_menu_pages()[0] # TDE CHECK api.one -> returns a list with one item ?
|
||||
seq = 0
|
||||
for name, url in to_create_menus:
|
||||
self.env['website.menu'].create({
|
||||
'name': name,
|
||||
'url': url,
|
||||
'parent_id': root_menu.id,
|
||||
'sequence': seq,
|
||||
})
|
||||
seq += 1
|
||||
self.menu_id = root_menu
|
||||
|
||||
def _get_show_menu(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict.fromkeys(ids, '')
|
||||
for event in self.browse(cr, uid, ids, context=context):
|
||||
res[event.id] = bool(event.menu_id)
|
||||
return res
|
||||
|
||||
def _website_url(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict.fromkeys(ids, '')
|
||||
for event in self.browse(cr, uid, ids, context=context):
|
||||
res[event.id] = "/event/" + slug(event)
|
||||
return res
|
||||
|
||||
def _default_hashtag(self, cr, uid, context={}):
|
||||
name = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.name
|
||||
return re.sub("[- \\.\\(\\)\\@\\#\\&]+", "", name).lower()
|
||||
|
||||
_columns = {
|
||||
'twitter_hashtag': fields.char('Twitter Hashtag'),
|
||||
'website_published': fields.boolean('Visible in Website', copy=False),
|
||||
# TDE TODO FIXME: when website_mail/mail_thread.py inheritance work -> this field won't be necessary
|
||||
'website_message_ids': fields.one2many(
|
||||
'mail.message', 'res_id',
|
||||
domain=lambda self: [
|
||||
'&', ('model', '=', self._name), ('type', '=', 'comment')
|
||||
],
|
||||
string='Website Messages',
|
||||
help="Website communication history",
|
||||
),
|
||||
'website_url': fields.function(_website_url, string="Website url", type="char"),
|
||||
'show_menu': fields.function(_get_show_menu, fnct_inv=_set_show_menu, type='boolean', string='Dedicated Menu'),
|
||||
'menu_id': fields.many2one('website.menu', 'Event Menu'),
|
||||
}
|
||||
_defaults = {
|
||||
'show_menu': False,
|
||||
'twitter_hashtag': _default_hashtag
|
||||
}
|
||||
@api.one
|
||||
def _get_show_menu(self):
|
||||
self.show_menu = bool(self.menu_id)
|
||||
|
||||
def google_map_img(self, cr, uid, ids, zoom=8, width=298, height=298, context=None):
|
||||
event = self.browse(cr, uid, ids[0], context=context)
|
||||
@@ -119,4 +88,3 @@ class event(osv.osv):
|
||||
if event.address_id:
|
||||
return self.browse(cr, SUPERUSER_ID, ids[0], context=context).address_id.google_map_link()
|
||||
return None
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import api
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.website.models.website import slug
|
||||
@@ -173,16 +174,16 @@ class event_event(osv.osv):
|
||||
'show_blog': False,
|
||||
}
|
||||
|
||||
def _get_new_menu_pages(self, cr, uid, event, context=None):
|
||||
context = context or {}
|
||||
result = super(event_event, self)._get_new_menu_pages(cr, uid, event, context=context)
|
||||
if event.show_tracks:
|
||||
result.append( (_('Talks'), '/event/%s/track' % slug(event)))
|
||||
result.append( (_('Agenda'), '/event/%s/agenda' % slug(event)))
|
||||
if event.blog_id:
|
||||
result.append( (_('News'), '/blogpost'+slug(event.blog_ig)))
|
||||
if event.show_track_proposal:
|
||||
result.append( (_('Talk Proposals'), '/event/%s/track_proposal' % slug(event)))
|
||||
@api.one
|
||||
def _get_new_menu_pages(self):
|
||||
result = super(event_event, self)._get_new_menu_pages()[0] # TDE CHECK api.one -> returns a list with one item ?
|
||||
if self.show_tracks:
|
||||
result.append((_('Talks'), '/event/%s/track' % slug(self)))
|
||||
result.append((_('Agenda'), '/event/%s/agenda' % slug(self)))
|
||||
if self.blog_id:
|
||||
result.append((_('News'), '/blogpost'+slug(self.blog_ig)))
|
||||
if self.show_track_proposal:
|
||||
result.append((_('Talk Proposals'), '/event/%s/track_proposal' % slug(self)))
|
||||
return result
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user