[ADD] added snippet for country event, script for finding coordinates from brwoser, And display events from users country

bzr revid: pga@tinyerp.com-20140226113121-vni0182v0cc2u3d4
This commit is contained in:
Parth Gajjar (Open ERP) 2014-02-26 17:01:21 +05:30
parent 2ab61cf001
commit d4e7b18a55
6 changed files with 132 additions and 0 deletions

View File

@ -529,3 +529,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

@ -428,3 +428,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

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

View File

@ -28,6 +28,7 @@ controllers = controllers()
from datetime import datetime, timedelta
import time
from dateutil.relativedelta import relativedelta
from openerp import tools
import werkzeug.urls
@ -215,3 +216,24 @@ 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)
@http.route('/event/get_country_event_list/<path:country_code>', type='http', auth='public', website=True)
def get_country_events(self,country_code ,**post):
cr, uid, context = request.cr, request.uid, request.context
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)
events = event_obj.browse(request.cr, request.uid, event_ids, context=request.context)
country_obj = request.registry['res.country']
country_ids = country_obj.search(request.cr, request.uid, [('code', '=', country_code)], context=request.context)
country = country_obj.browse(request.cr, request.uid, country_ids[0], context=request.context)
result = {'events':[], 'country': country}
for event in events:
start_date = datetime.strptime(event.date_begin.split(' ')[0], "%Y-%m-%d")
end_date = datetime.strptime(event.date_end.split(' ')[0], "%Y-%m-%d")
if end_date == start_date:
result['events'].append({"date": start_date.strftime("%b")+" "+start_date.strftime("%e"),
"event": event, 'url': event.website_url})
else:
result['events'].append({"date":start_date.strftime("%b")+" "+start_date.strftime("%e")+"-"+end_date.strftime("%e"),
"event": event, 'url': event.website_url})
return request.website.render("website_event.country_events_list",result)

View File

@ -0,0 +1,40 @@
(function() {
"use strict";
function getLocation()
{
if (navigator.geolocation)
{
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 );
});
}
}
}
});
}
$(document).ready(function () {
if($('.country_events').length){
getLocation();
}
});
})();

View File

@ -336,5 +336,63 @@
</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_feature']" position="inside">
<div data-snippet-id="country_events" data-selector-children=".oe_structure, [data-oe-type=html]" class="country_events">
<div class="oe_snippet_thumbnail">
<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>
</div>
<section class="oe_snippet_body country_events">
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="country_events_list">
<div class="text-muted text-center">
<h1><i class="fa fa-map-marker fa-5x"></i></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>
</section>
</div>
</xpath>
</template>
<template id="country_events_list" name="Country">
<t t-ignore="true">
<div class="mb16 country_events_list">
<img class="img-rounded img-responsive" t-att-src="'/website/image?model=res.country&amp;field=image&amp;id='+str(country.id)"></img>
<t t-if="events">
<h4><b>Events In <span t-esc="country.name"></span></b></h4>
<div t-foreach="events[:5]" t-as="country_event" class="oe_website_overflow_ellipsis mb8">
<t t-if="not country_event['event'].website_published">
<span class="label label-danger"><i class="fa fa-ban"></i></span>
</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>
</div>
</t>
<t t-if="len(events) > 5">
<b class="text-center"><a t-att-href="'/event/?country='+str(country.id)">All events for <span t-esc="country.name"></span></a></b>
</t>
<t t-if="events == []">
<h4 ><b>No events available for <span t-esc="country.name"></span></b></h4>
</t>
</div>
</t>
</template>
</data>
</openerp>