Changeset 2100
- Timestamp:
- 07/02/10 14:49:40 (19 months ago)
- Location:
- trunk/loreality
- Files:
-
- 17 added
- 9 edited
-
data/templates/base/index.html.py (modified) (9 diffs)
-
data/templates/component/campaign.html.py (added)
-
data/templates/derived/form (added)
-
data/templates/derived/form/campaign.html.py (added)
-
data/templates/derived/page/campaign.html.py (modified) (3 diffs)
-
data/templates/derived/page/campaign_edit.html.py (added)
-
data/templates/derived/page/mission.html.py (added)
-
data/templates/derived/page/mission_edit.html.py (added)
-
data/templates/derived/page/pilot.html.py (added)
-
development.db (modified) (previous)
-
generate.sh (added)
-
loreality/controllers/campaign.py (modified) (2 diffs)
-
loreality/controllers/mission.py (added)
-
loreality/controllers/pilot.py (added)
-
loreality/lib/auth.py (modified) (1 diff)
-
loreality/model/form.py (modified) (1 diff)
-
loreality/templates/base/index.html (modified) (1 diff)
-
loreality/templates/component/campaign.html (added)
-
loreality/templates/derived/page/campaign.html (modified) (1 diff)
-
loreality/templates/derived/page/campaign_edit.html (added)
-
loreality/templates/derived/page/mission.html (added)
-
loreality/templates/derived/page/mission_edit.html (added)
-
loreality/templates/derived/page/pilot.html (added)
-
loreality/tests/functional/test_mission.py (added)
-
loreality/tests/functional/test_pilot.py (added)
-
loreality/websetup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/loreality/data/templates/base/index.html.py
r2098 r2100 4 4 __M_locals_builtin = locals 5 5 _magic_number = 5 6 _modified_time = 127 7927792.1697247 _template_filename='/ home/dart/trunk/loreality/loreality/templates/base/index.html'6 _modified_time = 1278073648.668196 7 _template_filename='/media/divers/personnel/dev/dartsite.org/lotatc/trunk/loreality/loreality/templates/base/index.html' 8 8 _template_uri='/base/index.html' 9 9 _template_cache=cache.Cache(__name__, _modified_time) … … 74 74 __M_writer(u'\n ') 75 75 # SOURCE LINE 30 76 __M_writer(escape( self.heading()))76 __M_writer(escape(next.body())) 77 77 __M_writer(u'\n ') 78 78 # SOURCE LINE 31 79 __M_writer(escape(next.body()))80 __M_writer(u'\n ')81 # SOURCE LINE 3282 79 __M_writer(escape(self.footer())) 83 80 __M_writer(u'\n</body>\n</html>\n\n') 81 # SOURCE LINE 35 82 __M_writer(u'\n') 84 83 # SOURCE LINE 36 85 84 __M_writer(u'\n') … … 93 92 __M_writer(u'\n') 94 93 # SOURCE LINE 41 95 __M_writer(u'\n')96 # SOURCE LINE 4297 94 __M_writer(u'\n') 98 95 return '' … … 118 115 _mako_get_namespace(context, 'navigation')._populate(_import_ns, ['*']) 119 116 __M_writer = context.writer() 120 # SOURCE LINE 3 6117 # SOURCE LINE 35 121 118 __M_writer(u'LoReality') 122 119 return '' … … 132 129 navigation = _mako_get_namespace(context, 'navigation') 133 130 __M_writer = context.writer() 134 # SOURCE LINE 3 9131 # SOURCE LINE 38 135 132 __M_writer(escape(navigation.tabs())) 136 133 return '' … … 146 143 navigation = _mako_get_namespace(context, 'navigation') 147 144 __M_writer = context.writer() 148 # SOURCE LINE 40145 # SOURCE LINE 39 149 146 __M_writer(escape(navigation.menu())) 150 147 return '' … … 159 156 _mako_get_namespace(context, 'navigation')._populate(_import_ns, ['*']) 160 157 __M_writer = context.writer() 161 # SOURCE LINE 4 2158 # SOURCE LINE 41 162 159 __M_writer(u'<p><a href="#top">Top ^</a></p>') 163 160 return '' … … 172 169 _mako_get_namespace(context, 'navigation')._populate(_import_ns, ['*']) 173 170 __M_writer = context.writer() 174 # SOURCE LINE 3 8171 # SOURCE LINE 37 175 172 __M_writer(u'<a name="top"></a>') 176 173 return '' … … 186 183 c = _import_ns.get('c', context.get('c', UNDEFINED)) 187 184 __M_writer = context.writer() 188 # SOURCE LINE 4 1185 # SOURCE LINE 40 189 186 __M_writer(u'<h1>') 190 187 __M_writer(escape(c.heading or 'No Title')) -
trunk/loreality/data/templates/derived/page/campaign.html.py
r2099 r2100 4 4 __M_locals_builtin = locals 5 5 _magic_number = 5 6 _modified_time = 127 7995092.13793216 _modified_time = 1278079811.958066 7 7 _template_filename='/media/divers/personnel/dev/dartsite.org/lotatc/trunk/loreality/loreality/templates/derived/page/campaign.html' 8 8 _template_uri='/derived/page/campaign.html' … … 20 20 return context.namespaces[(__name__, name)] 21 21 def _mako_generate_namespaces(context): 22 pass 22 # SOURCE LINE 2 23 ns = runtime.Namespace('campaign', context._clean_inheritance_tokens(), templateuri='/component/campaign.html', callables=None, calling_uri=_template_uri, module=None) 24 context.namespaces[(__name__, 'campaign')] = ns 25 23 26 def _mako_inherit(template, context): 24 27 _mako_generate_namespaces(context) … … 28 31 try: 29 32 __M_locals = __M_dict_builtin(pageargs=pageargs) 30 c = context.get('c', UNDEFINED) 33 _import_ns = {} 34 _mako_get_namespace(context, 'campaign')._populate(_import_ns, ['*']) 35 h = _import_ns.get('h', context.get('h', UNDEFINED)) 36 c = _import_ns.get('c', context.get('c', UNDEFINED)) 37 campaign = _mako_get_namespace(context, 'campaign') 31 38 __M_writer = context.writer() 32 39 # SOURCE LINE 1 33 __M_writer(u'\n <h2>')40 __M_writer(u'\n') 34 41 # SOURCE LINE 2 42 __M_writer(u'') 43 # SOURCE LINE 3 44 __M_writer(u'\n\n<h2>') 45 # SOURCE LINE 5 35 46 __M_writer(escape(c.campaign_title)) 36 47 __M_writer(u'</h2>\n<ul>\n') 37 # SOURCE LINE 4 38 for campaign in c.campaigns: 39 # SOURCE LINE 5 40 __M_writer(u' <li><p>') 41 __M_writer(escape(campaign.name)) 42 __M_writer(u'</p>\n <ul>\n') 43 # SOURCE LINE 7 44 for mission in campaign.missions: 45 # SOURCE LINE 8 46 __M_writer(u' <li> ') 48 # SOURCE LINE 7 49 for camp in c.campaigns: 50 # SOURCE LINE 8 51 __M_writer(u' <li>') 52 __M_writer(escape(camp.name)) 53 __M_writer(u'\n') 54 # SOURCE LINE 9 55 if h.auth.authorized(h.auth.is_creator): 56 # SOURCE LINE 10 57 __M_writer(u' <a href=') 58 __M_writer(escape(h.url_for(controller='campaign', action='edit',id=camp.id) )) 59 __M_writer(u'>[Edit]</a>\n') 60 # SOURCE LINE 12 61 __M_writer(u' <ul>\n') 62 # SOURCE LINE 13 63 for mission in camp.missions: 64 # SOURCE LINE 14 65 __M_writer(u' <li> <a href=') 66 __M_writer(escape(h.url_for(controller='mission', action='view',id=mission.id) )) 67 __M_writer(u'>') 47 68 __M_writer(escape(mission.name)) 48 __M_writer(u' (\n')49 # SOURCE LINE 969 __M_writer(u'</a>(\n') 70 # SOURCE LINE 15 50 71 for pilot in mission.pilots: 51 # SOURCE LINE 10 52 __M_writer(u' ') 72 # SOURCE LINE 16 73 __M_writer(u' <a href=') 74 __M_writer(escape(h.url_for(controller='pilot', action='view',id=pilot.id) )) 75 __M_writer(u'>') 53 76 __M_writer(escape(pilot.name)) 54 __M_writer(u' - \n') 55 # SOURCE LINE 12 56 __M_writer(u' )</li>\n') 57 # SOURCE LINE 14 77 __M_writer(u'</a> - \n') 78 # SOURCE LINE 18 79 __M_writer(u' )\n') 80 # SOURCE LINE 19 81 if h.auth.authorized(h.auth.is_creator): 82 # SOURCE LINE 20 83 __M_writer(u' <a href=') 84 __M_writer(escape(h.url_for(controller='mission', action='edit',id=mission.id) )) 85 __M_writer(u'>[Edit]</a>\n <a href=') 86 # SOURCE LINE 21 87 __M_writer(escape(h.url_for(missionid=mission.id, controller='campaign', action='delete',id=camp.id) )) 88 __M_writer(u'>[Del]</a>\n') 89 # SOURCE LINE 23 90 __M_writer(u' </li>\n') 91 # SOURCE LINE 25 58 92 __M_writer(u' </ul></li>\n') 59 # SOURCE LINE 1693 # SOURCE LINE 27 60 94 __M_writer(u'</ul>\n') 95 # SOURCE LINE 28 96 __M_writer(escape(campaign.add_campaign())) 97 __M_writer(u'\n') 61 98 return '' 62 99 finally: -
trunk/loreality/loreality/controllers/campaign.py
r2099 r2100 8 8 import loreality.model as model 9 9 10 import loreality.lib.helpers as h 11 from loreality.model.form import * 12 13 from authkit.authorize.pylons_adaptors import authorize 14 from pylons.decorators import validate 15 16 from formencode import htmlfill, variabledecode 17 from formencode.validators import Invalid 18 import uuid 10 19 11 20 log = logging.getLogger(__name__) … … 13 22 class CampaignController(BaseController): 14 23 15 def index(self ):24 def index(self, values=None, errors=None ): 16 25 c.title = "LoReality" 17 26 c.heading = "Campaign" 18 c.campaign_title = "My Campaign"19 27 c.campaigns = meta.Session.query(model.Campaign).all() 20 28 21 return render('/derived/page/campaign.html') 29 html = render('/derived/page/campaign.html') 30 return htmlfill.render(html, defaults=values, errors=errors) 31 32 def process(self, id=None): 33 action = request.params.getone('action') 34 values = dict(request.params) 35 # Don't use the values field for repopulation 36 del values['action'] 37 if action=='Add campaign': 38 # Assume we are trying to save the form 39 schema = CampaignNameForm() 40 try: 41 result = schema.to_python(dict(request.params), c) 42 except Invalid, e: 43 return self.index( 44 values=values, 45 errors=variabledecode.variable_encode( 46 e.unpack_errors() or {}, 47 add_repetitions=False 48 ) 49 ) 50 else: 51 camp = model.Campaign( result['name_campaign'] ) 52 meta.Session.add(camp) 53 meta.Session.commit() 54 return self.index() 55 elif action=='Add mission': 56 # Assume we are trying to save the form 57 schema = MissionNameForm() 58 try: 59 result = schema.to_python(dict(request.params), c) 60 except Invalid, e: 61 return self.index( 62 values=values, 63 errors=variabledecode.variable_encode( 64 e.unpack_errors() or {}, 65 add_repetitions=False 66 ) 67 ) 68 else: 69 campaign_q = meta.Session.query(model.Campaign) 70 campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 71 if campaign is None: 72 abort(404) 73 74 mis = model.Mission( result["name_mission"] ) 75 meta.Session.add( mis ) 76 campaign.missions.append( mis ) 77 78 meta.Session.commit() 79 return self.edit(id) 80 elif action=='Modify': 81 # Assume we are trying to save the form 82 schema = CampaignForm() 83 try: 84 result = schema.to_python(dict(request.params), c) 85 except Invalid, e: 86 return self.index( 87 values=values, 88 errors=variabledecode.variable_encode( 89 e.unpack_errors() or {}, 90 add_repetitions=False 91 ) 92 ) 93 else: 94 campaign_q = meta.Session.query(model.Campaign) 95 campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 96 if campaign is None: 97 abort(404) 98 99 campaign.name = result["name"] 100 meta.Session.commit() 101 return self.edit(id=id) 102 else: 103 raise Exception('Invalid action %s'%action) 104 105 @authorize(h.auth.is_creator) 106 def edit(self, id=None, values=None, errors=None ): 107 if id is None: 108 abort(404) 109 campaign_q = meta.Session.query(model.Campaign) 110 campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 111 if campaign is None: 112 abort(404) 113 114 c.title = "LoReality" 115 c.heading = "Edit %s"%campaign.name 116 c.campaign = campaign 117 118 if not values: values = {} 119 values["name"] = campaign.name 120 121 html = render('/derived/page/campaign_edit.html') 122 return htmlfill.render(html, defaults=values, errors=errors) 123 124 @authorize(h.auth.is_creator) 125 def delete(self, id): 126 values = dict(request.params) 127 missionid = values["missionid"] 128 if id is None: 129 abort(404) 130 campaign_q = meta.Session.query(model.Campaign) 131 campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 132 if campaign is None: 133 abort(404) 134 135 if missionid is None: 136 abort(404) 137 mission_q = meta.Session.query(model.Mission) 138 mission = mission_q.filter_by(id=uuid.UUID(missionid)).first() 139 if mission is None: 140 abort(404) 141 142 #- del now 143 campaign.missions.remove( mission ) 144 meta.Session.delete( mission ) 145 meta.Session.commit() 146 return self.edit( id ) 147 148 @authorize(h.auth.is_creator) 149 def deletecampaign(self, id): 150 if id is None: 151 abort(404) 152 campaign_q = meta.Session.query(model.Campaign) 153 campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 154 if campaign is None: 155 abort(404) 156 157 #- del now 158 for mis in campaign.missions: 159 campaign.missions.remove( mis ) 160 meta.Session.delete( mis ) 161 meta.Session.delete( campaign ) 162 meta.Session.commit() 163 return self.index() -
trunk/loreality/loreality/lib/auth.py
r2097 r2100 1 from authkit.permissions import ValidAuthKitUser 1 from authkit.permissions import ValidAuthKitUser, HasAuthKitRole 2 2 from authkit.authorize.pylons_adaptors import authorized 3 3 4 4 is_valid_user = ValidAuthKitUser() 5 is_creator = HasAuthKitRole(['creator']) 6 -
trunk/loreality/loreality/model/form.py
r2097 r2100 1 import formencode 1 from formencode.schema import Schema 2 from formencode.validators import Invalid, FancyValidator 3 from formencode.validators import Int, DateConverter, String, OneOf 4 from formencode import variabledecode 5 from formencode import htmlfill 6 from formencode.foreach import ForEach 7 from formencode.api import NoDefault 2 8 3 class LoginForm(formencode.Schema):9 class CampaignNameForm(Schema): 4 10 allow_extra_fields = True 5 11 filter_extra_fields = True 6 login = formencode.validators.MinLength(4)7 password = formencode.validators.MinLength(4)8 12 13 pre_validators = [variabledecode.NestedVariables()] 14 name_campaign = String(not_empty=True) 15 16 class CampaignForm(Schema): 17 allow_extra_fields = True 18 filter_extra_fields = True 19 20 pre_validators = [variabledecode.NestedVariables()] 21 name = String(not_empty=True) 22 23 class MissionNameForm(Schema): 24 allow_extra_fields = True 25 filter_extra_fields = True 26 27 pre_validators = [variabledecode.NestedVariables()] 28 name_mission = String(not_empty=True) 29 30 class Pilot( Schema ): 31 name = String(not_empty=True) 32 33 class MissionForm(Schema): 34 allow_extra_fields = True 35 filter_extra_fields = True 36 37 pre_validators = [variabledecode.NestedVariables()] 38 name = String(not_empty=True) 39 pilots = ForEach( Pilot()) 40 41 42 -
trunk/loreality/loreality/templates/base/index.html
r2098 r2100 28 28 </div> 29 29 ${self.menu()} 30 ${self.heading()}31 30 ${next.body()} 32 31 ${self.footer()} -
trunk/loreality/loreality/templates/derived/page/campaign.html
r2099 r2100 1 1 <%inherit file="/base/index.html"/> 2 <%namespace name="campaign" file="/component/campaign.html" import="*" />\ 3 4 2 5 <h2>${c.campaign_title}</h2> 3 6 <ul> 4 % for campaign in c.campaigns: 5 <li><p>${campaign.name}</p> 7 % for camp in c.campaigns: 8 <li>${camp.name} 9 % if h.auth.authorized(h.auth.is_creator): 10 <a href=${h.url_for(controller='campaign', action='edit',id=camp.id) }>[Edit]</a> 11 %endif 6 12 <ul> 7 % for mission in camp aign.missions:8 <li> ${mission.name}(13 % for mission in camp.missions: 14 <li> <a href=${h.url_for(controller='mission', action='view',id=mission.id) }>${mission.name}</a>( 9 15 % for pilot in mission.pilots: 10 ${pilot.name}-16 <a href=${h.url_for(controller='pilot', action='view',id=pilot.id) }>${pilot.name}</a> - 11 17 % endfor 12 )</li> 18 ) 19 % if h.auth.authorized(h.auth.is_creator): 20 <a href=${h.url_for(controller='mission', action='edit',id=mission.id) }>[Edit]</a> 21 <a href=${h.url_for(missionid=mission.id, controller='campaign', action='delete',id=camp.id) }>[Del]</a> 22 %endif 23 </li> 13 24 % endfor 14 25 </ul></li> 15 26 % endfor 16 27 </ul> 28 ${campaign.add_campaign()} -
trunk/loreality/loreality/websetup.py
r2099 r2100 24 24 25 25 log.info("Adding roles and uses...") 26 27 #- Add roles 26 28 users.role_create("admin") 29 users.role_create("creator") 30 27 31 users.user_create("DArt", password="admin") 28 32 users.user_add_role("DArt", role="admin" ) 33 users.user_add_role("DArt", role="creator" ) 34 35 users.user_create("Tolteque", password="admin") 29 36 30 37 log.info("Adding mission...")
Note: See TracChangeset
for help on using the changeset viewer.
