Changes between Version 6 and Version 7 of NewManipulators
- Timestamp:
- Aug 21, 2006, 5:48:50 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NewManipulators
v6 v7 21 21 try: 22 22 m = Poll.CreateManipulator() 23 poll = m.process(request .POST)23 poll = m.process(request) 24 24 return HttpResponseRedirect('/poll/%d/' % poll.id) 25 25 except Form, form: … … 58 58 try: 59 59 m = Poll.CreateManipulator() 60 poll = m.process(request .POST)60 poll = m.process(request) 61 61 return HttpResponseRedirect('/poll/%d/' % poll.id) 62 62 except Form, form: … … 123 123 124 124 ### Interneal functions ### 125 def process(self, data):125 def process(self, request): 126 126 "Perform the manipulation process." 127 if (not data): 128 # Here we want to delete any data we have, just in case this manipulator is being re-used. 129 if 'data' in self.__dict__: 130 del self.data 131 if 'errors' in self.__dict__: 132 del self.errors 133 # Raise the form 134 raise self.form 135 self.data = copy_dict(data) # copy_dict -> lambda m: dict((k, v) for k, v in m.items()) 127 if (not request.POST): 128 raise self.form 129 self.request = request 130 self.data = copy_dict(data) 136 131 self.errors = {} 137 132 self._convert() … … 241 236 242 237 ### Custom Manipulator ### 243 class C ustomManipulator(Manipulator):238 class CreateManipulator(Manipulator): 244 239 def __init__(self, request): 245 240 self.fields = generate_fields(Poll) # Generate fields creates default fields for a Model … … 251 246 252 247 def save(self): 253 # do something with the data... 254 pass 248 poll = create(Poll, data) 249 # Here we'll also save our author as the current user. 250 # This assumes the Poll model has an author field 251 poll.author = self.request.user 252 poll.save() 253 return poll 255 254 256 255 ### Custom views ###