Example #1
0
 def index(self, **kw):
     page = 'homepage'
     try:
         main_menu = request.registry['ir.model.data'].get_object(
             request.cr, request.uid, 'website', 'main_menu')
     except Exception:
         pass
     else:
         first_menu = main_menu.child_id and main_menu.child_id[0]
         if first_menu:
             if first_menu.url and (not (first_menu.url.startswith(
                 ('/page/', '/?', '/#')) or (first_menu.url == '/'))):
                 return request.redirect(first_menu.url)
             if first_menu.url and first_menu.url.startswith('/page/'):
                 return request.registry['ir.http'].reroute(first_menu.url)
     return self.page(page)
Example #2
0
    def actions_server(self, path_or_xml_id_or_id, **post):
        cr, uid, context = request.cr, request.uid, request.context
        res, action_id, action = None, None, None
        ServerActions = request.registry['ir.actions.server']

        # find the action_id: either an xml_id, the path, or an ID
        if isinstance(path_or_xml_id_or_id,
                      str) and '.' in path_or_xml_id_or_id:
            action_id = request.registry['ir.model.data'].xmlid_to_res_id(
                request.cr,
                request.uid,
                path_or_xml_id_or_id,
                raise_if_not_found=False)
        if not action_id:
            action_ids = ServerActions.search(
                cr,
                uid, [('website_path', '=', path_or_xml_id_or_id),
                      ('website_published', '=', True)],
                context=context)
            action_id = action_ids and action_ids[0] or None
        if not action_id:
            try:
                action_id = int(path_or_xml_id_or_id)
            except ValueError:
                pass

        # check it effectively exists
        if action_id:
            action_ids = ServerActions.exists(cr,
                                              uid, [action_id],
                                              context=context)
            action_id = action_ids and action_ids[0] or None
        # run it, return only if we got a Response object
        if action_id:
            action = ServerActions.browse(cr, uid, action_id, context=context)
            if action.state == 'code' and action.website_published:
                action_res = ServerActions.run(cr,
                                               uid, [action_id],
                                               context=context)
                if isinstance(action_res, werkzeug.wrappers.Response):
                    res = action_res
        if res:
            return res
        return request.redirect('/')
Example #3
0
    def reset_template(self, templates, redirect='/'):
        templates = request.httprequest.form.getlist('templates')
        modules_to_update = []
        for temp_id in templates:
            view = request.registry['ir.ui.view'].browse(
                request.cr, request.uid, int(temp_id), context=request.context)
            if view.page:
                continue
            view.model_data_id.write({'noupdate': False})
            if view.model_data_id.module not in modules_to_update:
                modules_to_update.append(view.model_data_id.module)

        if modules_to_update:
            module_obj = request.registry['ir.module.module']
            module_ids = module_obj.search(request.cr,
                                           request.uid,
                                           [('name', 'in', modules_to_update)],
                                           context=request.context)
            if module_ids:
                module_obj.button_immediate_upgrade(request.cr,
                                                    request.uid,
                                                    module_ids,
                                                    context=request.context)
        return request.redirect(redirect)