[IMP] website_event: widget to promote Events with country flag

bzr revid: chm@openerp.com-20140327093517-8ppcxypc6krxc2fi
This commit is contained in:
chm@openerp.com 2014-03-27 10:35:17 +01:00
commit c1b6589851
6 changed files with 156 additions and 3 deletions

View File

@ -530,3 +530,9 @@ span[data-oe-type="monetary"] {
width: 400px;
margin: 40px auto;
}
.oe_website_overflow_ellipsis{
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
}

View File

@ -429,3 +429,9 @@ span[data-oe-type="monetary"]
.oe_website_login_container
width: 400px
margin: 40px auto
.oe_website_overflow_ellipsis
white-space:nowrap
overflow:hidden
text-overflow:ellipsis

View File

@ -28,9 +28,11 @@ controllers = controllers()
from datetime import datetime, timedelta
import time
from dateutil.relativedelta import relativedelta
from openerp import tools
import werkzeug.urls
import GeoIP
class website_event(http.Controller):
@http.route(['/event', '/event/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
@ -203,3 +205,33 @@ class website_event(http.Controller):
}
event_id = Event.create(request.cr, request.uid, vals, context=context)
return request.redirect("/event/%s?enable_editor=1" % event_id)
def get_visitors_country(self):
GI = GeoIP.open('/usr/share/GeoIP/GeoIP.dat', 0)
return {'country_code': GI.country_code_by_addr(request.httprequest.remote_addr), 'country_name': GI.country_name_by_addr(request.httprequest.remote_addr)}
def get_formated_date(self, event):
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):
country_obj = request.registry['res.country']
event_obj = request.registry['event.event']
cr, uid, context,event_ids = request.cr, request.uid, request.context,[]
country_code = self.get_visitors_country()['country_code']
result = {'events':[],'country':False}
if country_code:
country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context)
event_ids = event_obj.search(request.cr, request.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=request.context)
if not event_ids:
event_ids = event_obj.search(request.cr, request.uid, [('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00')),('state', '=', 'confirm')], order="date_begin", context=request.context)
for event in event_obj.browse(request.cr, request.uid, event_ids, context=request.context)[:6]:
if country_code and event.country_id.code == country_code:
result['country'] = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -0,0 +1,16 @@
(function() {
"use strict";
var website = openerp.website;
website.snippet.animationRegistry.visitor = website.snippet.Animation.extend({
selector: ".oe_country_events",
start: function () {
var self = this;
$.post( "/event/get_country_event_list", function( data ) {
if(data){
$( ".country_events_list" ).replaceWith( data );
}
});
}
});
})();

View File

