#17254: ModelBackend should have a get_anonymous_user method ------------------------------------+-------------------------------------- Reporter: riccardodivirgilio | Owner: nobody Type: Bug | Status: closed Component: contrib.auth | Version: Severity: Normal | Resolution: needsinfo Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------------+--------------------------------------
Comment (by anonymous): when you subclass the user, i would like to subclass even the AnonymousUser in request to check the user attributes without using getattr, or define custom methods, even for an AnonymousUser user. for example, i have got a field that is called "user_discount" and i have got a method that return the final price of the user. i use this method a lot of time in the site, because it's an commerce, and it's useful to do request.user.dicounted_price("120") without doing a mess like this get_discounted_price_from_user(user, 120), and using a function and not a class, and in every part of my code i have to check if user is_authenticated before using custom method of my user class. for me an AnonymousUser, should be a subclass of the user class, but it must be declared importing the user class from the backend and then subclassing it. i've a attached a new backend file, this is an easy way to allow developers to completely use another User and Permission backend using 3 line of code (read the backends.py i've attached) class MyModelBackend(ModelBackend): user_class = MyUser permission_class = MyPermission anonymoususer_class = MyAnonymousUser with this class i can set my own model table for existing legacy user and permission, without rewrite login, logout, password_change and so on... -- Ticket URL: <https://code.djangoproject.com/ticket/17254#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.