Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

3

How can I do search without the env attribute?

By
Sebin Siby
on 6/21/16, 9:27 AM 417 views

Hi,


I did overridden the "web_login" function defined in the "Home" class in the "web" module and I need to search a record from that function  but I am getting an internal server error that says,

AttributeError: 'Home (extended by Website, Home, AuthSignupHome)' object has no attribute 'env'


My function is as follows,


class Home(openerp.addons.web.controllers.main.Home):

        @http.route('/web/login', type='http', auth="none")

        def web_login(self, redirect=None, **kw):

                ensure_db()

                request.params['login_success'] = False

                if request.httprequest.method == 'GET' and redirect and request.session.uid:

                        return http.redirect_with_hash(redirect)

                if not request.uid:

                        request.uid = openerp.SUPERUSER_ID

                values = request.params.copy()

                try:

                        values['databases'] = http.db_list()

                except openerp.exceptions.AccessDenied:

                        values['databases'] = None

                if request.httprequest.method == 'POST':

                        old_uid = request.uid

                        uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])

                        if uid is not False:

                                user = self.env['res.users'].search([('id', '=', uid)]) 

                                if user.is_blocked != True:

                                        request.params['login_success'] = True

                                        if not redirect:

                                                 redirect = '/web'

                                        return http.redirect_with_hash(redirect)

                                 else:

                                        values['error'] = "You have pending customer payments and your system access is blocked.!! Please contact the administrator.!!"

                                        return request.render('web.login', values)

                          request.uid = old_uid

                          values['error'] = "Wrong login/password"

                    return request.render('web.login', values)



How can I do "user = self.env['res.users'].search([('id', '=', uid)])" this in that function or is there any other way to implement this??


Thanks...





 


3

Axel Mendoza

--Axel Mendoza--
10318
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 6/21/16, 6:29 PM

Use request.env instead of self.env and you will be ok

Really thanks...... @Axel Mendoza

Sebin Siby
on 6/22/16, 2:24 AM

Solved? If ok, please accept the answer too, :)

Axel Mendoza
on 6/22/16, 2:31 AM

Yes It's worked. But I don't have that much karma to accept your answer.

Sebin Siby
on 6/23/16, 12:29 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/21/16, 9:27 AM
Seen: 417 times
Last updated: 9/6/16, 9:49 AM