Changeset 2104


Ignore:
Timestamp:
07/05/10 12:56:53 (19 months ago)
Author:
dart
Message:

LoReality?:
o Add squadrons, pilots.
o Lot of fix
o Some cosmetics

Location:
trunk/loreality
Files:
8 added
2 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/loreality/development.ini

    r2099 r2104  
    4848authkit.cookie.secret = aoeuidts 
    4949authkit.cookie.signoutpath = /signout 
     50authkit.form.template.obj = loreality.lib.auth:render_signin 
    5051 
    5152# Logging configuration 
  • trunk/loreality/loreality/config/deployment.ini_tmpl

    r2097 r2104  
    3434sqlalchemy.url = sqlite:///production.db 
    3535 
     36# Auth 
     37authkit.setup.enable = true 
     38authkit.setup.method = form, cookie 
     39authkit.form.authenticate.user.type = authkit.users.sqlalchemy_driver:UsersFromDatabase 
     40authkit.form.authenticate.user.data = loreality.model 
     41#authkit.form.authenticate.user.data = dart:admin 
     42authkit.cookie.secret = aoeuidts 
     43authkit.cookie.signoutpath = /signout 
     44authkit.form.template.obj = loreality.lib.auth:render_signin 
     45 
     46 
    3647# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* 
    3748# Debug mode will enable the interactive debugging tool, allowing ANYONE to 
  • trunk/loreality/loreality/controllers/account.py

    r2098 r2104  
    1111class AccountController(BaseController): 
    1212 
     13    #-------------------------------------------------------------- 
    1314    def signin(self): 
    1415        if not request.environ.get('REMOTE_USER'): 
     
    1819            return redirect_to(h.url_for(controller='main', action='index')) 
    1920 
     21    #-------------------------------------------------------------- 
    2022    def signout(self): 
    2123        # The actual removal of the AuthKit cookie occurs when the response passes 
  • trunk/loreality/loreality/controllers/campaign.py

    r2100 r2104  
    2222class CampaignController(BaseController): 
    2323 
     24    #-------------------------------------------------------------- 
    2425    def index(self, values=None, errors=None ): 
    25         c.title = "LoReality" 
    26         c.heading = "Campaign" 
     26        c.title = "All campaigns" 
     27        c.heading = "Campaigns" 
    2728        c.campaigns = meta.Session.query(model.Campaign).all() 
     29 
     30        html = render('/derived/page/overview_campaign.html') 
     31        return  htmlfill.render(html, defaults=values, errors=errors) 
     32 
     33    #-------------------------------------------------------------- 
     34    def view(self, id, values=None, errors=None ): 
     35        if id is None: 
     36            abort(404) 
     37        campaign_q = meta.Session.query(model.Campaign) 
     38        campaign = campaign_q.filter_by(id=uuid.UUID(id)).first() 
     39        if campaign is None: 
     40            abort(404) 
     41 
     42        c.title = campaign.name 
     43        c.heading = "Campaigns" 
     44        c.campaign = campaign 
    2845 
    2946        html = render('/derived/page/campaign.html') 
    3047        return  htmlfill.render(html, defaults=values, errors=errors) 
    3148 
     49    #-------------------------------------------------------------- 
    3250    def process(self, id=None): 
    3351        action = request.params.getone('action') 
     
    98116 
    99117                campaign.name = result["name"] 
     118                campaign.description = result["description"] 
    100119                meta.Session.commit() 
    101                 return self.edit(id=id)  
     120                return self.view(id=id)  
    102121        else: 
    103122            raise Exception('Invalid action %s'%action) 
    104123 
     124    #-------------------------------------------------------------- 
    105125    @authorize(h.auth.is_creator) 
    106126    def edit(self, id=None, values=None, errors=None  ): 
     
    112132            abort(404) 
    113133 
    114         c.title = "LoReality" 
    115         c.heading = "Edit %s"%campaign.name 
     134        c.title = "Edit %s"%campaign.name 
     135        c.heading = "Campaigns" 
    116136        c.campaign = campaign 
    117137 
    118138        if not values: values = {} 
    119139        values["name"] = campaign.name 
     140        values["description"] = campaign.description 
    120141 
    121142        html = render('/derived/page/campaign_edit.html') 
    122143        return  htmlfill.render(html, defaults=values, errors=errors) 
    123144 
     145    #-------------------------------------------------------------- 
    124146    @authorize(h.auth.is_creator) 
    125147    def delete(self, id): 
     
    146168        return self.edit( id ) 
    147169 
     170    #-------------------------------------------------------------- 
    148171    @authorize(h.auth.is_creator) 
    149172    def deletecampaign(self, id): 
  • trunk/loreality/loreality/controllers/mission.py

    r2100 r2104  
    2222 
    2323class MissionController(BaseController): 
     24    #-------------------------------------------------------------- 
     25    def _get_pilots(self, already_pilots): 
     26        pilots = meta.Session.query(model.Pilot).all() 
     27        names = [] 
     28        for p in pilots: 
     29            if p not in already_pilots: 
     30                names.append( p.name ) 
     31        return names 
    2432 
     33    #-------------------------------------------------------------- 
    2534    def view(self, id, values=None, errors=None ): 
    2635        if id is None: 
     
    3443        c.heading = mission.name 
    3544        c.mission = mission 
     45        c.available_pilots = self._get_pilots(mission.pilots) 
    3646 
    3747        html = render('/derived/page/mission.html') 
    3848        return  htmlfill.render(html, defaults=values, errors=errors) 
    3949 
     50    #-------------------------------------------------------------- 
    4051    def process(self, id=None): 
    4152        action = request.params.getone('action') 
     
    6778        else: 
    6879            raise Exception('Invalid action %s'%action) 
     80    #-------------------------------------------------------------- 
    6981    @authorize(h.auth.is_creator) 
    7082    def edit(self, id=None, values=None, errors=None  ): 
     
    7991        c.heading = "Edit %s"%mission.name 
    8092        c.mission = mission 
     93        c.available_pilots = self._get_pilots(mission.pilots) 
    8194 
    8295        if not values: values = {} 
     
    8598        html = render('/derived/page/mission_edit.html') 
    8699        return  htmlfill.render(html, defaults=values, errors=errors) 
     100    #-------------------------------------------------------------- 
    87101    @authorize(h.auth.is_creator) 
    88102    def addpilot(self, id): 
    89103        values = dict(request.params) 
    90         pilotid = values["pilotid"] 
     104        pilotid = values["Pilot"] 
    91105        if id is None: 
    92106            abort(404) 
     
    99113            abort(404) 
    100114        pilot_q = meta.Session.query(model.Pilot) 
    101         pilot = pilot_q.filter_by(id=uuid.UUID(pilotid)).first() 
     115        pilot = pilot_q.filter_by(name=pilotid).first() 
    102116        if pilot is None: 
    103117            abort(404) 
    104118        
    105119        #- del now 
    106         mission.pilots.add( pilot ) 
     120        mission.pilots.append( pilot ) 
    107121        meta.Session.commit() 
    108122        return self.edit( id ) 
     123    #-------------------------------------------------------------- 
    109124    @authorize(h.auth.is_creator) 
    110125    def removepilot(self, id): 
  • trunk/loreality/loreality/controllers/pilot.py

    r2100 r2104  
    2424class PilotController(BaseController): 
    2525 
     26    #-------------------------------------------------------------- 
     27    def index(self, values=None, errors=None ): 
     28        c.heading = "Pilots" 
     29        c.title = "All pilots" 
     30 
     31        pilot_q = meta.Session.query(model.Pilot).order_by( model.Pilot.name ) 
     32        c.pilots = pilot_q.all() 
     33 
     34        html = render('/derived/page/overview_pilot.html') 
     35        return  htmlfill.render(html, defaults=values, errors=errors) 
     36    #-------------------------------------------------------------- 
    2637    def view(self, id, values=None, errors=None ): 
    2738        if id is None: 
     
    3243            abort(404) 
    3344 
    34         c.title = "LoReality" 
    35         c.heading = pilot.name 
     45        c.heading = "Pilots" 
     46        c.title = pilot.name 
    3647        c.pilot = pilot 
    3748 
     
    3950        return  htmlfill.render(html, defaults=values, errors=errors) 
    4051 
     52    #-------------------------------------------------------------- 
    4153    @authorize(h.auth.is_creator) 
    4254    def edit(self, id=None, values=None, errors=None  ): 
     
    4860            abort(404) 
    4961 
    50         c.title = "LoReality" 
    51         c.heading = "Edit %s"%pilot.name 
     62        c.heading = "Pilots" 
     63        c.title = "Edit %s"%pilot.name 
    5264        c.pilot = pilot 
    5365 
  • trunk/loreality/loreality/lib/auth.py

    r2100 r2104  
    11from authkit.permissions import ValidAuthKitUser, HasAuthKitRole 
    22from authkit.authorize.pylons_adaptors import authorized 
     3from pylons.templating import render_mako as render 
     4 
    35 
    46is_valid_user = ValidAuthKitUser() 
    57is_creator = HasAuthKitRole(['creator']) 
     8is_admin = HasAuthKitRole(['admin']) 
     9is_leader = HasAuthKitRole(['leader']) 
    610 
     11def render_signin(): 
     12    result = render('/derived/account/signin.html') 
     13    result = result.replace('%', '%%').replace('FORM_ACTION', '%s') 
     14    return render('/derived/account/signin.html') 
     15 
  • trunk/loreality/loreality/model/databases.py

    r2099 r2104  
    4545    id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 
    4646    name = sa.Column(sa.types.String, nullable=False) 
     47    description = sa.Column(sa.types.String) 
    4748 
    4849    missions = orm.relation("Mission", backref="campaign") 
     
    6970        self.name = name 
    7071#---------------------------------------------------------------- 
     72class Squadron(Base): 
     73    __tablename__ = 'squadrons' 
     74    id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 
     75    name = sa.Column(sa.types.String, nullable=False) 
     76    plane = sa.Column(sa.types.String) 
     77 
     78    pilots = orm.relation("Pilot", backref="squadron") 
     79 
     80 
     81    def __init__( self, name ): 
     82        self.name = name 
     83#---------------------------------------------------------------- 
    7184class Pilot(Base): 
    7285    __tablename__ = 'pilots' 
    7386    id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 
    7487    name = sa.Column(sa.types.String, nullable=False) 
     88    login = sa.Column(sa.types.String, nullable=False) 
     89    squadron_id = sa.Column(UUID(), ForeignKey('squadrons.id')) 
    7590 
    7691 
    77     def __init__( self, name ): 
     92    def __init__( self, name, login ): 
    7893        self.name = name 
     94        self.login = login 
  • trunk/loreality/loreality/model/form.py

    r2100 r2104  
    2020    pre_validators = [variabledecode.NestedVariables()] 
    2121    name =  String(not_empty=True) 
     22    description =  String() 
    2223 
    2324class MissionNameForm(Schema): 
  • trunk/loreality/loreality/public/style.css

    r2102 r2104  
    2323 border-left: 1px solid #000; 
    2424 padding-left: 3px; 
    25   
     25} 
    2626 
     27/* HEADING */ 
     28h1 { 
     29    width: 100%; 
     30    text-align: center; 
     31     color: yellow; 
    2732} 
     33 
     34h2{ 
     35    border-bottom: solid white 1px; 
     36} 
     37 
     38h3{ 
     39    border-bottom: solid white 1px; 
     40    margin-left: 5px; 
     41} 
     42 
  • trunk/loreality/loreality/templates/component/campaign.html

    r2100 r2104  
    2323</%def> 
    2424 
    25 <%def name="add_pilot(mission_id)"> 
     25<%def name="add_pilot(mission_id, available_pilots)"> 
    2626% if h.auth.authorized(h.auth.is_creator): 
    2727    ${h.form(h.url_for(controller='mission', action='addpilot', id=mission_id))} 
    2828    <fieldset><legend>Add a new pilot</legend> 
    2929 
    30         <label for="name_${name}">Name</label><br /> 
    31     ${h.text(name='name_pilot')} 
    32     ${h.submit(name="action", value='process')} 
     30    ${h.select( 
     31        "Pilot", 
     32        id='pilotid', 
     33        selected_values=[], 
     34        options=available_pilots, 
     35    )} 
     36    ${h.submit(name="action", value='Add')} 
    3337    </fieldset> 
    3438    ${h.end_form()} 
    3539%endif 
    3640</%def> 
     41<%def name="add_pilot_to_squadron(squadron_id, available_pilots)"> 
     42% if h.auth.authorized(h.auth.is_creator): 
     43    ${h.form(h.url_for(controller='squadron', action='addpilot', id=squadron_id))} 
     44    <fieldset><legend>Add a new pilot</legend> 
     45 
     46    ${h.select( 
     47        "Pilot", 
     48        id='pilotid', 
     49        selected_values=[], 
     50        options=available_pilots, 
     51    )} 
     52    ${h.submit(name="action", value='Add')} 
     53    </fieldset> 
     54    ${h.end_form()} 
     55%endif 
     56</%def> 
  • trunk/loreality/loreality/templates/component/navigation.html

    r2102 r2104  
    1212        <li> <a href=${h.url_for('/')}>Home</a> </li> 
    1313                % if h.auth.authorized(h.auth.is_valid_user) and not (request.urlvars['controller'] == 'account' and request.urlvars['action'] == 'signout'): 
    14         <li> <a href=${h.url_for(controller='campaign', action='index')}>Campaign</a> </li> 
     14        <li> <a href=${h.url_for(controller='campaign', action='index')}>Campaigns</a> </li> 
     15        <li> <a href=${h.url_for(controller='squadron', action='index')}>Squadrons</a> </li> 
     16        <li> <a href=${h.url_for(controller='pilot', action='index')}>Pilots</a> </li> 
    1517                % endif 
    1618</ul> 
  • trunk/loreality/loreality/templates/derived/page/campaign.html

    r2100 r2104  
    33 
    44 
    5 <h2>${c.campaign_title}</h2> 
    6 <ul> 
    7 % for camp in c.campaigns: 
    8     <li>${camp.name} 
     5<h2>${c.campaign.name} 
    96% if h.auth.authorized(h.auth.is_creator): 
    10     <a href=${h.url_for(controller='campaign', action='edit',id=camp.id) }>[Edit]</a> 
     7    <a href=${h.url_for(controller='campaign', action='edit',id=c.campaign.id) }>[Edit]</a> 
    118%endif 
     9</h2> 
     10<h3>Description</h3> 
     11<p>${c.campaign.description}</p> 
     12<h3>Missions</h3> 
    1213    <ul> 
    13     % for mission in camp.missions: 
     14    % for mission in c.campaign.missions: 
    1415    <li> <a href=${h.url_for(controller='mission', action='view',id=mission.id) }>${mission.name}</a>( 
    1516    % for pilot in mission.pilots: 
     
    1920% if h.auth.authorized(h.auth.is_creator): 
    2021    <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    <a href=${h.url_for(missionid=mission.id, controller='campaign', action='delete',id=c.campaign.id) }>[Del]</a> 
    2223%endif 
    2324        </li> 
    2425    % endfor 
    2526    </ul></li> 
    26 % endfor 
    27 </ul> 
    28 ${campaign.add_campaign()} 
     27${campaign.add_mission(c.campaign.id)} 
     28% if h.auth.authorized(h.auth.is_creator): 
     29<a href=${h.url_for(controller='campaign', action='deletecampaign',id=c.campaign.id) }>[Delete the campaign]</a></li> 
     30%endif 
     31<a href=${h.url_for(controller='campaign', action='index') }>[Back to overview]</a></li> 
  • trunk/loreality/loreality/templates/derived/page/campaign_edit.html

    r2100 r2104  
    33 
    44 
    5 <h2>${c.campaign.name}</h2> 
     5<h2><a href=${h.url_for(controller='campaign', action='view',id=c.campaign.id) }>${c.campaign.name}</a></h2> 
    66 
    77% if h.auth.authorized(h.auth.is_creator): 
    88    ${h.form(h.url_for(controller='campaign', action='process', id=c.campaign.id))} 
    9     <label for="name">Name</label><br /> 
    10     ${h.text(name='name')} 
     9    <label for="name">Name</label> 
     10    ${h.text(name='name')}<br /> 
     11    <label for="description">Description</label> 
     12    ${h.text(name='description')}<br /> 
    1113    ${h.submit(name="action", value="Modify")} 
    12     </fieldset> 
    1314    ${h.end_form()} 
    1415%endif 
     
    2526</ul> 
    2627${campaign.add_mission(c.campaign.id)} 
    27 <a href=${h.url_for(controller='campaign', action='deletecampaign',id=c.campaign.id) }>[Delete the campagnain]</a></li> 
     28<a href=${h.url_for(controller='campaign', action='deletecampaign',id=c.campaign.id) }>[Delete the campaign]</a></li> 
  • trunk/loreality/loreality/templates/derived/page/mission.html

    r2100 r2104  
    33 
    44 
    5 <h2>${c.mission.name}</h2> 
    6  
     5<h2>${c.mission.name} 
    76% if h.auth.authorized(h.auth.is_creator): 
    8 <a href=${h.url_for(controller='mission', action='edit',id=c.mission.id) }>[Edit]</a></li> 
     7<a href=${h.url_for(controller='mission', action='edit',id=c.mission.id) }>[Edit]</a> 
    98%endif 
     9</h2> 
    1010<ul> 
    1111% for pilot in c.mission.pilots: 
     
    1616% endfor 
    1717</ul> 
    18 ${campaign.add_pilot(c.mission.id)} 
     18%if h.auth.authorized(h.auth.is_creator): 
     19${campaign.add_pilot(c.mission.id, c.available_pilots)} 
     20%endif 
    1921 
     22<a href=${h.url_for(controller='campaign', action='view',id=c.mission.campaign_id) }>[Back to campaign]</a></li> 
  • trunk/loreality/loreality/templates/derived/page/mission_edit.html

    r2100 r2104  
    11<%inherit file="/base/index.html"/> 
     2<%namespace name="campaign" file="/component/campaign.html" import="*" />\ 
    23 
    34 
     
    1718<li><a href=${h.url_for(controller='pilot', action='view',id=pilot.id) }>${pilot.name}</a>  
    1819% if h.auth.authorized(h.auth.is_creator): 
    19     <a href=${h.url_for(controller='pilot', action='edit',id=pilot.id) }>[Edit]</a></li> 
     20    <a href=${h.url_for(controller='pilot', action='edit',id=pilot.id) }>[Edit]</a> 
     21    <a href=${h.url_for(pilotid=pilot.id, controller='mission', action='removepilot',id=c.mission.id) }>[Remove]</a></li> 
    2022%endif 
    2123%endfor 
    2224</ul> 
     25%if h.auth.authorized(h.auth.is_creator): 
     26${campaign.add_pilot(c.mission.id, c.available_pilots)} 
     27%endif 
     28<a href=${h.url_for(controller='campaign', action='view',id=c.mission.campaign_id) }>[Back to campaign]</a></li> 
  • trunk/loreality/loreality/templates/derived/page/pilot.html

    r2100 r2104  
    11<%inherit file="/base/index.html"/> 
     2<%namespace name="campaign" file="/component/campaign.html" import="*" />\ 
    23 
    34 
    4 <h2>${c.pilot.name}</h2> 
     5<h2>${c.pilot.name} - <a href=${h.url_for(controller='squadron', action='view',id=c.pilot.squadron_id) }>${c.pilot.squadron.name}</a></h2> 
    56 
    6 % if h.auth.authorized(h.auth.is_creator): 
     7Login: ${c.pilot.login} 
     8% if request.environ['REMOTE_USER'] == c.pilot.login: 
     9<p>It is you!</p> 
     10%endif 
     11% if h.auth.authorized(h.auth.is_admin): 
    712<a href=${h.url_for(controller='pilot', action='edit',id=c.pilot.id) }>[Edit]</a></li> 
    813%endif 
  • trunk/loreality/loreality/websetup.py

    r2100 r2104  
    2828    users.role_create("admin") 
    2929    users.role_create("creator") 
     30    users.role_create("leader") 
    3031 
    3132    users.user_create("DArt", password="admin") 
    3233    users.user_add_role("DArt", role="admin" ) 
    3334    users.user_add_role("DArt", role="creator" ) 
     35    users.user_add_role("DArt", role="leader" ) 
    3436 
    3537    users.user_create("Tolteque", password="admin") 
     38 
     39    users.user_create("MBug", password="admin") 
     40    users.user_add_role("MBug", role="leader" ) 
    3641 
    3742    log.info("Adding mission...") 
     
    4247    cam.missions.append( mis ) 
    4348 
    44     pil = Pilot("DArt") 
     49    squ = Squadron("12th") 
     50    squ.plane = "F-15C" 
     51    meta.Session.add( squ ) 
     52 
     53    pil = Pilot("DArt", "DArt") 
    4554    meta.Session.add( pil ) 
    4655    mis.pilots.append( pil ) 
     56    squ.pilots.append( pil ) 
    4757 
    48     pil = Pilot("Tolteque") 
     58    pil = Pilot("Tolteque", "Tolteque") 
    4959    meta.Session.add( pil ) 
    5060    mis.pilots.append( pil ) 
     61    squ.pilots.append( pil ) 
     62 
     63    squ = Squadron("92nd") 
     64    squ.plane = "Su-27" 
     65    meta.Session.add( squ ) 
     66 
     67    pil = Pilot("MajorBug", "MBug") 
     68    meta.Session.add( pil ) 
     69    mis.pilots.append( pil ) 
     70    squ.pilots.append( pil ) 
    5171 
    5272    mis = Mission("mission 2") 
  • trunk/loreality/setup.py

    r2097 r2104  
    88setup( 
    99    name='loreality', 
    10     version='0.1', 
    11     description='', 
    12     author='', 
    13     author_email='', 
    14     url='', 
     10    version='0.0.1', 
     11    description='Lockon Reality Tool', 
     12    author='DArt', 
     13    author_email='dart@dartsite.org', 
     14    url='http://lotatc.dartsite.org', 
    1515    install_requires=[ 
    1616        "Pylons>=0.9.7", 
    1717        "SQLAlchemy>=0.5", 
     18        "AuthKit>=0.4.3,<=0.4.99", 
     19 
    1820    ], 
    1921    setup_requires=["PasteScript>=1.6.3"], 
Note: See TracChangeset for help on using the changeset viewer.