Skip to content

Commit

Permalink
[ADD] website_backend_views poc
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Jan 20, 2015
1 parent 2de71f5 commit 917fb99
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 0 deletions.
55 changes: 55 additions & 0 deletions website_backend_views/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Backend views for website
=========================

This module was written to extend the functionality of ... to support ... and allow you to ...

Installation
============

To install this module, you need to:

* do this ...

Configuration
=============

To configure this module, you need to:

* go to ...

Usage
=====

To use this module, you need to:

* go to ...

For further information, please visit:

* https://www.odoo.com/forum/help-1

Known issues / Roadmap
======================

* ...

Credits
=======

Contributors
------------

* Firsname Lastname <[email protected]>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
22 changes: 22 additions & 0 deletions website_backend_views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model
from . import controllers
44 changes: 44 additions & 0 deletions website_backend_views/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Backend views for website",
"version": "1.0",
"author": "Therp BV",
"license": "AGPL-3",
"category": "Website",
"summary": "Hook backend views into your website frontend",
"depends": [
],
"data": [
'view/templates.xml',
],
"demo": [
"view/demo.xml",
],
"test": [
],
"auto_install": False,
"installable": True,
"application": False,
"external_dependencies": {
'python': [],
},
}
21 changes: 21 additions & 0 deletions website_backend_views/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import demo
30 changes: 30 additions & 0 deletions website_backend_views/controllers/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import http, _

class Demo(http.Controller):
@http.route('/website_backend_views/demo/', auth='user', website=True)
def index(self, debug=False):
if not http.request.env.ref(
'website_backend_views.demo_index', raise_if_not_found=False):
return _('You need to install this module in demo mode for this '
'url to work!')
return http.request.render('website_backend_views.demo_index')
21 changes: 21 additions & 0 deletions website_backend_views/model/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import ir_qweb
61 changes: 61 additions & 0 deletions website_backend_views/model/ir_qweb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import simplejson
from lxml import etree
from openerp import models, fields, api, exceptions


class IrQweb(models.Model):
_inherit = 'ir.qweb'

def render_tag_website_backend_view(
self, element, template_attributes, generated_attributes,
qwebcontext):
options = simplejson.loads(
template_attributes.get('website-backend-view', '{}'))
model = self.pool.get(options.get('res_model'))
if not model:
raise NameError(
'Unknown model "%s" or no model defined' %
options.get('res_model'))
etree.SubElement(
element,
'div',
attrib={
'data-website-backend-view-model': model._name,
'data-website-backend-view-type': options.get(
'view_type', 'form'),
'data-website-backend-view-id': options.get('view_id', ''),
'data-website-backend-view-res-id': str(
options.get('res_id', '')),
'data-website-backend-view-domain': simplejson.dumps(
options.get('domain', '{}')),
})
etree.SubElement(
element,
't',
attrib={
't-set': 'website_backend_views_active',
't-value': 'True',
})
return self.render_element(
element, template_attributes, generated_attributes,
qwebcontext)
Binary file added website_backend_views/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
58 changes: 58 additions & 0 deletions website_backend_views/static/src/js/website_backend_views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//-*- coding: utf-8 -*-
//############################################################################
//
// OpenERP, Open Source Management Solution
// This module copyright (C) 2015 Therp BV <http://therp.nl>.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//############################################################################
(function()
{
openerp.website.dom_ready.then(function()
{
var views = jQuery('[data-website-backend-view-model]');
if(!views.length)
{
return;
}
var backend = openerp.init();
backend.client = new backend.web.WebClient();
backend.client.start().then(function()
{
views.each(function(i, view)
{
view = jQuery(view);
var action = {
'type': 'ir.actions.act_window',
'res_model': view.data('website-backend-view-model'),
'res_id': view.data('website-backend-view-res-id'),
'views': [
[
view.data('website-backend-view-id'),
view.data('website-backend-view-type')
]
],
'domain': view.data('website-backend-view-domain') || [],
};
var action_manager = new backend.web.ActionManager(backend.client);
var view_manager = new backend.web.ViewManagerAction(
action_manager, action);
view_manager.setElement(view);
view_manager.renderElement();
view_manager.start();
});
});
});
})()
13 changes: 13 additions & 0 deletions website_backend_views/view/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="demo_index">
<t t-call="website.layout">
<h1>Beneath you'll see an edit form for your main partner. Should work</h1>
<!-- this wil end up in a window action with the appropriate fields set /-->
<t t-website-backend-view='{"res_model": "res.partner", "view_type": "form", "res_id": %(base.main_partner)s, "domain": [["id", "=", %(base.main_partner)s]]}' />
<div>And of course, you can do whatever you want with the rest of the page. Maybe hide the manager's buttons and provide a nicer UI for saving?</div>
</t>
</template>
</data>
</openerp>
18 changes: 18 additions & 0 deletions website_backend_views/view/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_frontend" name="website_backend_views assets" inherit_id="website.assets_frontend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website_backend_views/static/src/js/website_backend_views.js"></script>
<link rel="stylesheet" href="/website_backend_views/static/src/css/website_backend_views.css"/>
</xpath>
</template>
<template id="layout" inherit_id="website.layout">
<xpath expr="//t[@t-call-assets='web.assets_common' and @t-css='false']" position="after">
<t t-if="website_backend_views_active">
<t t-call-assets="web.assets_backend" t-css="false" />
</t>
</xpath>
</template>
</data>
</openerp>

0 comments on commit 917fb99

Please sign in to comment.