Adding a check to prevent duplicate channel names.

This commit is contained in:
Greg Taylor 2007-05-15 14:18:56 +00:00
parent 463197470e
commit 725b1b2ac0
2 changed files with 19 additions and 1 deletions

View file

@ -139,6 +139,12 @@ def cmd_ccreate(cdat):
if cname == '':
session.msg("You must supply a name!")
return
name_matches = functions_comsys.cname_search(cname, exact=True)
if name_matches:
session.msg("A channel with that name already exists.")
else:
# Create and set the object up.
cdat = {"name": cname, "owner": pobject}

View file

@ -42,4 +42,16 @@ def create_channel(cdat):
new_chan.header = "[%s]" % (ansi.parse_ansi(cdat["name"]),)
new_chan.set_owner(cdat["owner"])
new_chan.save()
return new_chan
return new_chan
def cname_search(search_text, exact=False):
"""
Searches for a particular channel name. Returns a QuerySet with the
results.
exact: (bool) Do an exact (case-insensitive) name match if true.
"""
if exact:
return CommChannel.objects.filter(name__iexact=search_text)
else:
return CommChannel.objects.filter(name__istartswith=search_text)