Changeset 2106
- Timestamp:
- 07/06/10 12:38:59 (19 months ago)
- Location:
- trunk/loreality
- Files:
-
- 1 added
- 8 edited
-
development.db (modified) (previous)
-
loreality/controllers/main.py (modified) (1 diff)
-
loreality/controllers/mission.py (modified) (6 diffs)
-
loreality/controllers/squadron.py (modified) (5 diffs)
-
loreality/model/databases.py (modified) (1 diff)
-
loreality/model/form.py (modified) (1 diff)
-
loreality/templates/derived/page/mission.html (modified) (1 diff)
-
loreality/templates/derived/page/mission_edit.html (modified) (1 diff)
-
loreality/templates/derived/page/squadron_edit.html (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/loreality/loreality/controllers/main.py
r2105 r2106 21 21 c.heading = "LoReality" 22 22 c.content = _(""" 23 <h1>Welcome</h1> 24 <p>Welcome to LoReality server. This tool will help you to make a new step in the Lockon Reality by managing a real dynamic campaign. 23 Welcome to LoReality server. This tool will help you to make a new step in the Lockon Reality by managing a real dynamic campaign. 25 24 """) 26 25 return render('/derived/page/main.html') -
trunk/loreality/loreality/controllers/mission.py
r2105 r2106 21 21 import uuid 22 22 from pylons.i18n.translation import _, ungettext 23 class MisField: 24 name = "" 25 formtype = "" 26 def __init__( self, **kwargs): 27 self.__dict__.update( kwargs ) 28 23 29 24 30 class MissionController(BaseController): 31 misfields = [ 32 MisField(name="name" ,t_name=_("name") ,formtype="text"), 33 MisField(name="description" ,t_name=_("description") ,formtype="text"), 34 MisField(name="date" ,t_name=_("date") ,formtype="text"), 35 MisField(name="situation" ,t_name=_("situation") ,formtype="textarea"), 36 MisField(name="objectives" ,t_name=_("objectives") ,formtype="textarea"), 37 MisField(name="flightplan" ,t_name=_("flight plan") ,formtype="textarea"), 38 MisField(name="threat" ,t_name=_("threat") ,formtype="textarea"), 39 MisField(name="others" ,t_name=_("others") ,formtype="textarea") 40 ] 25 41 #-------------------------------------------------------------- 26 42 def _get_pilots(self, already_pilots): … … 29 45 for p in pilots: 30 46 if p not in already_pilots: 31 names.append( p.name)47 names.append( [p.id, p.name] ) 32 48 return names 33 49 … … 44 60 c.heading = mission.name 45 61 c.mission = mission 62 c.misfields = self.misfields 46 63 c.available_pilots = self._get_pilots(mission.pilots) 47 64 … … 75 92 abort(404) 76 93 77 mission.name = result["name"]78 mission.description = result["description"]79 mission.date = result["date"] 94 for f in self.misfields: 95 setattr(mission, f.name, result[f.name] ) 96 80 97 meta.Session.commit() 81 98 return self.view(id=id) … … 95 112 c.heading = "Edit %s"%mission.name 96 113 c.mission = mission 114 c.misfields = self.misfields 97 115 c.available_pilots = self._get_pilots(mission.pilots) 98 116 99 117 if not values: values = {} 100 values["name"] = mission.name 101 values["description"] = mission.description102 values["date"] = mission.date118 119 for f in self.misfields: 120 values[f.name] = getattr(mission, f.name ) 103 121 104 122 html = render('/derived/page/mission_edit.html') … … 119 137 abort(404) 120 138 pilot_q = meta.Session.query(model.Pilot) 121 pilot = pilot_q.filter_by( name=pilotid).first()139 pilot = pilot_q.filter_by(id=uuid.UUID(pilotid)).first() 122 140 if pilot is None: 123 141 abort(404) -
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') -
trunk/loreality/loreality/model/databases.py
r2105 r2106 68 68 date = sa.Column(sa.types.Date ) 69 69 70 #- Briefing part 71 situation = sa.Column(sa.types.String) 72 objectives = sa.Column(sa.types.String) 73 flightplan = sa.Column(sa.types.String) 74 threat = sa.Column(sa.types.String) 75 others = sa.Column(sa.types.String) 70 76 71 77 def __init__( self, name ): -
trunk/loreality/loreality/model/form.py
r2105 r2106 42 42 date = DateConverter() 43 43 44 situation = String() 45 objectives = String() 46 flightplan = String() 47 threat = String() 48 others = String() 44 49 50 class SquadronForm(Schema): 51 allow_extra_fields = True 52 filter_extra_fields = True 45 53 54 pre_validators = [variabledecode.NestedVariables()] 55 name = String(not_empty=True) 56 pilots = ForEach( Pilot()) 57 plane = String() 58 -
trunk/loreality/loreality/templates/derived/page/mission.html
r2105 r2106 8 8 %endif 9 9 </h2> 10 <h3>Date</h3> 11 < p>${c.mission.date}</p>12 <h3>Description</h3>13 <p>${c.mission.description}</p> 10 % for f in c.misfields: 11 <h3>${f.t_name.capitalize()}</h3> 12 <p>${getattr(c.mission, f.name)}</p> 13 %endfor 14 14 <h3>Pilots</h3> 15 15 <ul> -
trunk/loreality/loreality/templates/derived/page/mission_edit.html
r2105 r2106 7 7 % if h.auth.authorized(h.auth.is_creator): 8 8 ${h.form(h.url_for(controller='mission', action='process', id=c.mission.id))} 9 <label for="name">Name</label> 10 ${h.text(name='name')}<br />11 <label for=" description">Description</label>12 ${ h.text(name='description')}<br />13 <label for="date">Date</label>14 ${h.text(name='date')}<br /> 9 10 % for f in c.misfields: 11 <label for="${f.name}">${f.t_name.capitalize()}</label><br /> 12 ${eval("h."+ f.formtype +"(name='" + f.name+ "')")}<br /> 13 %endfor 14 15 15 ${h.submit(name="action", value="Modify")} 16 16 </fieldset>
Note: See TracChangeset
for help on using the changeset viewer.
