From 32ffa258953c4ab9ae72e058063ccd46f37fdb36 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Mon, 25 Apr 2016 09:57:36 +1000 Subject: [PATCH] Adds util.all_arguments_optional --- registrasion/util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/registrasion/util.py b/registrasion/util.py index 3df54800..7179ceb5 100644 --- a/registrasion/util.py +++ b/registrasion/util.py @@ -14,3 +14,14 @@ def generate_access_code(): chars = string.uppercase + string.digits[1:] # 4 chars => 35 ** 4 = 1500625 (should be enough for anyone) return get_random_string(length=length, allowed_chars=chars) + + +def all_arguments_optional(ntcls): + ''' Takes a namedtuple derivative and makes all of the arguments optional. + ''' + + ntcls.__new__.__defaults__ = ( + (None,) * len(ntcls._fields) + ) + + return ntcls