Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing cleanup #877

Draft
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 5 additions & 41 deletions runbot/controllers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,8 @@ def decorator(f):
@o_route(routes, **kw)
@functools.wraps(f)
def response_wrap(*args, **kwargs):
projects = request.env['runbot.project'].search([('hidden', '=', False)])
more = request.httprequest.cookies.get('more', False) == '1'
filter_mode = request.httprequest.cookies.get('filter_mode', 'all')
keep_search = request.httprequest.cookies.get('keep_search', False) == '1'
cookie_search = request.httprequest.cookies.get('search', '')
refresh = kwargs.get('refresh', False)
nb_build_errors = request.env['runbot.build.error'].search_count([('random', '=', True), ('parent_id', '=', False)])
nb_assigned_errors = request.env['runbot.build.error'].search_count([('responsible', '=', request.env.user.id)])
nb_team_errors = request.env['runbot.build.error'].search_count([('responsible', '=', False), ('team_id', 'in', request.env.user.runbot_team_ids.ids)])
kwargs['more'] = more
kwargs['projects'] = projects

response = f(*args, **kwargs)
if isinstance(response, Response):
if keep_search and cookie_search and 'search' not in kwargs:
search = cookie_search
else:
search = kwargs.get('search', '')
has_pr = kwargs.get('has_pr', None)
if keep_search and cookie_search != search:
response.set_cookie('search', search)

project = response.qcontext.get('project') or projects and projects[0]

response.qcontext['theme'] = kwargs.get('theme', request.httprequest.cookies.get('theme', 'legacy'))
response.qcontext['projects'] = projects
response.qcontext['more'] = more
response.qcontext['keep_search'] = keep_search
response.qcontext['search'] = search
response.qcontext['current_path'] = request.httprequest.full_path
response.qcontext['refresh'] = refresh
response.qcontext['filter_mode'] = filter_mode
response.qcontext['default_category'] = request.env['ir.model.data']._xmlid_to_res_id('runbot.default_category')

response.qcontext['qu'] = QueryURL('/runbot/%s' % (slug(project) if project else ''), search=search, refresh=refresh, has_pr=has_pr)
if 'title' not in response.qcontext:
response.qcontext['title'] = 'Runbot %s' % project.name or ''
response.qcontext['nb_build_errors'] = nb_build_errors
response.qcontext['nb_assigned_errors'] = nb_assigned_errors
response.qcontext['nb_team_errors'] = nb_team_errors
return response
return response_wrap
return decorator
Expand All @@ -84,7 +46,7 @@ def _pending(self):
@o_route([
'/runbot/submit'
], type='http', auth="public", methods=['GET', 'POST'], csrf=False)
def submit(self, more=False, redirect='/', keep_search=False, category=False, filter_mode=False, update_triggers=False, **kwargs):
def submit(self, more=False, redirect='/', category=False, filter_mode=False, update_triggers=False, **kwargs):
assert redirect.startswith('/')
response = werkzeug.utils.redirect(redirect)
response.set_cookie('more', '1' if more else '0')
Expand All @@ -106,10 +68,11 @@ def submit(self, more=False, redirect='/', keep_search=False, category=False, fi
'/runbot',
'/runbot/<model("runbot.project"):project>',
'/runbot/<model("runbot.project"):project>/search/<search>'], website=True, auth='public', type='http')
def bundles(self, project=None, search='', projects=False, refresh=False, for_next_freeze=False, limit=40, has_pr=None, **kwargs):
def bundles(self, project=None, search='', refresh=False, for_next_freeze=False, limit=40, has_pr=None, **kwargs):
search = search if len(search) < 60 else search[:60]
env = request.env
categories = env['runbot.category'].search([])
projects = request.env['runbot.project'].search([('hidden', '=', False)])
if not project and projects:
project = projects[0]

Expand All @@ -123,6 +86,7 @@ def bundles(self, project=None, search='', projects=False, refresh=False, for_ne
'pending_level': level,
'scheduled_count': scheduled_count,
'hosts_data': request.env['runbot.host'].search([('assigned_only', '=', False)]),
'projects': projects
}
if project:
domain = [('last_batch', '!=', False), ('project_id', '=', project.id)]
Expand Down Expand Up @@ -180,8 +144,8 @@ def bundles(self, project=None, search='', projects=False, refresh=False, for_ne
'project': project,
'triggers': triggers,
'trigger_display': trigger_display,
'has_pr': has_pr,
'search': search,
'has_pr': has_pr,
})

context.update({'message': request.env['ir.config_parameter'].sudo().get_param('runbot.runbot_message')})
Expand Down
8 changes: 3 additions & 5 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ def _run_run_odoo(self, build, force=False):

def _run_install_odoo(self, build):
exports = build._checkout()

modules_to_install = self._modules_to_install(build)
modules_to_install = build.params_id.get('mods')
if not modules_to_install:
modules_to_install = set(build._get_modules_to_test(modules_patterns=self.install_modules))
mods = ",".join(modules_to_install)
python_params = []
py_version = build._get_py_version()
Expand Down Expand Up @@ -890,9 +891,6 @@ def _log_end(self, build):
message = 'Flamegraph report: [data @icon-download](%s), [svg @icon-eye](%s)' % (dat_url, svg_url)
build._log('end_job', message, log_type='markdown')

def _modules_to_install(self, build):
return set(build._get_modules_to_test(modules_patterns=self.install_modules))

def _post_install_commands(self, build, modules_to_install, py_version=None):
cmds = []
if self.coverage:
Expand Down
27 changes: 27 additions & 0 deletions runbot/models/ir_qweb.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
from ..common import s2human, s2human_long
from odoo import models
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.website.controllers.main import QueryURL


class IrQweb(models.AbstractModel):
_inherit = ["ir.qweb"]

def _prepare_frontend_environment(self, values):
response = super()._prepare_frontend_environment(values)

has_pr = values.get('has_pr', None)
search = values.get('search', None)
refresh = values.get('refresh', None)
project = values.get('project', None)

values['more'] = values.get('more', request.httprequest.cookies.get('more', False) == '1')
values['theme'] = values.get('theme', request.httprequest.cookies.get('theme', 'legacy'))
values['filter_mode'] = values.get('filter_mode', request.httprequest.cookies.get('filter_mode', 'all'))

values['s2human'] = s2human
values['s2human_long'] = s2human_long
if 'projects' not in values:
values['projects'] = request.env['runbot.project'].search([('hidden', '=', False)])

values['qu'] = QueryURL('/runbot/%s' % (slug(project) if project else ''), search=search, refresh=refresh, has_pr=has_pr)

if 'title' not in values and project:
values['title'] = 'Runbot %s' % project.name or ''

values['nb_build_errors'] = request.env['runbot.build.error'].search_count([('random', '=', True), ('parent_id', '=', False)])
values['nb_assigned_errors'] = request.env['runbot.build.error'].search_count([('responsible', '=', request.env.user.id)])
values['nb_team_errors'] = request.env['runbot.build.error'].search_count([('responsible', '=', False), ('team_id', 'in', request.env.user.runbot_team_ids.ids)])

values['current_path'] = request.httprequest.full_path
values['default_category'] = request.env['ir.model.data']._xmlid_to_res_id('runbot.default_category')

return response