From 725b1b2ac08af82bac9486cd65a47b40e168b214 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 15 May 2007 14:18:56 +0000 Subject: [PATCH] Adding a check to prevent duplicate channel names. --- commands_comsys.py | 6 ++++++ functions_comsys.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/commands_comsys.py b/commands_comsys.py index d22d6bfc6f..2dc0e113ec 100644 --- a/commands_comsys.py +++ b/commands_comsys.py @@ -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} diff --git a/functions_comsys.py b/functions_comsys.py index 65ad2806e0..e8e4f62b7a 100644 --- a/functions_comsys.py +++ b/functions_comsys.py @@ -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 \ No newline at end of file + 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) \ No newline at end of file