Style guide

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.


import os
import sys

from extlib import function

from myapp.module import function
Line width (columns)
The code must be always 80 columns wide except on templates.
Long declarations

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:


website = models.URLField(_('Website'), verify_exists=True,
                          max_length=200, null=True, blank=True,
                          help_text=_('The URL will be checked'))


this_is_a_very_long(function_call, 'with many parameters') \

MyModel.query.filter(MyModel.scalar > 120) \
             .order_by( \

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),
Indentation must be always 4 spaces per level, no exceptions. You can not use tabs for indenting.
Blank lines

Every classes and method must be separated by two blank lines. The code inside a class or method by one blank line.


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('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


HTML code does not have a column limit, but it must be indented in a way we can locate easily every element inside the document. The indentation preceeds rendered results in application.

The X/HTML code must be indented with four spaces like python code, no exceptions.


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.


body {
    background: #FAFAFA;
          padding: 0;
          margin: 0;
          font-family: Verdana, "Lucida Sans", Arial;
          font-size: 1em;
          color: #000;
          cursor: default;
Colors must be always written in hexadecimal. You are allowed to use three digits abbreviations.
Font size
Font size must be declared in em’s except for presentation requirement.


The JavaScript code follows the same rules from the python code.