Code

Changes between Version 13 and Version 14 of NewManipulators


Ignore:
Timestamp:
03/31/11 20:12:15 (3 years ago)
Author:
newacct
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NewManipulators

    v13 v14  
    3333 * Custom form views become very simple, and intuitive. 
    3434 * Validation aware models are harnessed in this system. 
    35  * Custom Manipulators could be defined in the model itself, which hightens 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. 
    3636 * 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. 
    3737 * 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. 
     
    7070 
    7171    To create a custom manipulator you have four functions that you may  
    72     want to override, each is a step in the maniplator process: 
     72    want to override, each is a step in the manipulator process: 
    7373        * __init__ 
    7474        * convert 
     
    8888        "Allows access of the fields via the brackets, like: manipulator['field_name']" 
    8989        for f in self.fields: 
    90             if (f.name == k): 
     90            if f.name == k: 
    9191                return f 
    9292        raise KeyError, "Could not find field with the name %r." % k 
     
    125125        raise NotImplementedError 
    126126     
    127     ### Interneal functions ### 
     127    ### Internal functions ### 
    128128    def process(self, request): 
    129129        "Perform the manipulation process." 
    130         if (not request.POST): 
     130        if not request.POST: 
    131131            raise self.form 
    132132        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) 
    134134        self.errors = {} 
    135135        self._convert() 
     
    149149        for field in self.fields: 
    150150            name = field.name 
    151             if (name in self.data): 
     151            if name in self.data: 
    152152                try: 
    153153                    #~ self.data[name] = field.to_python(self.data[name]) 
     
    155155                except (validators.ValidationError, validators.CriticalValidationError), e: 
    156156                    self.errors.setdefault(name, []).extend(e.messages) 
    157         if (self.errors): 
     157        if self.errors: 
    158158            raise self.form 
    159159        self.convert(self.data) 
    160         if (self.errors): 
     160        if self.errors: 
    161161            raise self.form 
    162162     
     
    175175                    #~ self.errors.setdefault(name, []).extend(e.messages) 
    176176            errors = field.validate(self.data) 
    177             if (errors): 
     177            if errors: 
    178178                self.errors.setdefault(name, []).extend(errors) 
    179         if (self.errors): 
     179        if self.errors: 
    180180            raise self.form 
    181181        self.validate(self.data) 
    182         if (self.errors): 
     182        if self.errors: 
    183183            raise self.form 
    184184     
     
    220220def create(Model, data): 
    221221    """ 
    222     Usefull in 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. 
    223223    """ 
    224224    m = Model(**data)