[MERGE] from upstream

bzr revid: fva@openerp.com-20130806123005-7mup0zq6ua4d8g3r
This commit is contained in:
Frédéric van der Essen 2013-08-06 14:30:05 +02:00
commit 9cba9de9fd
15 changed files with 454 additions and 296 deletions

View File

@ -211,7 +211,7 @@ class event_event(osv.osv):
'city': fields.related('address_id','city',type='char',string='city'),
'speaker_confirmed': fields.boolean('Speaker Confirmed', readonly=False, states={'done': [('readonly', True)]}),
'country_id': fields.related('address_id', 'country_id',
type='many2one', relation='res.country', string='Country', readonly=False, states={'done': [('readonly', True)]}),
type='many2one', relation='res.country', string='Country', readonly=False, states={'done': [('readonly', True)]}, store=True),
'note': fields.text('Description', readonly=False, states={'done': [('readonly', True)]}),
'company_id': fields.many2one('res.company', 'Company', required=False, change_default=True, readonly=False, states={'done': [('readonly', True)]}),
'is_subscribed' : fields.function(_subscribe_fnc, type="boolean", string='Subscribed'),

View File

@ -17,30 +17,6 @@ import werkzeug.wrappers
logger = logging.getLogger(__name__)
def template_values():
script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in manifest_list('js', db=request.db)])
css = "\n".join('<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db))
try:
request.session.check_security()
loggued = True
uid = request.session._uid
except http.SessionExpiredException:
loggued = False
uid = openerp.SUPERUSER_ID
values = {
'loggued': loggued,
'editable': loggued,
'request': request,
'registry': request.registry,
'cr': request.cr,
'uid': uid,
'script': script,
'css': css,
'host_url': request.httprequest.host_url,
}
return values
class Website(openerp.addons.web.controllers.main.Home):
@http.route('/', type='http', auth="admin")
def index(self, **kw):
@ -52,13 +28,11 @@ class Website(openerp.addons.web.controllers.main.Home):
@http.route('/pagenew/<path:path>', type='http', auth="admin")
def pagenew(self, path):
values = template_values()
uid = values['uid']
imd = request.registry['ir.model.data']
view = request.registry['ir.ui.view']
view_model, view_id = imd.get_object_reference(request.cr, uid, 'website', 'default_page')
newview_id = view.copy(request.cr, uid, view_id)
newview = view.browse(request.cr, uid, newview_id, context={})
view_model, view_id = imd.get_object_reference(request.cr, request.uid, 'website', 'default_page')
newview_id = view.copy(request.cr, request.uid, view_id)
newview = view.browse(request.cr, request.uid, newview_id, context={})
newview.write({
'arch': newview.arch.replace("website.default_page", path),
'name': "page/%s" % path
@ -68,7 +42,7 @@ class Website(openerp.addons.web.controllers.main.Home):
else:
module = False
idname = path
imd.create(request.cr, uid, {
imd.create(request.cr, request.uid, {
'name': idname,
'module': module,
'model': 'ir.ui.view',
@ -79,29 +53,14 @@ class Website(openerp.addons.web.controllers.main.Home):
@http.route('/page/<path:path>', type='http', auth="admin")
def page(self, path):
#def get_html_head():
# head += ['<link rel="stylesheet" href="%s">' % i for i in manifest_list('css', db=request.db)]
#modules = request.registry.get("ir.module.module").search_read(request.cr, openerp.SUPERUSER_ID, fields=['id', 'shortdesc', 'summary', 'icon_image'], limit=50)
values = template_values()
uid = values['uid']
context = {
'inherit_branding': values['editable'],
}
company = request.registry['res.company'].browse(request.cr, uid, 1, context=context)
values.update(
res_company=company,
path=path,
google_map_url="http://maps.googleapis.com/maps/api/staticmap?" + urllib.urlencode({
'center': '%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''),
'sensor': 'false',
'zoom': '8',
'size': '298x298',
}),
)
website = request.registry.get("website")
values = website.get_rendering_context({
'path': path
})
try:
html = request.registry.get("ir.ui.view").render(request.cr, uid, path, values, context)
except ValueError, e:
html = request.registry.get("ir.ui.view").render(request.cr, uid, 'website.404', values, context)
html = website.render(path, values)
except ValueError:
html = website.render('website.404', values)
return html
@http.route('/website/attach', type='http', auth='admin') # FIXME: auth

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import openerp
from openerp.osv import osv
from openerp.addons.web import http
from openerp.addons.web.controllers import main
from openerp.addons.web.http import request
@ -18,22 +19,36 @@ def auth_method_public():
http.auth_methods['public'] = auth_method_public
class website(object):
def render(self, template, add_values={}):
class website(osv.osv):
_name = "website" # Avoid website.website convention for conciseness (for new api). Got a special authorization from xmo and rco
_description = "Website"
def get_rendering_context(self, additional_values=None):
debug = 'debug' in request.params
script = "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in main.manifest_list('js', db=request.db, debug=debug)])
css = "\n".join('<link rel="stylesheet" href="%s">' % i for i in main.manifest_list('css', db=request.db, debug=debug))
_values = {
'editable': request.uid != request.public_uid,
editable = False
if request.uid or (request.public_uid and request.uid != request.public_uid):
editable = True
values = {
'debug': debug,
'editable': editable,
'request': request,
'registry': request.registry,
'cr': request.cr,
'uid': request.uid,
'script': script,
'css': css,
'host_url': request.httprequest.host_url,
'res_company': request.registry['res.company'].browse(request.cr, openerp.SUPERUSER_ID, 1),
}
_values.update(add_values)
return request.registry.get("ir.ui.view").render(request.cr, request.uid, template, _values)
website = website()
if editable:
values.update({
'script': "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in main.manifest_list('js', db=request.db, debug=debug)]),
'css': "\n".join('<link rel="stylesheet" href="%s">' % i for i in main.manifest_list('css', db=request.db, debug=debug))
})
if additional_values:
values.update(additional_values)
return values
def render(self, template, values={}):
# context = {
# 'inherit_branding': values['editable'],
# }
return request.registry.get("ir.ui.view").render(request.cr, request.uid, template, values)

View File

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
import openerp
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website.controllers.main import template_values
from urllib import quote_plus
@ -11,16 +9,14 @@ class contactus(http.Controller):
@http.route(['/crm/contactus'], type='http', auth="admin")
def contactus(self, *arg, **post):
website = request.registry['website']
post['user_id'] = False
request.registry['crm.lead'].create(request.cr, request.uid, post)
values = template_values()
company = request.registry['res.company'].browse(request.cr, request.uid, 1)
values = website.get_rendering_context()
company = values['res_company']
values.update({
'res_company': company,
'google_map_url': "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=8&size=298x298" % quote_plus('%s, %s %s, %s' % (company.street, company.city, company.zip, company.country_id and company.country_id.name_get()[0][1] or ''))
})
html = request.registry.get("ir.ui.view").render(request.cr, request.uid, "website_crm.thanks", values)
return html
return website.render("website_crm.thanks", values)
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -8,7 +8,7 @@ OpenERP Blog
""",
'author': 'OpenERP SA',
'depends': ['website', 'event'],
'depends': ['website', 'event', 'website_sale'],
'data': [
'views/website_event.xml',
'security/ir.model.access.csv',

View File

@ -1,22 +1,29 @@
# -*- coding: utf-8 -*-
from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website import website
from openerp.tools.translate import _
from datetime import datetime
from dateutil.relativedelta import relativedelta
from openerp import tools
import urllib
import werkzeug
class website_hr(http.Controller):
class website_event(http.Controller):
@http.route(['/event'], type='http', auth="public")
def events(self, **searches):
data_obj = request.registry['event.event']
website = request.registry['website']
event_obj = request.registry['event.event']
searches.setdefault('date', 'all')
searches.setdefault('type', 'all')
searches.setdefault('country', 'all')
domain_search = {}
def sd(date):
return date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)
@ -45,44 +52,67 @@ class website_hr(http.Controller):
0],
]
domain_search = {
'date': 'all'
}
# search domains
for date in dates:
if searches.get("date") == date[0]:
domain_search["date"] = date[2]
if searches.get("type", "all") != 'all':
domain_search["type"] = [("type", "=", int(searches.get("type")))]
if searches.get("country", "all") != 'all':
domain_search["country"] = [("country_id", "=", int(searches.get("country")))]
def dom_without(without):
domain = [(1, "=", 1)]
for key, search in domain_search.items():
if key != without:
domain += search
print domain
return domain
# count by domains without self search
domain = [(1, "=", 1)]
for key, search in domain_search.items():
if key != 'date':
domain += search
for date in dates:
date[3] = data_obj.search(request.cr, request.uid, domain + date[2], count=True)
date[3] = event_obj.search(request.cr, request.uid, dom_without('date') + date[2], count=True)
domain = dom_without('type')
types = event_obj.read_group(request.cr, request.uid, domain, ["id", "type"], groupby="type", orderby="type")
types.insert(0, {'type_count': event_obj.search(request.cr, request.uid, domain, count=True), 'type': ("all", _("All Categories"))})
domain = dom_without('country')
countries = event_obj.read_group(request.cr, request.uid, domain, ["id", "country_id"], groupby="country_id", orderby="country_id")
countries.insert(0, {'country_id_count': event_obj.search(request.cr, request.uid, domain, count=True), 'country_id': ("all", _("All Countries"))})
# domain and search_path
domain = [(1, "=", 1)]
for key, search in domain_search.items():
domain += search
obj_ids = data_obj.search(request.cr, request.uid, domain)
values = {
'event_ids': data_obj.browse(request.cr, request.uid, obj_ids),
obj_ids = event_obj.search(request.cr, request.uid, dom_without("none"), order="date_begin DESC")
values = website.get_rendering_context({
'event_ids': event_obj.browse(request.cr, request.uid, obj_ids),
'dates': dates,
'types': types,
'countries': countries,
'searches': searches,
'search_path': "?%s" % urllib.urlencode(searches),
}
})
html = website.render("website_event.index", values)
return html
return website.render("website_event.index", values)
@http.route(['/event/<int:event_id>'], type='http', auth="public")
def event(self, event_id=None, **post):
return ""
website = request.registry['website']
event = request.registry['event.event'].browse(request.cr, request.uid, event_id)
organizer = event.user_id and request.registry['res.users'].browse(request.cr, SUPERUSER_ID, event.user_id.id) or None
values = website.get_rendering_context({
'event_id': event,
'organizer': organizer,
'google_map_url': "http://maps.googleapis.com/maps/api/staticmap?center=%s&sensor=false&zoom=12&size=298x298" % urllib.quote_plus('%s, %s %s, %s' % (event.street, event.city, event.zip, event.country_id and event.country_id.name_get()[0][1] or ''))
})
return website.render("website_event.detail", values)
@http.route(['/event/<int:event_id>/add_cart'], type='http', auth="public")
def add_cart(self, event_id=None, **post):
if not post:
return werkzeug.utils.redirect("/event/%s/" % event_id)
return werkzeug.utils.redirect("/shop/checkout")
@http.route(['/event/publish'], type='http', auth="public")
def publish(self, **post):

View File

@ -7,5 +7,17 @@ class event(osv.osv):
_inherit = 'event.event'
_columns = {
'website_published': fields.boolean('Available in the website'),
'description_website': fields.html('Description for the website'),
'product_ids': fields.one2many('event.event.product', "event_id", "Event"),
}
class event_product(osv.osv):
_name = 'event.event.product'
_columns = {
'event_id': fields.many2one('event.event', "Event"),
'product_id': fields.many2one('product.product', 'Product'),
'price': fields.float('Price'),
'qty': fields.integer('Current Registrations', readonly=True),
'max_qty': fields.integer('Maximum Registrations'),
}

View File

@ -2,6 +2,29 @@
<openerp>
<data>
<record id="view_event_form" model="ir.ui.view">
<field name="name">view_event_form</field>
<field name="model">event.event</field>
<field name="inherit_id" ref="event.view_event_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//notebook" position="inside">
<page string="Tarifs">
<group colspan="4">
<field name="product_ids">
<tree string="Payments" editable="top">
<field name="product_id"/>
<field name="price"/>
<field name="max_qty"/>
</tree>
</field>
</group>
</page>
</xpath>
</data>
</field>
</record>
<!-- Layout add nav and footer -->
<record id="header_website_event" model="ir.ui.view">
@ -28,7 +51,7 @@
</record>
<!-- Page -->
<template id="index">
<t t-call="website.layout">
<t t-set="head">
@ -49,83 +72,127 @@
</ul>
<ul class="nav nav-list">
<li class="nav-header">Category</li>
<li class="active">
<a >All Categories <span>(27)</span></a>
</li>
<li>
<a >Conferences <span>(18)</span></a>
</li>
<li>
<a >Business <span>(18)</span></a>
</li>
<li>
<a>Classes <span>(9)</span></a>
</li>
<t t-foreach="types">
<li t-if="type" t-att-class="searches.get('type') == str(type[0]) and 'active' or ''">
<a t-att-href="'/event/%%s&amp;type=%%s' %% (search_path, type[0])"><t t-esc="type[1]"/> <small>(<t t-esc="type_count"/>)</small></a>
</li>
</t>
</ul>
<ul class="nav nav-list">
<li class="nav-header">Location</li>
<li>
<a>Ramillies <span>(7)</span></a>
</li>
<li>
<a>Eindhoven <span>(6)</span></a>
</li>
<li>
<a>Hasselt <span>(6)</span></a>
</li>
<li>
<a>Herentals <span>(6)</span></a>
</li>
<li>
<a>Geel <span>(2)</span></a>
</li>
<t t-foreach="countries">
<li t-if="country_id" t-att-class="searches.get('country') == str(country_id[0]) and 'active' or ''">
<a t-att-href="'/event/%%s&amp;country=%%s' %% (search_path, country_id[0])"><t t-esc="country_id[1]"/><small>(<t t-esc="country_id_count"/>)</small></a>
</li>
</t>
</ul>
</div>
<div class="span8">
<ul class="media-list mt32">
<t t-foreach="event_ids" t-as="event_id">
<li class="media thumbnail">
<div class="media-body">
<t t-if="event_id.register_avail">
<t t-if="event_id.register_avail == 9999">
<span class="label pull-right">No ticket available.</span>
</t>
<span t-if="event_id.register_avail != 9999" t-att-class="'label pull-right label-%%s' %% (event_id.register_avail &lt;= 10 and 'warning' or 'info')">
<t t-if="event_id.register_avail &lt;= 10">Only</t>
<t t-esc="event_id.register_avail"/>
<t t-if="event_id.register_avail &gt; 1">tickets </t>
<t t-if="event_id.register_avail == 1">ticket </t>
available.
</span>
<li t-foreach="event_ids" t-as="event_id" class="media thumbnail">
<div class="media-body">
<t t-if="event_id.register_avail">
<span t-if="event_id.register_avail == 9999" class="label pull-right">No ticket available.</span>
<span t-if="event_id.register_avail != 9999" t-att-class="'label pull-right label-%%s' %% (event_id.register_avail &lt;= 10 and 'warning' or 'info')">
<t t-if="event_id.register_avail &lt;= 10">Only</t>
<t t-esc="event_id.register_avail"/>
<t t-if="event_id.register_avail &gt; 1">tickets </t>
<t t-if="event_id.register_avail == 1">ticket </t>
available.
</span>
</t>
<h4 class="media-heading"><a t-att-href="'/event/%%s/' %% event_id.id"><span t-field="event_id.name"> </span></a></h4>
<a t-if="editable" href="#" t-att-data-id="event_id.id" class="pull-right">
<span t-att-class="'label label-success js_unpublish %%s' %% (not event_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (event_id.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<div>
<span t-field="event_id.type">: </span>
<t t-if="event_id.user_id">
Organized by: <span t-field="event_id.user_id"> </span>
</t>
<h4 class="media-heading"><a t-att-href="'event/%%s' %% event_id.id"><span t-field="event_id.name"> </span></a></h4>
<t t-if="editable">
<a href="#" t-att-data-id="event_id.id" class="pull-right">
<span t-att-class="'label label-success js_unpublish %%s' %% (not event_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (event_id.website_published and 'hidden' or '')">Click to Publish</span>
</a>
</t>
<div>
<span t-field="event_id.type">: </span>
<t t-if="event_id.user_id">
Organized by: <span t-field="event_id.user_id"> </span>
</t>
</div>
<div>
<i class="icon-time"></i> <span t-field="event_id.date_begin"> </span> <i>to</i> <span t-field="event_id.date_end"> </span>
</div>
<div t-if="event_id.country_id">
<i class="icon-map-marker"></i> <span t-field="event_id.city"> </span> <span t-field="event_id.zip"> </span>, <span t-field="event_id.country_id"> </span>
</div>
<div t-field="event_id.note"> </div>
</div>
</li>
</t>
<div>
<i class="icon-time"></i> <span t-field="event_id.date_begin"> </span> <i>to</i> <span t-field="event_id.date_end"> </span>
</div>
<div t-if="event_id.country_id">
<i class="icon-map-marker"></i> <span t-field="event_id.city"> </span> <span t-field="event_id.zip"> </span>, <span t-field="event_id.country_id"> </span>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</t>
</template>
<template id="detail">
<t t-call="website.layout">
<t t-set="head">
<script type="text/javascript" src="/website_event/static/src/js/website_event.js"></script>
<t t-raw="head"/>
</t>
<t t-set="title">Events</t>
<div class="container mt48">
<div class="row">
<div class="span4 css_noprint">
<h4>When &amp; Where</h4>
<img t-att-src="google_map_url"/>
<address>
<h4 t-field="event_id.address_id">Name</h4><br/>
<span t-field="event_id.street"/><br/>
<span t-field="event_id.city"/>, <span t-field="event_id.zip"/><br/>
<span t-field="event_id.country_id"> </span><br/>
<i class="icon-time"></i> <span t-field="event_id.date_begin"> </span><br/>
<i class="icon-time"></i> <span t-field="event_id.date_end"> </span><br/>
<br/>
<t t-if="event_id.user_id">
Organized by: <span t-field="event_id.user_id"/><br/>
<span>&amp;#x2706; <span t-field="organizer.phone"></span></span><br/>
<i class="icon-envelope"></i> <span t-field="organizer.email"></span>
</t>
</address>
</div>
<div class="span8">
<div class="media-body">
<t t-if="event_id.register_avail">
<span t-if="event_id.register_avail == 9999" class="label pull-right">No ticket available.</span>
<span t-if="event_id.register_avail != 9999" t-att-class="'label pull-right label-%%s' %% (event_id.register_avail &lt;= 10 and 'warning' or 'info')">
<t t-if="event_id.register_avail &lt;= 10">Only</t>
<t t-esc="event_id.register_avail"/>
<t t-if="event_id.register_avail &gt; 1">tickets </t>
<t t-if="event_id.register_avail == 1">ticket </t>
available.
</span>
</t>
<h4 class="media-heading"><a t-att-href="'/event/%%s/' %% event_id.id"><span t-field="event_id.name"> </span></a></h4>
<a t-if="editable" href="#" t-att-data-id="event_id.id" class="pull-right">
<span t-att-class="'label label-success js_unpublish %%s' %% (not event_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (event_id.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<h4 t-if="event_id.product_ids">Ticket Information</h4>
<form t-att-action="'/event/%%s/add_cart' %% event_id.id" method="post" t-if="event_id.product_ids">
<div t-foreach="event_id.product_ids" t-as="prod">
<span t-field="prod.product_id"/>
<span t-field="prod.price"/>
<span t-field="prod.qty"/>
<span t-field="prod.max_qty"/>
<select t-att-name="'product[%%s]' %% prod.id">
<t t-foreach="range(0,10)" t-as="nb">
<option t-esc="nb"/>
</t>
</select>
</div>
<button type="submit" class="btn btn-primary">Order Now</button>
</form>
<h4>Event Details</h4>
<div t-field="event_id.description_website"></div>
</div>
</div>
</div>
</div>
</t>
</template>
</data>
</openerp>

View File

@ -2,21 +2,18 @@
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website import website
class website_hr(http.Controller):
@http.route(['/hr'], type='http', auth="public")
def blog(self, **post):
website = request.registry['website']
hr_obj = request.registry['hr.employee']
employee_ids = hr_obj.search(request.cr, request.uid, [(1, "=", 1)])
values = {
'employee_ids': hr_obj.browse(request.cr, request.uid, employee_ids),
}
html = website.render("website_hr.index", values)
return html
values = website.get_rendering_context({
'employee_ids': hr_obj.browse(request.cr, request.uid, employee_ids)
})
return website.render("website_hr.index", values)
@http.route(['/hr/publish'], type='http', auth="public")
def publish(self, **post):

View File

@ -27,35 +27,31 @@
<t t-set="title">Team</t>
<div class="container">
<div class="thumbnails">
<t t-foreach="employee_ids" t-as="employee_id">
<div class="span4 mt16">
<div class="media thumbnail">
<a class="pull-left" href="#">
<img class="media-object" t-att-src="'data:image/png;base64,%%s' %% employee_id.image_small"/>
</a>
<div class="media-body">
<t t-if="editable">
<div class="pull-right">
<a href="#" t-att-data-id="employee_id.id">
<span t-att-class="'label label-success js_unpublish %%s' %% (not employee_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (employee_id.website_published and 'hidden' or '')">Click to Publish</span>
</a><br/>
<a href="#" t-att-data-id="employee_id.id">
<span t-att-class="'label label-success js_unpublish_contact %%s' %% (not employee_id.website_published and 'hidden' or '')">hidden on Contacts</span>
<span t-att-class="'label label-important js_publish_contact %%s' %% (employee_id.website_published and 'hidden' or '')">display in Contacts</span>
</a>
</div>
</t>
<h5 class="media-heading"><t t-esc="employee_id.name"/></h5>
<div t-record="employee_id" t-field="department_id"> </div>
<div t-record="employee_id" t-field="job_id"> </div>
<div t-record="employee_id" t-field="work_location"> </div>
<div t-record="employee_id" t-field="work_phone"> </div>
<div t-record="employee_id" t-field="work_email"> </div>
<div t-foreach="employee_ids" t-as="employee_id" class="span4 mt16">
<div class="media thumbnail">
<a class="pull-left" href="#">
<img class="media-object" t-att-src="'data:image/png;base64,%%s' %% employee_id.image_small"/>
</a>
<div class="media-body">
<div t-if="editable" class="pull-right">
<a href="#" t-att-data-id="employee_id.id">
<span t-att-class="'label label-success js_unpublish %%s' %% (not employee_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (employee_id.website_published and 'hidden' or '')">Click to Publish</span>
</a><br/>
<a href="#" t-att-data-id="employee_id.id">
<span t-att-class="'label label-success js_unpublish_contact %%s' %% (not employee_id.website_published and 'hidden' or '')">hidden on Contacts</span>
<span t-att-class="'label label-important js_publish_contact %%s' %% (employee_id.website_published and 'hidden' or '')">display in Contacts</span>
</a>
</div>
<h5 class="media-heading"><t t-esc="employee_id.name"/></h5>
<div t-record="employee_id" t-field="department_id"> </div>
<div t-record="employee_id" t-field="job_id"> </div>
<div t-record="employee_id" t-field="work_location"> </div>
<div t-record="employee_id" t-field="work_phone"> </div>
<div t-record="employee_id" t-field="work_email"> </div>
</div>
</div>
</t>
</div>
</div>
</div>
</t>

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request
from openerp.addons.website import website
import werkzeug
from openerp.tools.translate import _
from openerp.tools.safe_eval import safe_eval
@ -13,19 +13,28 @@ _months = {1:_("January"), 2:_("February"), 3:_("March"), 4:_("April"), 5:_("May
class website_mail(http.Controller):
@http.route(['/blog', '/blog/<int:mail_group_id>', '/blog/<int:mail_group_id>/<int:blog_id>'], type='http', auth="public")
@http.route(['/blog', '/blog/<int:mail_group_id>/', '/blog/<int:mail_group_id>/<int:blog_id>/'], type='http', auth="public")
def blog(self, mail_group_id=None, blog_id=None, **post):
website = request.registry['website']
group_obj = request.registry['mail.group']
message_obj = request.registry['mail.message']
user_obj = request.registry['res.users']
values = {
values = website.get_rendering_context({
'blog_ids': None,
'blog_id': None,
'nav_list': dict(),
'prev_date': None,
'next_date': None,
'mail_group_id': mail_group_id,
}
'subscribe': post.get('subscribe'),
})
if request.uid != request.public_uid and mail_group_id:
message_follower_ids = group_obj.read(request.cr, request.uid, [mail_group_id], ['message_follower_ids'])[0]['message_follower_ids']
parent_id = user_obj.browse(request.cr, SUPERUSER_ID, request.uid).partner_id.id
values['subscribe'] = parent_id in message_follower_ids
domain = mail_group_id and [("res_id", "=", mail_group_id)] or []
for group in message_obj.read_group(request.cr, request.uid, domain + group_obj.get_public_blog(request.cr, request.uid), ['subject', 'date'], groupby="date", orderby="create_date asc"):
@ -49,11 +58,8 @@ class website_mail(http.Controller):
if blog_id:
values['blog_id'] = message_obj.browse(request.cr, request.uid, blog_id)
comment_ids = [child_id.id for child_id in values['blog_id'].child_ids]
values['comments'] = message_obj.read(request.cr, request.uid, comment_ids, ['website_published', 'author_id', 'date', 'body'])
html = website.render("website_mail.index", values)
return html
return website.render("website_mail.index", values)
@http.route(['/blog/nav'], type='http', auth="public")
def nav(self, **post):
@ -91,9 +97,9 @@ class website_mail(http.Controller):
request.session.body = False
if post.get('body'):
return '%s/blog/%s/%s' % (url, mail_group_id, blog_id)
return '%s/blog/%s/%s/' % (url, mail_group_id, blog_id)
else:
return werkzeug.utils.redirect("/blog/%s/%s" % (mail_group_id, blog_id))
return werkzeug.utils.redirect("/blog/%s/%s/" % (mail_group_id, blog_id))
@http.route(['/blog/<int:mail_group_id>/new'], type='http', auth="public")
def new_blog_post(self, mail_group_id=None, **post):
@ -105,4 +111,37 @@ class website_mail(http.Controller):
subtype='mt_comment',
context={'mail_create_nosubsrequest.cribe': True},
)
return werkzeug.utils.redirect("/blog/%s/%s" % (mail_group_id, blog_id))
return werkzeug.utils.redirect("/blog/%s/%s/" % (mail_group_id, blog_id))
@http.route(['/blog/<int:mail_group_id>/subscribe', '/blog/<int:mail_group_id>/<int:blog_id>/subscribe'], type='http', auth="public")
def subscribe(self, mail_group_id=None, blog_id=None, **post):
partner_obj = request.registry['res.partner']
group_obj = request.registry['mail.group']
user_obj = request.registry['res.users']
if mail_group_id and 'subscribe' in post and (post.get('email') or request.uid != request.public_uid):
if request.uid == request.public_uid:
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", post.get('email'))])
if not partner_ids:
partner_ids = [partner_obj.create(request.cr, SUPERUSER_ID, {"email": post.get('email'), "name": "Subscribe: %s" % post.get('email')})]
else:
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid).partner_id.id]
group_obj.message_subscribe(request.cr, request.uid, [mail_group_id], partner_ids)
return self.blog(mail_group_id=mail_group_id, blog_id=blog_id, subscribe=post.get('email'))
@http.route(['/blog/<int:mail_group_id>/unsubscribe', '/blog/<int:mail_group_id>/<int:blog_id>/unsubscribe'], type='http', auth="public")
def unsubscribe(self, mail_group_id=None, blog_id=None, **post):
partner_obj = request.registry['res.partner']
group_obj = request.registry['mail.group']
user_obj = request.registry['res.users']
if mail_group_id and 'unsubscribe' in post and (post.get('email') or request.uid != request.public_uid):
if request.uid == request.public_uid:
partner_ids = partner_obj.search(request.cr, SUPERUSER_ID, [("email", "=", post.get('email'))])
else:
partner_ids = [user_obj.browse(request.cr, request.uid, request.uid).partner_id.id]
group_obj.message_unsubscribe(request.cr, request.uid, [mail_group_id], partner_ids)
return self.blog(mail_group_id=mail_group_id, blog_id=blog_id, subscribe=None)

View File

@ -18,7 +18,7 @@
<field name="arch" type="xml">
<data>
<xpath expr="//li[last()]" position="after">
<li class="pull-right"><a href="/blog/%(website_mail.website_mail_blog)d">News</a></li>
<li class="pull-right"><a href="/blog/%(website_mail.website_mail_blog)d/">News</a></li>
</xpath>
</data>
</field>
@ -29,7 +29,7 @@
<field name="arch" type="xml">
<data>
<xpath expr="//a[@href='/page/website.news']" position="replace">
<a href="/blog/%(website_mail.website_mail_blog)d">News</a>
<a href="/blog/%(website_mail.website_mail_blog)d/">News</a>
</xpath>
</data>
</field>
@ -50,20 +50,27 @@
<div class="span4">
<ul class="nav nav-list">
<a t-if="mail_group_id and editable" t-att-href="'/blog/%%s/new' %% mail_group_id" class="btn">Add a new Blog</a>
<li class="nav-header">BLOG ARCHIVE</li>
<li class="nav-header"><a t-att-href="'/blog/%%s/' %% mail_group_id">BLOG ARCHIVE</a></li>
<!-- TODO: check qweb iteration -->
<t t-foreach="nav_list" t-as="year">
<li t-foreach="nav_list" t-as="year" class="js_nav_year">
<t t-set="year" t-value="nav_list[year]"/>
<li class="js_nav_year"><a href="#"><t t-esc="year['name']"/> <small>(<t t-esc="year['date_count']"/>)</small></a>
<ul class="nav nav-list css_nav_month">
<t t-foreach="year['months']">
<li class="js_nav_month"><a href="#" t-att-data-domain="__domain"><t t-esc="date"/> <small>(<t t-esc="date_count"/>)</small></a>
<ul class="nav nav-list"/>
</li>
</t>
</ul>
</li>
</t>
<a href="#"><t t-esc="year['name']"/> <small>(<t t-esc="year['date_count']"/>)</small></a>
<ul class="nav nav-list css_nav_month">
<t t-foreach="year['months']">
<li class="js_nav_month"><a href="#" t-att-data-domain="__domain"><t t-esc="date"/> <small>(<t t-esc="date_count"/>)</small></a>
<ul class="nav nav-list"/>
</li>
</t>
</ul>
</li>
<form action="./subscribe" method="POST" class="form-inline" t-if="not subscribe">
<input placeholder="Email Address" type="email" name="email" class="input-medium" t-if="request.uid == request.public_uid"/>
<button type="submit" class="btn btn-primary" name="subscribe">Subscribe</button>
</form>
<form action="./unsubscribe" method="POST" class="form-inline" t-if="subscribe">
<input type="hidden" name="email" t-att-value="subscribe"/>
<button type="submit" class="btn" name="unsubscribe">Unsubscribe</button>
</form>
</ul>
</div>
<div class="span8" t-if="blog_id">
@ -73,30 +80,27 @@
<span t-att-class="'label label-success js_unpublish %%s' %% (not blog_id.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (blog_id.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<h3 t-field="blog_id.subject"></h3>
<div t-field="blog_id.body"></div>
<h3 t-field="blog_id.subject"/>
<div t-field="blog_id.body"/>
<small class="pull-right muted text-right">
<div><t t-field="blog_id.author_id"/></div>
<div><t t-field="blog_id.date"/></div>
<div t-field="blog_id.author_id"/>
<div t-field="blog_id.date"/>
</small>
</div>
<ul class="media-list">
<t t-foreach="blog_id.child_ids" t-as="comment">
<!-- TODO: check qweb iteration -->
<li class="media">
<div class="media-body">
<a href="#" t-att-data-id="blog_id.id" class="pull-right" t-if="editable">
<span t-att-class="'label label-success js_unpublish %%s' %% (not comment.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (comment.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<t t-raw="comment.body"/>
<small class="pull-right muted text-right">
<div><t t-esc="comment.author_id"/></div>
<div><t t-esc="comment.date"/></div>
</small>
</div>
</li>
</t>
<ul class="media-list" id="comment">
<li t-foreach="blog_id.child_ids" t-as="comment" class="media">
<div class="media-body">
<a href="#" t-att-data-id="blog_id.id" class="pull-right" t-if="editable">
<span t-att-class="'label label-success js_unpublish %%s' %% (not comment.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (comment.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<t t-raw="comment.body"/>
<small class="pull-right muted text-right">
<div t-esc="comment.author_id"/>
<div t-esc="comment.date"/>
</small>
</div>
</li>
<form id="post" t-att-action="'/blog/%%s/%%s/post#post' %% (blog_id.res_id, blog_id.id)" method="POST" class="form-horizontal text-center" groups="group_website_mail_reply">
<textarea rows="4" placeholder="Your message" class="span7"> </textarea>
<button type="submit" class="btn">Post your message</button>
@ -106,28 +110,26 @@
</div>
<div class="span8" t-if="not blog_id and blog_ids">
<ul class="media-list">
<t t-foreach="blog_ids" t-as="blog">
<li class="media well">
<div t-att-class="'media-body %%s' %% (blog.website_published and 'css_published' or '')">
<a href="#" t-att-data-id="blog.id" class="pull-right" t-if="editable">
<span t-att-class="'label label-success js_unpublish %%s' %% (not blog.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (blog.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<h4 class="media-heading" ><a t-att-href="'/blog/%%s/%%s' %% (blog.res_id, blog.id)" t-field="blog.subject"></a></h4>
<div class="media">
<div t-field="blog.body"></div>
<small class="pull-left muted text-right" t-if="len(blog.child_ids)">
<a t-if="len(blog.child_ids) &lt;= 1" t-att-href="'/blog/%%s/%%s' %% (blog.res_id, blog.id)"><t t-esc="len(blog.child_ids)"/> Message</a>
<a t-if="len(blog.child_ids) > 1" t-att-href="'/blog/%%s/%%s' %% (blog.res_id, blog.id)"><t t-esc="len(blog.child_ids)"/> Messages</a>
</small>
<small class="pull-right muted text-right">
<div><t t-field="blog.author_id"/></div>
<div><t t-field="blog.date"/></div>
</small>
</div>
<li t-foreach="blog_ids" t-as="blog" class="media well">
<div t-att-class="'media-body %%s' %% (blog.website_published and 'css_published' or '')">
<a href="#" t-att-data-id="blog.id" class="pull-right" t-if="editable">
<span t-att-class="'label label-success js_unpublish %%s' %% (not blog.website_published and 'hidden' or '')">Click to Unpublish</span>
<span t-att-class="'label label-important js_publish %%s' %% (blog.website_published and 'hidden' or '')">Click to Publish</span>
</a>
<h4 class="media-heading" ><a t-att-href="'/blog/%%s/%%s#comment' %% (blog.res_id, blog.id)" t-field="blog.subject"></a></h4>
<div class="media">
<div t-field="blog.body"/>
<small class="pull-left muted text-right" t-if="len(blog.child_ids)">
<a t-if="len(blog.child_ids) &lt;= 1" t-att-href="'/blog/%%s/%%s#comment' %% (blog.res_id, blog.id)"><t t-esc="len(blog.child_ids)"/> Message</a>
<a t-if="len(blog.child_ids) > 1" t-att-href="'/blog/%%s/%%s#comment' %% (blog.res_id, blog.id)"><t t-esc="len(blog.child_ids)"/> Messages</a>
</small>
<small class="pull-right muted text-right">
<div t-field="blog.author_id"/>
<div t-field="blog.date"/>
</small>
</div>
</li>
</t>
</div>
</li>
</ul>
<ul class="pager">
<li t-if="next_date" class="previous">

View File

@ -3,10 +3,50 @@
import math
import openerp
import simplejson
from openerp.osv import osv
from openerp.addons.web import http
from openerp.addons.website import website
from openerp.addons.web.http import request
def get_order(order_id=None):
order_obj = request.registry.get('sale.order')
# check if order allready exists
if order_id:
try:
order_obj.browse(request.cr, openerp.SUPERUSER_ID, order_id).pricelist_id
except:
order_id = None
if not order_id:
fields = [k for k, v in order_obj._columns.items()]
order_value = order_obj.default_get(request.cr, openerp.SUPERUSER_ID, fields)
order_value['partner_id'] = openerp.SUPERUSER_ID != request.public_uid and \
request.registry.get('res.users').browse(request.cr, openerp.SUPERUSER_ID, request.uid).partner_id.id or \
None
order_value.update(order_obj.onchange_partner_id(request.cr, openerp.SUPERUSER_ID, [], request.uid, context={})['value'])
order_id = order_obj.create(request.cr, openerp.SUPERUSER_ID, order_value)
return order_obj.browse(request.cr, openerp.SUPERUSER_ID, order_id)
def get_current_order():
order = get_order(request.httprequest.session.get('ecommerce_order_id'))
request.httprequest.session['ecommerce_order_id'] = order.id
return order
def get_categories():
category_obj = request.registry.get('pos.category')
category_ids = category_obj.search(request.cr, openerp.SUPERUSER_ID, [('parent_id', '=', False)])
return category_obj.browse(request.cr, openerp.SUPERUSER_ID, category_ids)
class website(osv.osv):
_inherit = "website"
def get_rendering_context(self, additional_values=None):
values = {
'website_sale_get_categories': get_categories,
'order': get_current_order(),
# 'website_sale_get_current_order': get_current_order, # TODO: replace 'order' key in templates
}
if additional_values:
values.update(additional_values)
return super(website, self).get_rendering_context(values)
class Ecommerce(http.Controller):
@ -52,7 +92,7 @@ class Ecommerce(http.Controller):
def recommended_product(self, my_pids):
if not my_pids:
return []
my_pids = str(my_pids)[1:-1]
product_ids = []
query = """
@ -74,6 +114,7 @@ class Ecommerce(http.Controller):
@http.route(['/shop', '/shop/category/<cat_id>', '/shop/category/<cat_id>/page/<page>', '/shop/page/<page>'], type='http', auth="public")
def category(self, cat_id=0, page=0, **post):
website = request.registry['website']
product_obj = request.registry.get('product.product')
domain = [("sale_ok", "=", True)]
@ -104,20 +145,20 @@ class Ecommerce(http.Controller):
product_ids = product_obj.search(request.cr, request.uid, domain, limit=20, offset=offset)
values = {
values = website.get_rendering_context({
'current_category': cat_id,
'products': product_obj.browse(request.cr, request.uid, product_ids),
'search': post.get("search"),
'page_count': page_count,
'pages': pages,
'page': page,
}
html = self.render("website_sale.products", values)
return html
})
return website.render("website_sale.products", values)
@http.route(['/shop/product/<product_id>'], type='http', auth="public")
def product(self, cat_id=0, product_id=0):
order = self.get_current_order()
website = request.registry['website']
order = get_current_order()
product_id = product_id and int(product_id) or 0
product_obj = request.registry.get('product.product')
@ -125,17 +166,17 @@ class Ecommerce(http.Controller):
line = [line for line in order.order_line if line.product_id.id == product_id]
quantity = line and int(line[0].product_uom_qty) or 0
values = {
values = website.get_rendering_context({
'product': product_obj.browse(request.cr, request.uid, product_id),
'quantity': quantity,
'recommended_products': self.recommended_product([product_id]),
}
html = self.render("website_sale.product", values)
return html
})
return website.render("website_sale.product", values)
@http.route(['/shop/mycart'], type='http', auth="public")
def mycart(self, **post):
order = self.get_current_order()
website = request.registry['website']
order = get_current_order()
if post.get('code'):
pricelist_obj = request.registry.get('product.pricelist')
@ -144,14 +185,16 @@ class Ecommerce(http.Controller):
order.write({'pricelist_id': pricelist_ids[0]})
my_pids = [line.product_id.id for line in order.order_line]
values= {"recommended_products": self.recommended_product(my_pids)}
values = website.get_rendering_context({
"recommended_products": self.recommended_product(my_pids)
})
html = self.render("website_sale.mycart", values)
return html
return website.render("website_sale.mycart", values)
@http.route(['/shop/add_cart'], type='http', auth="public")
def add_cart(self, product_id=0, remove=False):
website = request.registry['website']
values = website.get_rendering_context()
context = {}
order_obj = request.registry.get('sale.order')
@ -159,13 +202,12 @@ class Ecommerce(http.Controller):
user_obj = request.registry.get('res.users')
product_id = product_id and int(product_id) or 0
order = self.get_current_order()
order = get_current_order()
quantity = 0
# values initialisation
order_line_ids = order_line_obj.search(request.cr, openerp.SUPERUSER_ID, [('order_id', '=', order.id), ('product_id', '=', product_id)], context=context)
values = {}
if order_line_ids:
order_line = order_line_obj.read(request.cr, openerp.SUPERUSER_ID, order_line_ids, [], context=context)[0]
quantity = order_line['product_uom_qty'] + (remove and -1 or 1)
@ -191,8 +233,7 @@ class Ecommerce(http.Controller):
order_line_id = order_line_obj.create(request.cr, openerp.SUPERUSER_ID, values, context=context)
order.write({'order_line': [(4, order_line_id)]}, context=context)
html = self.render("website_sale.total")
html = website.render("website_sale.total", values)
return simplejson.dumps({"quantity": quantity, "totalHTML": html})
@http.route(['/shop/remove_cart'], type='http', auth="public")
@ -201,7 +242,11 @@ class Ecommerce(http.Controller):
@http.route(['/shop/checkout'], type='http', auth="public")
def checkout(self, **post):
order = self.get_current_order()
website = request.registry['website']
values = website.get_rendering_context({
'partner': False
})
order = get_current_order()
if order.state != 'draft':
return self.confirmed(**post)
@ -214,7 +259,6 @@ class Ecommerce(http.Controller):
country_state_obj = request.registry.get('res.country.state')
payment_obj = request.registry.get('portal.payment.acquirer')
values = {'partner': False}
if request.uid != request.public_uid:
values['partner'] = user_obj.browse(request.cr, request.uid, request.uid).partner_id
@ -232,12 +276,12 @@ class Ecommerce(http.Controller):
content = payment_obj.render(request.cr, openerp.SUPERUSER_ID, payment.id, order, order.name, order.pricelist_id.currency_id, order.amount_total)
payment._content = content
return self.render("website_sale.checkout", values)
return website.render("website_sale.checkout", values)
@http.route(['/shop/confirm_order'], type='http', auth="public")
def confirm_order(self, **post):
order = self.get_current_order()
order = get_current_order()
json = {'error': [], 'validation': False}
partner_obj = request.registry.get('res.partner')
user_obj = request.registry.get('res.users')
@ -322,23 +366,23 @@ class Ecommerce(http.Controller):
@http.route(['/shop/confirmed'], type='http', auth="public")
def confirmed(self, **post):
website = request.registry['website']
if request.httprequest.session.get('ecommerce_order_id'):
order = self.get_current_order()
order = get_current_order()
if order.state != 'draft':
request.httprequest.session['ecommerce_order_id_old'] = order.id
request.httprequest.session['ecommerce_order_id'] = None
order_old = self.get_order(request.httprequest.session.get('ecommerce_order_id_old'))
order_old = get_order(request.httprequest.session.get('ecommerce_order_id_old'))
if not order_old.order_line:
return self.mycart(**post)
values = {
values = website.get_rendering_context({
'temp': 0,
'order': order_old,
'categories': self.get_categories(),
}
return self.render("website_sale.confirmed", values)
})
return website.render("website_sale.confirmed", values)
@http.route(['/shop/publish'], type='http', auth="public")
def publish(self, **post):

View File

@ -7,4 +7,5 @@ class product_pricelist(osv.osv):
_inherit = "product.product"
_columns = {
'website_published': fields.boolean('Available in the website'),
'description_website': fields.html('Description for the website'),
}

View File

@ -67,7 +67,7 @@
<div class="span4">
<ul class="nav nav-list">
<li t-att-class=" '' if current_category else 'active' " class='active'><a href='/shop/'>All Products</a></li>
<t t-foreach="categories" t-as="category">
<t t-foreach="website_sale_get_categories()" t-as="category">
<t t-call="website_sale.categories_recursive"/>
</t>
</ul>
@ -188,7 +188,7 @@
</button>
</div>
<img class="media-object" t-att-src="'data:image/png;base64,' + product.image"/>
<div t-field="product.description_sale"></div>
<div t-field="product.description_website"></div>
<div class="oe_ecommerce_price"><t t-field="product.list_price" /></div>
<t t-call="website_sale.product_recommended"/>
</div>