From 4cb2617324ce6e2703f538bb168af21340c34c87 Mon Sep 17 00:00:00 2001 From: Michael King Date: Tue, 13 Jan 2009 07:21:41 +0000 Subject: [PATCH] Added extrapolated "name_exists" function. Note that this can move, I just put it where it made the most sense. Code that checks for account names and aliases can now be replaced with (assuming this is imported): functions_user.name_exists("username") If there is an alias match or an account match, it will return True. --- src/util/functions_user.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/util/functions_user.py diff --git a/src/util/functions_user.py b/src/util/functions_user.py new file mode 100644 index 000000000..11813643b --- /dev/null +++ b/src/util/functions_user.py @@ -0,0 +1,30 @@ +""" +User-related functions +""" +from django.contrib.auth.models import User + +from src.object.models import Attribute, Object +from src import defines_global + +def name_exists(uname): + """ + Searches for an account first by username, then by alias. + + uname: (string) A username or alias + + returns True or False + """ + + # Search for a user object with username = uname + account = User.objects.filter(username=uname) + # Look for any objects with an 'Alias' attribute that matches + # the uname + alias_matches = Object.objects.filter(attribute__attr_name__exact="ALIAS", + attribute__attr_value__iexact=uname).filter( + type=defines_global.OTYPE_PLAYER) + + if not account.count() == 0 or not alias_matches.count() == 0: + return True + + return False +