def request_create_group (request, user, language, group_name, slot): logger.debug ("user %s group_name %s slot %s" % (user, group_name, slot)) slot = urllib.unquote_plus(slot) group_type = 'public' if not user.has_empty_slot (): return language.user_has_no_empty_slots () type_and_slot_regex = re.compile("^\w+\s+\d$") slot_only_regex = re.compile("^\d$") if type_and_slot_regex.match(slot): (group_type, slot) = slot.split() if group_type != 'private': group_type = 'public' elif len(slot) > 1 and not slot_only_regex.match(slot): #only provided type without slot group_type = slot if group_type != 'private': group_type = 'public' #check to ensure its actually a group type slot = '' else: group_type = 'public' slot = '' msg_list = [] if slot is None or len(slot) < 1: logger.debug ("slot is none") slot = auto_alloc_slot(user) logger.info ("slot allocated %s" % slot) else: logger.debug ("slot is %s" % slot) regex = re.compile ('^[A-Za-z]') if not regex.match (group_name) or len(group_name) < 4 or len(group_name) > 60: msg_list.append (language.group_name_not_valid (group_name)) if slot >= 0 and not user.slot_is_empty (slot): msg_list.append (language.slot_not_free (slot)) # XXX calling this causes an error (and we've fixed the types as unchangeable for now) #if not Groups.is_valid_type (group_type): #ok = False #msg_list.append (language.invalid_group_type (group_type)) # that should take care of the race condition with lock: if not Groups.is_name_available (group_name): msg_list.append (language.group_name_not_available (group_name)) # TODO add suggestions if len(msg_list) > 0: msg_text = " ".join(msg_list) return msg_text # create group and assign it to the given slot, if one has been provided group = Groups.create (user, group_name, slot, group_type) return language.group_created (group_name, slot, group_type)