Changes between Version 39 and Version 40 of WebCodingStyle

Changes between Version 39 and Version 40 of WebCodingStyle

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 39 and Version 40 of WebCodingStyle

Please note that these Trac pages are no longer being updated. Wiki contents/documentation have moved to GitHub.

Changes between Version 39 and Version 40 of WebCodingStyle

Show
Ignore:
Timestamp:
08/20/12 20:37:07 (7 years ago)
Author:
gpress
Comment:

Django Template example

Legend:

Unmodified
Added
Removed
Modified
  • WebCodingStyle

    v39 v40  
    1919---- 
    2020 
    21  Decorators must be explained. Always.:: 
     21Views are python functions which take a web request and return a web response.  These responses can be anything from redirects to 404 errors.  All of the Clearinghouse web pages are defined in views.py as well as all of the Django variables they use.  All web pages must be defined in views.py and also mapped to a URL in the urls.py file. 
     22   
     23 Decorators must be explained. Always.  A Decorator is the "@whatever" before a views.py function.:: 
    2224 
    2325  - Django makes use of decorators to simplify complex functions. Each use of a decorator must be explained in the {{{<Note>}}} section of the function's docstring. Example: 
     
    7880Django templates define a view on data generated by the Django application. Templates are written in a mix of HTML and Django templating language. Because there is no well-defined interface between templates and Django applications. This interface must be explicitly defined and maintained in comments maintained in the template file. It is important to maintain these comments in the template file because the template may be instantiated from different points in Django code, and may be used by different Django applications. 
    7981 
    80  * All templates should include a header that defines all the variables expected by the template. Here is an example: 
    81 {{{ 
     82 * a template tag looks like: 
     83{{{  
    8284#!python 
    83 example goes here 
     85   {% if myvariable %} 
     86     //do stuff 
     87   {% endif %} 
     88}}} 
     89These are used for built in Django code such as if statements, comments, for loops etc.  These change based on Django version so be mindful. 
     90 
     91 * a template variable looks like: 
     92{{{ 
     93#!python 
     94  {{ myvessels }} 
     95}}} 
     96These are defined in views.py specifically for each web page. 
     97 
     98 * All templates should include a header that defines all the variables expected by the template.  Try to be as specific as possible. Here is an example: 
     99{{{ 
     100#!python 
     101{% comment %} 
     102<Program> 
     103  myvessels.html 
     104 
     105<Author> 
     106  Originally by?: 
     107  Justin Samuel 2009 
     108 
     109  Modified: 
     110  Gaetano Pressimone Aug 14 2012 
     111   
     112<Purpose> 
     113  Django template file for Seattle Clearinghouse's 'My Vessels' page.  The page  
     114  allows a logged in user to acquire, renew or remove vessels. 
     115 
     116<extends> 
     117  control/control_base.html 
     118 
     119<Stylesheet> 
     120  myvessels.css 
     121 
     122<Scripts> 
     123  myvessels.js 
     124 
     125<Template Variables> 
     126  username: 
     127    The currently logged in user. 
     128         
     129  my_vessels:  
     130    list of infodicts of the user's currently acquired vessels. 
     131    .node_ip:  last known ip 
     132    .node_port:  last known port 
     133    .vessel_id:  vessel name 
     134    .node_id:  identifier for the node that the vessel is on 
     135    .handle:  node id + ":" + vessel name 
     136    .is_active:  whether the node is active 
     137    .expires_in_seconds: expiration time, in seconds, for the vessel 
     138 
     139  num_vessels:  
     140    Length of my_vessels list. 
     141 
     142  sh_vessels:  
     143    List of shared vessels that are used by other but which belong to this user. 
     144 
     145  get_form: 
     146    The form to acquire vessels.  See forms.py for more info. 
     147    .num: number of acquireable vessels. 
     148    .env: enviromental variables example WAN, LAN, NAT, Random 
     149 
     150  action_summary:  
     151    Generic error message. 
     152{% endcomment %} 
    84153}}} 
    85154