2013-11-24 18:54:34 +00:00
|
|
|
# -*- 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/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2014-01-30 17:51:53 +00:00
|
|
|
import openerp
|
2013-11-24 18:54:34 +00:00
|
|
|
from openerp.addons.web import http
|
|
|
|
from openerp.addons.web.http import request
|
|
|
|
from openerp.addons.website.controllers.main import Website as controllers
|
2014-03-07 08:52:48 +00:00
|
|
|
import datetime
|
2013-12-22 14:40:57 +00:00
|
|
|
|
2013-11-27 09:22:23 +00:00
|
|
|
import re
|
2013-12-22 14:40:57 +00:00
|
|
|
import werkzeug.utils
|
2013-11-24 18:54:34 +00:00
|
|
|
|
|
|
|
controllers = controllers()
|
2014-03-21 06:45:41 +00:00
|
|
|
import pytz
|
|
|
|
from pytz import timezone
|
2013-11-24 18:54:34 +00:00
|
|
|
|
|
|
|
class website_event(http.Controller):
|
2014-01-20 15:37:33 +00:00
|
|
|
@http.route(['/event/<model("event.event"):event>/track/<model("event.track"):track>'], type='http', auth="public", website=True, multilang=True)
|
2013-11-25 14:37:13 +00:00
|
|
|
def event_track_view(self, event, track, **post):
|
2014-01-30 22:51:52 +00:00
|
|
|
track_obj = request.registry.get('event.track')
|
|
|
|
track = track_obj.browse(request.cr, openerp.SUPERUSER_ID, track.id, context=request.context)
|
2013-12-16 11:22:11 +00:00
|
|
|
values = { 'track': track, 'event': track.event_id, 'main_object': track }
|
2013-11-24 22:38:02 +00:00
|
|
|
return request.website.render("website_event_track.track_view", values)
|
|
|
|
|
2014-04-09 17:26:00 +00:00
|
|
|
def _prepare_calendar(self, event, event_track_ids):
|
|
|
|
local_tz = pytz.timezone(event.timezone_of_event or 'UTC')
|
|
|
|
locations = {} # { location: [track, start_date, end_date, rowspan]}
|
|
|
|
dates = [] # [ (date, {}) ]
|
|
|
|
for track in event_track_ids:
|
|
|
|
locations.setdefault(track.location_id or False, [])
|
|
|
|
|
|
|
|
forcetr = True
|
|
|
|
for track in event_track_ids:
|
|
|
|
start_date = (datetime.datetime.strptime(track.date, '%Y-%m-%d %H:%M:%S')).replace(tzinfo=pytz.utc).astimezone(local_tz)
|
2014-04-09 18:43:34 +00:00
|
|
|
end_date = start_date + datetime.timedelta(hours = (track.duration or 30))
|
2014-04-09 17:26:00 +00:00
|
|
|
location = track.location_id or False
|
|
|
|
locations.setdefault(location, [])
|
|
|
|
|
|
|
|
# New TR, align all events
|
|
|
|
if forcetr or (start_date>dates[-1][0]) or not location:
|
|
|
|
dates.append((start_date, {}, bool(location)))
|
|
|
|
for loc in locations.keys():
|
|
|
|
if locations[loc] and (locations[loc][-1][2] > start_date):
|
|
|
|
locations[loc][-1][3] += 1
|
|
|
|
elif not locations[loc] or locations[loc][-1][2] < start_date:
|
|
|
|
locations[loc].append([False, locations[loc] and locations[loc][-1][2] or dates[0][0], start_date, 1])
|
|
|
|
dates[-1][1][loc] = locations[loc][-1]
|
|
|
|
forcetr = not bool(location)
|
|
|
|
|
|
|
|
# Add event
|
|
|
|
if locations[location] and locations[location][-1][1] > start_date:
|
|
|
|
locations[location][-1][3] -= 1
|
|
|
|
locations[location].append([track, start_date, end_date, 1])
|
|
|
|
dates[-1][1][location] = locations[location][-1]
|
|
|
|
return {
|
|
|
|
'locations': locations,
|
|
|
|
'dates': dates
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-30 16:33:21 +00:00
|
|
|
# TODO: not implemented
|
2014-03-14 16:23:46 +00:00
|
|
|
@http.route(['/event/<model("event.event"):event>/agenda'], type='http', auth="public", website=True, multilang=True)
|
2013-12-22 18:36:32 +00:00
|
|
|
def event_agenda(self, event, tag=None, **post):
|
2014-04-09 17:26:00 +00:00
|
|
|
comp = lambda x: (x.date, bool(x.location_id))
|
|
|
|
event.track_ids.sort(lambda x,y: cmp(comp(x), comp(y)))
|
|
|
|
|
|
|
|
days = {}
|
|
|
|
days_nbr = {}
|
|
|
|
for track in event.track_ids:
|
|
|
|
if not track.date: continue
|
|
|
|
days.setdefault(track.date[:10], [])
|
|
|
|
days[track.date[:10]].append(track)
|
|
|
|
|
|
|
|
for d in days:
|
|
|
|
days_nbr[d] = len(days[d])
|
|
|
|
days[d] = self._prepare_calendar(event, days[d])
|
|
|
|
|
|
|
|
return request.website.render("website_event_track.agenda", {
|
2013-12-22 18:36:32 +00:00
|
|
|
'event': event,
|
2014-04-09 17:26:00 +00:00
|
|
|
'days': days,
|
|
|
|
'days_nbr': days_nbr,
|
|
|
|
'tag': tag
|
|
|
|
})
|
2013-12-22 18:36:32 +00:00
|
|
|
|
2014-01-20 15:37:33 +00:00
|
|
|
@http.route([
|
2014-03-14 16:23:46 +00:00
|
|
|
'/event/<model("event.event"):event>/track',
|
2013-11-25 14:37:13 +00:00
|
|
|
'/event/<model("event.event"):event>/track/tag/<model("event.track.tag"):tag>'
|
2014-01-20 15:37:33 +00:00
|
|
|
], type='http', auth="public", website=True, multilang=True)
|
2013-11-25 16:24:18 +00:00
|
|
|
def event_tracks(self, event, tag=None, **post):
|
2013-11-27 09:22:23 +00:00
|
|
|
searches = {}
|
2013-11-25 14:37:13 +00:00
|
|
|
if tag:
|
2013-11-27 09:22:23 +00:00
|
|
|
searches.update(tag=tag.id)
|
2013-11-25 14:37:13 +00:00
|
|
|
track_obj = request.registry.get('event.track')
|
|
|
|
track_ids = track_obj.search(request.cr, request.uid,
|
|
|
|
[("id", "in", [track.id for track in event.track_ids]), ("tag_ids", "=", tag.id)], context=request.context)
|
|
|
|
tracks = track_obj.browse(request.cr, request.uid, track_ids, context=request.context)
|
|
|
|
else:
|
|
|
|
tracks = event.track_ids
|
2013-11-27 09:22:23 +00:00
|
|
|
|
|
|
|
def html2text(html):
|
|
|
|
return re.sub(r'<[^>]+>', "", html)
|
|
|
|
|
2013-11-24 18:54:34 +00:00
|
|
|
values = {
|
|
|
|
'event': event,
|
2013-12-16 11:02:34 +00:00
|
|
|
'main_object': event,
|
2013-11-25 14:37:13 +00:00
|
|
|
'tracks': tracks,
|
2013-11-27 09:22:23 +00:00
|
|
|
'tags': event.tracks_tag_ids,
|
|
|
|
'searches': searches,
|
|
|
|
'html2text': html2text
|
2013-11-24 18:54:34 +00:00
|
|
|
}
|
2013-11-24 22:38:02 +00:00
|
|
|
return request.website.render("website_event_track.tracks", values)
|
|
|
|
|
2014-03-14 16:23:46 +00:00
|
|
|
@http.route(['/event/<model("event.event"):event>/track_proposal'], type='http', auth="public", website=True, multilang=True)
|
2013-11-25 16:24:18 +00:00
|
|
|
def event_track_proposal(self, event, **post):
|
2013-12-16 11:22:11 +00:00
|
|
|
values = { 'event': event }
|
2013-11-24 18:54:34 +00:00
|
|
|
return request.website.render("website_event_track.event_track_proposal", values)
|
|
|
|
|
2014-01-20 15:37:33 +00:00
|
|
|
@http.route(['/event/<model("event.event"):event>/track_proposal/post'], type='http', auth="public", methods=['POST'], website=True, multilang=True)
|
2013-12-22 14:40:57 +00:00
|
|
|
def event_track_proposal_post(self, event, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
|
|
|
|
tobj = request.registry['event.track']
|
|
|
|
|
|
|
|
tags = []
|
|
|
|
for tag in event.allowed_track_tag_ids:
|
|
|
|
if post.get('tag_'+str(tag.id)):
|
|
|
|
tags.append(tag.id)
|
|
|
|
|
|
|
|
e = werkzeug.utils.escape
|
|
|
|
track_description = '''<section data-snippet-id="text-block">
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-12 text-center">
|
|
|
|
<h2>%s</h2>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
|
|
<p>%s</p>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-12">
|
|
|
|
<h3>About The Author</h3>
|
|
|
|
<p>%s</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>''' % (e(post['track_name']),
|
|
|
|
e(post['description']), e(post['biography']))
|
|
|
|
|
2014-01-30 17:51:53 +00:00
|
|
|
track_id = tobj.create(cr, openerp.SUPERUSER_ID, {
|
2013-12-22 14:40:57 +00:00
|
|
|
'name': post['track_name'],
|
|
|
|
'event_id': event.id,
|
|
|
|
'tag_ids': [(6, 0, tags)],
|
|
|
|
'user_id': False,
|
|
|
|
'description': track_description
|
|
|
|
}, context=context)
|
|
|
|
|
2014-01-30 17:51:53 +00:00
|
|
|
tobj.message_post(cr, openerp.SUPERUSER_ID, [track_id], body="""Proposed By: %s<br/>
|
2013-12-22 14:40:57 +00:00
|
|
|
Mail: <a href="mailto:%s">%s</a><br/>
|
|
|
|
Phone: %s""" % (e(post['partner_name']), e(post['email_from']),
|
|
|
|
e(post['email_from']), e(post['phone'])), context=context)
|
|
|
|
|
|
|
|
track = tobj.browse(cr, uid, track_id, context=context)
|
2014-01-30 16:51:11 +00:00
|
|
|
values = {'track': track, 'event':event}
|
2013-11-25 16:24:18 +00:00
|
|
|
return request.website.render("website_event_track.event_track_proposal_success", values)
|