Changeset 2106 for trunk/loreality/loreality/controllers/squadron.py
- Timestamp:
- 07/06/10 12:38:59 (23 months ago)
- File:
-
- 1 edited
-
trunk/loreality/loreality/controllers/squadron.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/loreality/loreality/controllers/squadron.py
r2105 r2106 12 12 13 13 import loreality.lib.helpers as h 14 from loreality.model.form import CampaignForm, MissionForm14 from loreality.model.form import * 15 15 16 16 from authkit.authorize.pylons_adaptors import authorize … … 22 22 import uuid 23 23 24 class SquField: 25 name = "" 26 formtype = "" 27 def __init__( self, **kwargs): 28 self.__dict__.update( kwargs ) 29 30 24 31 class SquadronController(BaseController): 32 squfields = [ 33 SquField(name="name" ,t_name=_("name") ,formtype="text"), 34 SquField(name="plane" ,t_name=_("plane") ,formtype="text"), 35 ] 25 36 #-------------------------------------------------------------- 26 37 def _get_pilots(self, already_pilots=[]): … … 38 49 c.heading = _("Squadrons") 39 50 c.squadrons = squadrons 51 c.squfields = self.squfields 40 52 c.available_pilots = self._get_pilots() 41 53 … … 54 66 c.heading = squadron.name 55 67 c.squadron = squadron 68 c.squfields = self.squfields 56 69 c.available_pilots = self._get_pilots(squadron.pilots) 57 70 58 71 html = render('/derived/page/squadron.html') 59 72 return htmlfill.render(html, defaults=values, errors=errors) 73 #-------------------------------------------------------------- 74 def process(self, id=None): 75 action = request.params.getone('action') 76 values = dict(request.params) 77 # Don't use the values field for repopulation 78 del values['action'] 79 if action=='Modify': 80 # Assume we are trying to save the form 81 schema = SquadronForm() 82 try: 83 result = schema.to_python(dict(request.params), c) 84 except Invalid, e: 85 return self.edit( 86 id=id, 87 values=values, 88 errors=variabledecode.variable_encode( 89 e.unpack_errors() or {}, 90 add_repetitions=False 91 ) 92 ) 93 else: 94 squadron_q = meta.Session.query(model.Squadron) 95 squadron = squadron_q.filter_by(id=uuid.UUID(id)).first() 96 if squadron is None: 97 abort(404) 98 99 for f in self.squfields: 100 setattr(squadron, f.name, result[f.name] ) 101 102 meta.Session.commit() 103 return self.view(id=id) 104 else: 105 raise Exception('Invalid action %s'%action) 60 106 61 107 #-------------------------------------------------------------- … … 72 118 c.heading = "Edit %s"%squadron.name 73 119 c.squadron = squadron 120 c.squfields = self.squfields 74 121 c.available_pilots = self._get_pilots(squadron.pilots) 122 123 if not values: values = {} 124 125 for f in self.squfields: 126 values[f.name] = getattr(squadron, f.name ) 75 127 76 128 html = render('/derived/page/squadron_edit.html')
Note: See TracChangeset
for help on using the changeset viewer.
