diff options
| author | Thibault Delavallée <tde@openerp.com> | 2014-10-03 11:57:02 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2014-10-03 14:00:28 +0200 |
| commit | 9353c101deee8964f5e19298aa271d9656a7d2b8 (patch) | |
| tree | 9021feee35dded61311310663b7a2a214e5e8a4b /addons/website_event/controllers/main.py | |
| parent | 85dda405e87d3adb99c2dfa057180a1929fa7d6c (diff) | |
[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.
Diffstat (limited to 'addons/website_event/controllers/main.py')
| -rw-r--r-- | addons/website_event/controllers/main.py | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py index 6d0a0dfa74b..da343c9fa3b 100644 --- a/addons/website_event/controllers/main.py +++ b/addons/website_event/controllers/main.py @@ -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) |
