@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
from odoo import http , _
from odoo import http , _
from odoo.http import request
from odoo.http import request
from odoo.osv import expression
import logging
import logging
from odoo import models , fields , api
from odoo import models , fields , api
import werkzeug
import werkzeug
from werkzeug.datastructures import OrderedMultiDict
from datetime import datetime , timedelta
from datetime import datetime , timedelta
from odoo.tools import format_datetime , format_date , is_html_empty
from odoo.tools import format_datetime , format_date , is_html_empty
from dateutil.relativedelta import relativedelta
from dateutil.relativedelta import relativedelta
from odoo.exceptions import UserError
from odoo.exceptions import UserError
from collections import defaultdict
import babel
import babel
import babel.dates
import babel.dates
from odoo.addons.web.controllers.main import ensure_db , Home
from odoo.addons.web.controllers.main import ensure_db , Home
from odoo.addons.website_event.controllers.main import WebsiteEventController
from odoo.addons.website_event.controllers.main import WebsiteEventController
from odoo.addons.website.controllers.main import QueryURL
from odoo.addons.payment.controllers.portal import PaymentProcessing
from odoo.addons.payment.controllers.portal import PaymentProcessing
#from odoo.addons.sale.controllers.portal import CustomerPortal
#from odoo.addons.sale.controllers.portal import CustomerPortal
from odoo.addons.account.controllers.portal import CustomerPortal
from odoo.addons.account.controllers.portal import CustomerPortal
@ -156,7 +160,9 @@ class KalaAuthSignupHome(Home):
return response
return response
class kalachakra_event ( WebsiteEventController , PaymentProcessing ) :
class kalachakra_event ( WebsiteEventController , PaymentProcessing ) :
def sitemap_event ( env , rule , qs ) :
if not qs or qs . lower ( ) in ' /events ' :
yield { ' loc ' : ' /events ' }
#afficher la liste des prochains événement sur la home page (sans les retraites ! )
#afficher la liste des prochains événement sur la home page (sans les retraites ! )
@http.route ( ' /event/csv_booking_registrants ' , website = False , auth = ' user ' , methods = [ ' GET ' ] )
@http.route ( ' /event/csv_booking_registrants ' , website = False , auth = ' user ' , methods = [ ' GET ' ] )
def export_csv_booking_registrants ( self , id , * args , * * kw ) :
def export_csv_booking_registrants ( self , id , * args , * * kw ) :
@ -266,7 +272,157 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing):
tags = request . env [ ' event.tag ' ] . search ( [ ( ' name ' , ' = ' , searches [ ' tags ' ] ) ] )
tags = request . env [ ' event.tag ' ] . search ( [ ( ' name ' , ' = ' , searches [ ' tags ' ] ) ] )
return tags
return tags
@http.route ( [ ' /kalachakra/mediatheque/event ' ] , type = ' http ' , auth = " public " , website = True , sitemap = sitemap_event )
def kalachakraMediathequeEvent ( self , * * id ) :
id = id . get ( ' id ' )
event = request . env [ ' event.event ' ] . sudo ( ) . search ( [ ( ' id ' , ' = ' , int ( id ) ) ] )
data = { }
data [ ' event ' ] = event
return request . render ( " kalachakra.website_mediatheque_event " , data )
@http.route ( [ ' /kalachakra/mediatheque ' ] , type = ' http ' , auth = " public " , website = True , sitemap = sitemap_event )
def kalachakraMediatheque ( self , page = 1 , * * searches ) :
Event = request . env [ ' event.event ' ]
SudoEventType = request . env [ ' event.type ' ] . sudo ( )
searches . setdefault ( ' search ' , ' ' )
searches . setdefault ( ' date ' , ' all ' )
searches . setdefault ( ' tags ' , ' ' )
searches . setdefault ( ' type ' , ' all ' )
searches . setdefault ( ' country ' , ' all ' )
website = request . website
today = fields . Datetime . today ( )
def sdn ( date ) :
return fields . Datetime . to_string ( date . replace ( hour = 23 , minute = 59 , second = 59 ) )
def sd ( date ) :
return fields . Datetime . to_string ( date )
def get_month_filter_domain ( filter_name , months_delta ) :
first_day_of_the_month = today . replace ( day = 1 )
filter_string = _ ( ' This month ' ) if months_delta == 0 \
else format_date ( request . env , value = today + relativedelta ( months = months_delta ) ,
date_format = ' LLLL ' , lang_code = get_lang ( request . env ) . code ) . capitalize ( )
return [ filter_name , filter_string , [
( " date_end " , " >= " , sd ( first_day_of_the_month + relativedelta ( months = months_delta ) ) ) ,
( " date_begin " , " < " , sd ( first_day_of_the_month + relativedelta ( months = months_delta + 1 ) ) ) ] ,
0 ]
dates = [
[ ' all ' , _ ( ' Upcoming Events ' ) , [ ( " date_end " , " > " , sd ( today ) ) ] , 0 ] ,
[ ' today ' , _ ( ' Today ' ) , [
( " date_end " , " > " , sd ( today ) ) ,
( " date_begin " , " < " , sdn ( today ) ) ] ,
0 ] ,
get_month_filter_domain ( ' month ' , 0 ) ,
[ ' old ' , _ ( ' Past Events ' ) , [
( " date_end " , " < " , sd ( today ) ) ] ,
0 ] ,
]
# search domains
domain_search = { ' website_specific ' : website . website_domain ( ) }
if searches [ ' search ' ] :
domain_search [ ' search ' ] = [ ( ' name ' , ' ilike ' , searches [ ' search ' ] ) ]
search_tags = self . _extract_searched_event_tags ( searches )
if search_tags :
# Example: You filter on age: 10-12 and activity: football.
# Doing it this way allows to only get events who are tagged "age: 10-12" AND "activity: football".
# Add another tag "age: 12-15" to the search and it would fetch the ones who are tagged:
# ("age: 10-12" OR "age: 12-15") AND "activity: football
grouped_tags = defaultdict ( list )
for tag in search_tags :
grouped_tags [ tag . category_id ] . append ( tag )
domain_search [ ' tags ' ] = [ ]
for group in grouped_tags :
domain_search [ ' tags ' ] = expression . AND ( [ domain_search [ ' tags ' ] , [ ( ' tag_ids ' , ' in ' , [ tag . id for tag in grouped_tags [ group ] ] ) ] ] )
current_date = None
current_type = None
current_country = None
for date in dates :
if searches [ " date " ] == date [ 0 ] :
domain_search [ " date " ] = date [ 2 ]
if date [ 0 ] != ' all ' :
current_date = date [ 1 ]
if searches [ " type " ] != ' all ' :
current_type = SudoEventType . browse ( int ( searches [ ' type ' ] ) )
domain_search [ " type " ] = [ ( " event_type_id " , " = " , int ( searches [ " type " ] ) ) ]
if searches [ " country " ] != ' all ' and searches [ " country " ] != ' online ' :
current_country = request . env [ ' res.country ' ] . browse ( int ( searches [ ' country ' ] ) )
domain_search [ " country " ] = [ ' | ' , ( " country_id " , " = " , int ( searches [ " country " ] ) ) , ( " country_id " , " = " , False ) ]
elif searches [ " country " ] == ' online ' :
domain_search [ " country " ] = [ ( " country_id " , " = " , False ) ]
def dom_without ( without ) :
domain = [ ]
for key , search in domain_search . items ( ) :
if key != without :
domain + = search
return domain
# count by domains without self search
for date in dates :
if date [ 0 ] != ' old ' :
date [ 3 ] = Event . search_count ( dom_without ( ' date ' ) + date [ 2 ] )
domain = dom_without ( ' type ' )
domain = dom_without ( ' country ' )
countries = Event . read_group ( domain , [ " id " , " country_id " ] , groupby = " country_id " , orderby = " country_id " )
countries . insert ( 0 , {
' country_id_count ' : sum ( [ int ( country [ ' country_id_count ' ] ) for country in countries ] ) ,
' country_id ' : ( " all " , _ ( " All Countries " ) )
} )
step = 12 # Number of events per page
event_count = Event . search_count ( dom_without ( " none " ) )
pager = website . pager (
url = " /event " ,
url_args = searches ,
total = event_count ,
page = page ,
step = step ,
scope = 5 )
order = ' date_begin '
if searches . get ( ' date ' , ' all ' ) == ' old ' :
order = ' date_begin desc '
order = ' is_published desc, ' + order
events = Event . search ( dom_without ( " none " ) , limit = step , offset = pager [ ' offset ' ] , order = order )
keep = QueryURL ( ' /event ' , * * { key : value for key , value in searches . items ( ) if ( key == ' search ' or value != ' all ' ) } )
#search_tags=['enregistrement']
values = {
' current_date ' : current_date ,
' current_country ' : current_country ,
' current_type ' : current_type ,
' event_ids ' : events , # event_ids used in website_event_track so we keep name as it is
' dates ' : dates ,
' categories ' : request . env [ ' event.tag.category ' ] . search ( [ ] ) ,
' countries ' : countries ,
' pager ' : pager ,
' searches ' : searches ,
' search_tags ' : search_tags ,
' keep ' : keep ,
}
if searches [ ' date ' ] == ' old ' :
# the only way to display this content is to set date=old so it must be canonical
values [ ' canonical_params ' ] = OrderedMultiDict ( [ ( ' date ' , ' old ' ) ] )
return request . render ( " kalachakra.website_mediatheque " , values )
@http.route ( [ ' /notre-centre-de-retraite/presentation-du-centre ' ] , type = ' http ' , auth = ' public ' , website = True , sitemap = False , csrf = False )
@http.route ( [ ' /notre-centre-de-retraite/presentation-du-centre ' ] , type = ' http ' , auth = ' public ' , website = True , sitemap = False , csrf = False )
def kalachakracentreretraite ( self , * * post ) :
def kalachakracentreretraite ( self , * * post ) :