Code

Opened 7 years ago

Closed 7 years ago

#6020 closed (wontfix)

Allow group comparing with basestring

Reported by: italomaia <italo.maia@…> Owned by: nobody
Component: Contrib apps Version: master
Severity: Keywords: auth, group, improvement
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Sometimes, i have to check is a user is in a particular group(from auth), and i have to load the group
i'm checking against, before i can use the "in" operator. Something like this:

MyGroupName="badass_people"
group=Group.objects.get(name=MyGroupName) 
if group in user.groups:
    ...
else:
    ...

I would like to suggest the overwrite of the method cmp, so that something like this:

group="badass_people"
if group in user.groups:
    ...
else:
    ...

I believe the code to do so is something like this:

class Group(models.Model):
    #stuff stuff ...
    def __cmp__(self, group):
        if isinstance(group, basestring):
            return cmp(self.name,group)
    #more stuff...

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by Simon G <dev@…>

  • Keywords improvement added; improviment removed
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Group comparing with basestring to Allow group comparing with basestring
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

I'm really not a fan of this. Though it looks nice for the if 'group' in user.groups case, I don't think that "group" == some_group_object should be true. Strings and groups are very different beasts.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.