forked from nicolas-petit/website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] website_field_autocomplete: Switch from JS model to controller
- Loading branch information
Showing
5 changed files
with
53 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import controllers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import json | ||
from openerp import http | ||
from openerp.http import request | ||
from openerp.addons.website.controllers.main import Website | ||
|
||
|
||
class Website(Website): | ||
|
||
@http.route( | ||
'/website/field_autocomplete/<string:model>', | ||
type='http', | ||
auth='public', | ||
methods=['GET'], | ||
website=True, | ||
) | ||
def _get_autocomplete_data(self, model, **kwargs): | ||
res = [] | ||
domain = json.loads(kwargs.get('domain', "[]")) | ||
fields = json.loads(kwargs.get('fields', "[]")) | ||
limit = kwargs.get('limit', None) | ||
if limit: | ||
limit = int(limit) | ||
for rec_id in request.env[model].search(domain, limit=limit): | ||
res.append({ | ||
k: getattr(rec_id, k, None) for k in fields | ||
}) | ||
return json.dumps(res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters