Example #1
0
    def __init_validators(self):
        for k, obj in self.fields.items():
            func = getattr(self, 'validate_%s' % obj.field_name, None)
            if func and callable(func):
                obj.validators.insert(0, func)

        func = getattr(self, 'form_validate', None)
        if func and callable(func):
            self.validators.append(func)
Example #2
0
 def get(self, key, default=Empty, creator=Empty, expire=None):
     """
     :para default: if default is callable then invoke it, save it and return it
     """
     try:
         return self.storage.get(key)
     except KeyError as e:
         if creator is not Empty:
             if callable(creator):
                 v = creator()
             else:
                 v = creator
             self.set(key, v, expire)
             return v
         else:
             if default is not Empty:
                 if callable(default):
                     v = default()
                     return v
                 return default
             else:
                 raise
Example #3
0
 def set(self, key, value=None, expire=None):
     if callable(value):
         value = value()
     return self.storage.set(key, value, expire or self.expiry_time)
Example #4
0
 def __setitem__(self, key, value):
     if callable(value):
         value = value()
     return self.set(key, value)
Example #5
0
 def get_choices(self, value=None):
     if callable(self.choices):
         return self.choices()
     else:
         return self.choices
Example #6
0
 def get_commands(self, global_options):
     if callable(self.commands):
         commands = self.commands(global_options)
     else:
         commands = self.commands
     return commands