#16611: Contrib.auth.UserManager should allow filtering active/inactive users
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  TomaszZielinski
  TomaszZielinski                    |         Status:  reopened
                   Type:  New        |      Component:  contrib.auth
  feature                            |       Severity:  Normal
              Milestone:  1.4        |       Keywords:
                Version:  SVN        |      Has patch:  1
             Resolution:             |    Needs tests:  0
           Triage Stage:  Design     |  Easy pickings:  1
  decision needed                    |
    Needs documentation:  0          |
Patch needs improvement:  0          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
Changes (by twoolie):

 * status:  closed => reopened
 * cc: twoolie (added)
 * resolution:  wontfix =>
 * easy:  0 => 1
 * milestone:   => 1.4


Comment:

 Right up front: appologies if re-opening is not the correct etiquette, but
 i believe there is a use case that has not been considdered and i don't
 know if closed tickets will ever show up again in the core dev's ticket
 lists. Feel free to shut me down after hearing me out.

 I independently opened a [https://github.com/django/django/pull/51 Pull
 Request] for this feature a few days ago before I knew this issue existed.
 I just wanted to note that the main purpose of my patch was not to enable
 shortcutting in python when a more verbose approach is better. My patch
 was motivated by the following (admittedly generic) template use case
 which is enabled by setting use_for_related_fields = True on UserManager.

 {{{
 {% for moderator in forum.moderators.active %}
     {{ moderator|profilelink }}{% if not forloop.last %},{% endif %}
 {% endfor %}
 }}}
 instead of
 {{{
 {% for moderator in forum.moderators.all %}
     {% if moderator.is_active %}
         {{ moderator|profilelink }}{% if not forloop.last %},{% endif %}
     {% endif %}
 {% endfor %}
 }}}

 While it is perfectly verbose to put explicit filtering in the template,
 it seems to me that this is exactly the use case that custom manager
 methods (especially those that span related) were made for. This is a
 common use case that can be optimised in a short, semantic, performant
 way, and the benefit extends out to all models that reference User, making
 this a high ROI patch.

 As far as potential confusion about the exact meaning of active(), this is
 the reason that the django project takes such pride in having
 comprehensive docs, is it not? Also, the custom method could be changed to
 be is_active() so as to explicitly mirror the property and hence suggest
 function.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16611#comment:6>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to