Changes between Version 40 and Version 41 of WebCodingStyle

Changes between Version 40 and Version 41 of WebCodingStyle

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

Changes between Version 40 and Version 41 of WebCodingStyle

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

Changes between Version 40 and Version 41 of WebCodingStyle

Show
Ignore:
Timestamp:
08/20/12 21:04:51 (7 years ago)
Author:
gpress
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WebCodingStyle

    v40 v41  
    8080Django 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. 
    8181 
    82  * a template tag looks like: 
     82Templates are composed of block tags and variables. 
     83 
     84 * A template block tag looks like: 
    8385{{{  
    84 #!python 
     86#!c 
    8587   {% if myvariable %} 
    8688     //do stuff 
    8789   {% endif %} 
    8890}}} 
    89 These 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 
     91These are used for built in Django code such as if statements, comments, for loops etc.  These change based on Django version so be mindful.  Make sure to always close the block tag if applicable. 
     92 
     93 * A template variable looks like: 
     94{{{ 
     95#!c 
    9496  {{ myvessels }} 
    9597}}} 
     
    145147  get_form: 
    146148    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    .num: number of acquirable vessels. 
     150    .env: environmental variables example WAN, LAN, NAT, Random 
    149151 
    150152  action_summary:  
     
    152154{% endcomment %} 
    153155}}} 
     156 
     157Django allows template inheritance which is a boilerplate or skeleton page in which a child expands upon.  This improves template file readability and also makes drastic website style changes easier.  Every Clearinghouse web page should inherit from the relevant base template of that category which is organized by folder.  If need be a child can override any of the inherited block elements. 
     158{{{ 
     159#!c 
     160{% extends "accounts/accounts_base.html" %} 
     161 
     162{% block title %} 
     163Register - Clearinghouse 
     164{% endblock title %} 
     165 
     166{% block script %} 
     167{{ block.super }} 
     168<script type="text/javascript" src="{{MEDIA_URL}}scripts/register.js" charset="utf-8"></script> 
     169{% endblock script %} 
     170 
     171{% block nav_register %} 
     172<td class="active">Register</td> 
     173{% endblock nav_register %} 
     174 
     175{% block content %} 
     176 //this page's web content 
     177{% endblock content %} 
     178}}}    
     179this page inherits from "accounts/accounts_base.html" and overrides the parent in every {% block whatever %} tag.  {{block.super}} is called when extension on that block is wanted instead of overriding such as in: 
     180{{{ 
     181#!c 
     182{% block script %} 
     183{{ block.super }} 
     184<script type="text/javascript" src="{{MEDIA_URL}}scripts/register.js" charset="utf-8"></script> 
     185{% endblock script %} 
     186}}}  
    154187 
    155188[[BR]]