[IMP] moved snippet to content, Get country with help of GeoIP module
bzr revid: pga@tinyerp.com-20140228094148-e2nr13o9e9u0vkor
This commit is contained in:
parent
c40b4fe69b
commit
6a3a62d94c
|
@ -32,6 +32,7 @@ import time
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
import werkzeug.urls
|
import werkzeug.urls
|
||||||
|
import GeoIP
|
||||||
|
|
||||||
class website_event(http.Controller):
|
class website_event(http.Controller):
|
||||||
@http.route(['/event/', '/event/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
@http.route(['/event/', '/event/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||||
|
@ -205,23 +206,32 @@ class website_event(http.Controller):
|
||||||
event_id = Event.create(request.cr, request.uid, vals, context=context)
|
event_id = Event.create(request.cr, request.uid, vals, context=context)
|
||||||
return request.redirect("/event/%s/?enable_editor=1" % event_id)
|
return request.redirect("/event/%s/?enable_editor=1" % event_id)
|
||||||
|
|
||||||
@http.route('/event/get_country_event_list/<path:country_code>', type='http', auth='public', website=True)
|
def get_visitors_country(self):
|
||||||
def get_country_events(self,country_code ,**post):
|
GI = GeoIP.open('/usr/share/GeoIP/GeoIP.dat', 0)
|
||||||
cr, uid, context = request.cr, request.uid, request.context
|
return {'country_code': GI.country_code_by_addr(request.httprequest.remote_addr), 'country_name': GI.country_name_by_addr(request.httprequest.remote_addr)}
|
||||||
event_obj = request.registry['event.event']
|
|
||||||
event_ids = event_obj.search(request.cr, request.uid, [('country_id.code', '=', country_code),('state', '=', 'confirm'),('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00'))], order="date_begin", context=request.context)
|
def get_formated_date(self, event):
|
||||||
events = event_obj.browse(request.cr, request.uid, event_ids, context=request.context)
|
start_date = datetime.strptime(event.date_begin, "%Y-%m-%d %H:%M:%S").date()
|
||||||
|
end_date = datetime.strptime(event.date_end, "%Y-%m-%d %H:%M:%S").date()
|
||||||
|
return 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']
|
country_obj = request.registry['res.country']
|
||||||
country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context)
|
event_obj = request.registry['event.event']
|
||||||
country = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.context)
|
cr, uid, context,event_ids = request.cr, request.uid, request.context,[]
|
||||||
result = {'events':[], 'country': country}
|
country_code = self.get_visitors_country()['country_code']
|
||||||
for event in events:
|
result = {'events':[]}
|
||||||
start_date = datetime.strptime(event.date_begin.split(' ')[0], "%Y-%m-%d")
|
if country_code:
|
||||||
end_date = datetime.strptime(event.date_end.split(' ')[0], "%Y-%m-%d")
|
country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context)
|
||||||
if end_date == start_date:
|
result['country'] = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.context)
|
||||||
result['events'].append({"date": start_date.strftime("%b")+" "+start_date.strftime("%e"),
|
event_ids = event_obj.search(request.cr, request.uid, [('country_id.code', '=', country_code),('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00'))], order="date_begin", context=request.context)
|
||||||
"event": event, 'url': event.website_url})
|
if not event_ids:
|
||||||
else:
|
event_ids = event_obj.search(request.cr, request.uid, [('date_begin','>=', time.strftime('%Y-%m-%d 00:00:00'))], order="date_begin", context=request.context)
|
||||||
result['events'].append({"date":start_date.strftime("%b")+" "+start_date.strftime("%e")+"-"+end_date.strftime("%e"),
|
result['country'] = False
|
||||||
"event": event, 'url': event.website_url})
|
for event in event_obj.browse(request.cr, request.uid, event_ids, 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)
|
return request.website.render("website_event.country_events_list",result)
|
||||||
|
|
|
@ -1,33 +1,9 @@
|
||||||
(function() {
|
(function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
function getLocation()
|
function getLocation(){
|
||||||
{
|
$.post( "/event/get_country_event_list/", function( data ) {
|
||||||
if (navigator.geolocation)
|
if(data){
|
||||||
{
|
$( ".country_events_list" ).replaceWith( data );
|
||||||
navigator.geolocation.getCurrentPosition(showPosition);
|
|
||||||
}
|
|
||||||
else{alert("Geolocation is not supported by this browser.");}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPosition(position)
|
|
||||||
{
|
|
||||||
var latitude = position.coords.latitude;
|
|
||||||
var longitude = position.coords.longitude;
|
|
||||||
$.ajax({
|
|
||||||
url: "https://maps.googleapis.com/maps/api/geocode/json?latlng="+latitude+","+longitude+"&sensor=false",
|
|
||||||
type: 'GET',
|
|
||||||
dataType: 'json',
|
|
||||||
success: function(response, status, xhr, wfe){
|
|
||||||
if(response.status == 'OK'){
|
|
||||||
var last_element = response.results[response.results.length - 1]
|
|
||||||
if( last_element.types.indexOf( "country" ) != -1){
|
|
||||||
var country_obj = last_element.address_components[0];
|
|
||||||
$('img.event_country_flag').attr('src','base/static/img/country_flags/'+country_obj.short_name.toLowerCase()+'.png');
|
|
||||||
$.post( "/event/get_country_event_list/"+country_obj.short_name, function( data ) {
|
|
||||||
$( ".country_events_list" ).replaceWith( data );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,54 +338,71 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="country_events" name="Country Events" inherit_id="website.snippets">
|
<template id="country_events" name="Country Events" inherit_id="website.snippets">
|
||||||
<xpath expr="//div[@id='snippet_feature']" position="inside">
|
<xpath expr="//div[@id='snippet_content']" position="inside">
|
||||||
<div data-snippet-id="country_events" data-selector-children=".oe_structure, [data-oe-type=html]" class="country_events">
|
<div data-snippet-id="country_events" data-selector-siblings="p, h2, h3, blockquote" data-selector-children=".content">
|
||||||
<div class="oe_snippet_thumbnail">
|
<div class="oe_snippet_thumbnail">
|
||||||
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block-country_events.png" />
|
<img class="oe_snippet_thumbnail_img" src="/website/static/src/img/blocks/block-country_events.png" />
|
||||||
<span class="oe_snippet_thumbnail_title">Country Events</span>
|
<span class="oe_snippet_thumbnail_title">Country Events</span>
|
||||||
</div>
|
</div>
|
||||||
<section class="oe_snippet_body country_events">
|
<div class="oe_snippet_body country_events">
|
||||||
<div class="container">
|
<div class="country_events_list">
|
||||||
<div class="row">
|
<div class="text-muted text-center">
|
||||||
<div class="col-md-3">
|
<h1>
|
||||||
<div class="country_events_list">
|
<i class="fa fa-flag fa-5x"></i>
|
||||||
<div class="text-muted text-center">
|
</h1>
|
||||||
<h1><i class="fa fa-map-marker fa-5x"></i></h1>
|
<h1>Events from Your Country</h1>
|
||||||
<h3>Allow browser to use your Location.</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-5">
|
|
||||||
</div>
|
|
||||||
<div class="col-md-4">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</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 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="country_events_list" name="Country">
|
<template id="country_events_list" name="Country">
|
||||||
<t t-ignore="true">
|
<t t-ignore="true">
|
||||||
<div class="mb16 country_events_list">
|
<t t-if="events">
|
||||||
<img class="img-rounded img-responsive" t-att-src="'/website/image?model=res.country&field=image&id='+str(country.id)"></img>
|
<div class="mb16 country_events_list">
|
||||||
<t t-if="events">
|
<t t-if="country">
|
||||||
<h4><b>Events In <span t-esc="country.name"></span></b></h4>
|
<img class="img-rounded img-responsive" t-att-src="'/website/image?model=res.country&field=image&id='+str(country.id)"></img>
|
||||||
|
<h4><b>Events In <span t-esc="country.name"></span></b></h4>
|
||||||
|
</t>
|
||||||
|
<t t-if="not country">
|
||||||
|
<h4><b>Upcoming Events</b></h4>
|
||||||
|
</t>
|
||||||
<div t-foreach="events[:5]" t-as="country_event" class="oe_website_overflow_ellipsis mb8">
|
<div t-foreach="events[:5]" t-as="country_event" class="oe_website_overflow_ellipsis mb8">
|
||||||
<t t-if="not country_event['event'].website_published">
|
<t t-if="not country_event['event'].website_published">
|
||||||
<span class="label label-danger"><i class="fa fa-ban"></i></span>
|
<span class="label label-danger"><i class="fa fa-ban"></i></span>
|
||||||
</t>
|
</t>
|
||||||
<i class="fa fa-calendar"></i> <b><span t-esc="country_event['date']"/>: <span><a t-att-href="country_event['url']"><t t-esc="country_event['event'].name"/></a></span></b>
|
<i class="fa fa-calendar"></i> <b><span t-esc="country_event['date']"/>: <span><a t-att-href="country_event['url']"><t t-esc="country_event['event'].name"/></a></span></b>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
<t t-if="len(events) > 5">
|
||||||
<t t-if="len(events) > 5">
|
<div t-if="country" class="text-center">
|
||||||
<b class="text-center"><a t-att-href="'/event/?country='+str(country.id)">All events for <span t-esc="country.name"></span></a></b>
|
<b><a t-att-href="'/event/?country='+str(country.id)">See All events from <span t-esc="country.name"></span></a></b>
|
||||||
</t>
|
</div>
|
||||||
<t t-if="events == []">
|
<div t-if="not country" class="text-center">
|
||||||
<h4 ><b>No events available for <span t-esc="country.name"></span></b></h4>
|
<b><a t-att-href="'/event/"> See All Upcoming events </a></b>
|
||||||
</t>
|
</div>
|
||||||
</div>
|
</t>
|
||||||
|
</div>
|
||||||
|
</t>
|
||||||
</t>
|
</t>
|
||||||
</template>
|
</template>
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue