The style guide establish a series of rules to follow when coding in e-cidadania. These rules are unbreakable. The style guide follows closely the PEP8 document, with some exceptions provided from the internal style guide at Pocoo.
Every import must be situated in the file header, below to the comment header. The python imports must precede any others, and the external librearies or third party modules must precede the application ones.
Example:
import os
import sys
from extlib import function
from myapp.module import function
If a code line does not fit in 80 columns, try to reduce it declaring variables previously. If it still can not fit, you can divide the lines this way:
Parentheses:
website = models.URLField(_('Website'), verify_exists=True,
max_length=200, null=True, blank=True,
help_text=_('The URL will be checked'))
Declararations:
this_is_a_very_long(function_call, 'with many parameters') \
.that_returns_an_object_with_an_attribute
MyModel.query.filter(MyModel.scalar > 120) \
.order_by(MyModel.name.desc()) \
.limit(10)
Lists, tuples and dictionariess:
items = [
'this is the first', 'set of items', 'with more items',
'to come in this line', 'like this'
]
dict = {
('mobile': phone),
('car': key),
('another': thing),
}
Every classes and method must be separated by two blank lines. The code inside a class or method by one blank line.
Example:
class ListDocs(ListView):
----blank line----
"""
List all documents stored whithin a space.
"""
paginate_by = 25
context_object_name = 'document_list'
----blank line----
def get_queryset(self):
place = get_object_or_404(Space, url=self.kwargs['space_name'])
objects = Document.objects.all().filter(space=place.id).order_by('pub_date')
return objects
----blank line----
def get_context_data(self, **kwargs):
context = super(ListDocs, self).get_context_data(**kwargs)
context['get_place'] = get_object_or_404(Space, url=self.kwargs['space_name'])
return context
----blank line----
----blank line----
def whatever(args):
----blank line----
"""
A comment.
"""
this_is_something = 0
The X/HTML code must be indented with four spaces like python code, no exceptions.
Note
There may be some old code that follows the old indentation rule (2 spaces per level). If you see it we would be glad to receive a path to solve it.
Indentation will be 4 spaces, always, like Python code.
Example:
body {
background: #FAFAFA;
padding: 0;
margin: 0;
font-family: Verdana, "Lucida Sans", Arial;
font-size: 1em;
color: #000;
cursor: default;
}
The JavaScript code follows the same rules from the python code.