Changes between Version 13 and Version 14 of NewManipulators
- Timestamp:
- Mar 31, 2011, 10:12:15 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NewManipulators
v13 v14 33 33 * Custom form views become very simple, and intuitive. 34 34 * Validation aware models are harnessed in this system. 35 * Custom Manipulators could be defined in the model itself, which h ightens the sense of everything in one place. Likewise, it can be seperated out if it's too much code in one spot.35 * Custom Manipulators could be defined in the model itself, which heightens the sense of everything in one place. Likewise, it can be separated out if it's too much code in one spot. 36 36 * Defining Custom Manipulators allows one greater control of how the Admin deals with objects. Having a field automatically update with the author's User object would be a snap. Also, some options could move from the {{{class Admin:}}} into the Custom Manipulator, which would tighten things up a great deal. 37 37 * Making your own Admin app now becomes a lot easier. People often want to be able to simply plop a form down, and this gives them that ability. … … 70 70 71 71 To create a custom manipulator you have four functions that you may 72 want to override, each is a step in the manip lator process:72 want to override, each is a step in the manipulator process: 73 73 * __init__ 74 74 * convert … … 88 88 "Allows access of the fields via the brackets, like: manipulator['field_name']" 89 89 for f in self.fields: 90 if (f.name == k):90 if f.name == k: 91 91 return f 92 92 raise KeyError, "Could not find field with the name %r." % k … … 125 125 raise NotImplementedError 126 126 127 ### Intern eal functions ###127 ### Internal functions ### 128 128 def process(self, request): 129 129 "Perform the manipulation process." 130 if (not request.POST):130 if not request.POST: 131 131 raise self.form 132 132 self.request = request 133 self.data = copy_dict(request.POST) # copy_dict == lambda m: dict( (k, v) for k, v in m.items())133 self.data = copy_dict(request.POST) # copy_dict == lambda m: dict(m) 134 134 self.errors = {} 135 135 self._convert() … … 149 149 for field in self.fields: 150 150 name = field.name 151 if (name in self.data):151 if name in self.data: 152 152 try: 153 153 #~ self.data[name] = field.to_python(self.data[name]) … … 155 155 except (validators.ValidationError, validators.CriticalValidationError), e: 156 156 self.errors.setdefault(name, []).extend(e.messages) 157 if (self.errors):157 if self.errors: 158 158 raise self.form 159 159 self.convert(self.data) 160 if (self.errors):160 if self.errors: 161 161 raise self.form 162 162 … … 175 175 #~ self.errors.setdefault(name, []).extend(e.messages) 176 176 errors = field.validate(self.data) 177 if (errors):177 if errors: 178 178 self.errors.setdefault(name, []).extend(errors) 179 if (self.errors):179 if self.errors: 180 180 raise self.form 181 181 self.validate(self.data) 182 if (self.errors):182 if self.errors: 183 183 raise self.form 184 184 … … 220 220 def create(Model, data): 221 221 """ 222 Useful lin the .save of a custom manipulator, this will quickly create an object for you.222 Useful in the .save of a custom manipulator, this will quickly create an object for you. 223 223 """ 224 224 m = Model(**data)