@ -117,6 +117,23 @@
</xpath>
</template>
<template id="event_right_country_event" inherit_option_id="website_event.index" name="Country Events">
<xpath expr="//div[@id='right_column']" position="inside">
<div class="row">
<div class="col-md-12 mb16 mt16 country_events">
<div class="country_events_list">
<div class="text-muted text-center">
<h1>
<i class="fa fa-flag fa-5x"></i>
</h1>
<h1>Events from Your Country</h1>
</div>
</div>
</div>
</div>
</xpath>
</template>
<template id="event_left_column" inherit_option_id="website_event.index" inherit_id="website_event.index" name="Filters">
<xpath expr="//div[@id='middle_column']" position="attributes">
<attribute name="class">col-md-6</attribute>
@ -126,7 +143,7 @@
<ul class="nav nav-pills nav-stacked">
<t t-foreach="dates" t-as="date">
<li t-att-class="searches.get('date') == date[0] and 'active' or ''" t-if="date[3] or (date[0] in ('old','all'))">
<a t-attf-href="/event/?{{ keep_query('country', 'type', date=date[0]) }}"><t t-esc="date[1]"/>
<a t-attf-href="/event?{{ keep_query('country', 'type', date=date[0]) }}"><t t-esc="date[1]"/>
<span t-if="date[3]" class="badge pull-right"><t t-esc="date[3]"/></span>
</a>
</li>
@ -141,7 +158,7 @@
<ul class="nav nav-pills nav-stacked mt32">
<t t-foreach="types">
<li t-if="type" t-att-class="searches.get('type') == str(type and type[0]) and 'active' or ''">
<a t-attf-href="/event/?{{ keep_query('country', 'date', type=type[0]) }}"><t t-esc="type[1]"/>
<a t-attf-href="/event?{{ keep_query('country', 'date', type=type[0]) }}"><t t-esc="type[1]"/>
<span class="badge pull-right"><t t-esc="type_count"/></span>
</a>
</li>
@ -155,7 +172,7 @@
<ul class="nav nav-pills nav-stacked mt32">
<t t-foreach="countries">
<li t-if="country_id" t-att-class="searches.get('country') == str(country_id and country_id[0]) and 'active' or ''">
<a t-attf-href="/event/?{{ keep_query('type', 'data', country=country_id[0]) }}"><t t-esc="country_id[1]"/>
<a t-attf-href="/event?{{ keep_query('type', 'data', country=country_id[0]) }}"><t t-esc="country_id[1]"/>
<span class="badge pull-right"><t t-esc="country_id_count"/></span>
</a>
</li>
@ -335,5 +352,81 @@
</div>
</t>
</template>
<template id="event_script" name="Country Events Snippet Script" inherit_id="website.layout">
<xpath expr="//head" position="inside">
<script type="text/javascript" src="/website_event/static/src/js/website_geolocation.js"></script>
</xpath>
</template>
<template id="country_events" name="Country Events" inherit_id="website.snippets">
<xpath expr="//div[@id='snippet_content']" position="inside">
<div>
<div class="oe_snippet_thumbnail">
<div style="background: white;box-shadow:none;-webkit-box-shadow:none;" class="oe_snippet_thumbnail_img" >
<i class="fa fa-flag fa-5x text-muted"></i>
</div>
<span class="oe_snippet_thumbnail_title">Local Events</span>
</div>
<div class="oe_snippet_body oe_country_events mb16 mt16">
<div class="country_events_list">
<div class="text-muted text-left">
<div>
<img style="max-height:10em;" class="img-rounded img-responsive" src="/website_event/static/src/img/world_map.jpg"></img>
</div>
<div>Events in visitor's country</div>
</div>
</div>
</div>
</div>
</xpath>
<xpath expr="//div[@id='snippet_options']" position="inside">
<div data-snippet-option-id='content'
data-selector=".oe_country_events"
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel"
data-selector-children=".content"
>
</div>
</xpath>
</template>
<template id="country_events_list" name="Country">
<t t-ignore="true">
<t t-if="events">
<div class="country_events_list">
<div>
<t t-if="country">
<img style="max-height:10em;" class="img-rounded img-responsive" t-att-src="'/website/image?model=res.country&amp;field=image&amp;id='+str(country.id)"></img>
<h4><b>Events in <span t-esc="country.name"></span></b></h4>
</t>
<t t-if="not country">
<img style="max-height:10em;" class="img-rounded img-responsive" src="/website_event/static/src/img/world_map.jpg"></img>
<h4><b>Upcoming Events</b></h4>
</t>
<div t-foreach="events[:5]" t-as="event_dict" class="oe_website_overflow_ellipsis mb8">
<t t-if="not event_dict['event'].website_published">
<span class="label label-danger"><i class="fa fa-ban"></i></span>
</t>
<t t-if="event_dict['event'].address_id">
<i class="fa fa-map-marker"></i>
</t>
<t t-if="not event_dict['event'].address_id">
<i class="fa fa-cloud"></i>
</t>
<b><span t-esc="event_dict['date']"/>: <span><a t-att-href="event_dict['url']"><t t-esc="event_dict['event'].name"/></a></span></b>
</div>
<t t-if="len(events) > 5">
<div t-if="country">
<b><a t-att-href="'/event?country='+str(country.id)">See all events from <span t-esc="country.name"></span></a></b>
</div>
<div t-if="not country">
<b><a href="/event"> See all upcoming events </a></b>
</div>
</t>
</div>
</div>
</t>
</t>
</template>
</data>
</openerp>