Changes between Version 6 and Version 7 of NewManipulators


Ignore:
Timestamp:
Aug 21, 2006, 5:48:50 PM (18 years ago)
Author:
brantley
Comment:

Oversight corrected

Legend:

Unmodified
Added
Removed
Modified
  • NewManipulators

    v6 v7  
    2121    try:
    2222        m = Poll.CreateManipulator()
    23         poll = m.process(request.POST)
     23        poll = m.process(request)
    2424        return HttpResponseRedirect('/poll/%d/' % poll.id)
    2525    except Form, form:
     
    5858    try:
    5959        m = Poll.CreateManipulator()
    60         poll = m.process(request.POST)
     60        poll = m.process(request)
    6161        return HttpResponseRedirect('/poll/%d/' % poll.id)
    6262    except Form, form:
     
    123123   
    124124    ### Interneal functions ###
    125     def process(self, data):
     125    def process(self, request):
    126126        "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)
    136131        self.errors = {}
    137132        self._convert()
     
    241236
    242237### Custom Manipulator ###
    243 class CustomManipulator(Manipulator):
     238class CreateManipulator(Manipulator):
    244239    def __init__(self, request):
    245240        self.fields = generate_fields(Poll)   # Generate fields creates default fields for a Model
     
    251246   
    252247    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
    255254
    256255### Custom views ###
Back to Top