Main Convention#
Table of Contents#
Basic#
Basic graphql and admin:
for graphql sandbox: use
localhost:8000/sandbox/for create admin :
python manage.py createsuperuser
Coding Convention#
Unless stated, below are coding convention for respective language, you can find in this docs:
Python : PEP-8
React : Airbnb coding convention https://airbnb.io/javascript/react/
React#
Defining javascript#
Graphql code must defined under the query/mutation unless it takes a lot of lines (more than 10 lines) or will be reused
// ✓ YES
client.query ({
query: gql` some graphql code`,
// ...
})
// X NO
const someQuery=gql` ... `
client.query({
query: someQuery,
// ...
})
Define gerServerSide or other nextjs server function before creating component#
Each function must be define on top of the code
// ✓ YES
async function getServerSide(ctx){
//...
}
export default function SomeComponent{
//...
}
// X NO
export default function SomeComponent{
//...
}
async function getServerSide(ctx){
//...
}
Declare Constant#
Unless const is not for function or component , need to be defined with capital case
const DEFAULT_VALUE = 3 // ✓ YES
const DEFAULT_FUNCTION = () => { ... } // X NO
const defaultFunction = ()=>{ ... } // X NO
Python#
import within python#
import python with rules:
python library import
django import (using
form ... import ...)third party import
app model import
This is to make sure easy to discern what libraries are imported and prevent duplication.
import datetime
from django.conf import settings
from django.contrib import auth
from thirdparty.dev import dev
from your.custom import models
Don’t use tab use space#
Indentation always use 4 spaces instead of tab.
docstring and documentation#
Documentation using google style docstring, as the following example
class ExampleClass(object):
"""The summary line for a class docstring should fit on one line.
If the class has public attributes, they may be documented here
in an ``Attributes`` section and follow the same formatting as a
function's ``Args`` section. Alternatively, attributes may be documented
inline with the attribute's declaration (see __init__ method below).
Properties created with the ``@property`` decorator should be documented
in the property's getter method.
Attributes:
attr1 (str): Description of `attr1`.
attr2 (:obj:`int`, optional): Description of `attr2`.
"""
attr3 = "test" #: Doc comment *inline* with attribute
#: list of str: Doc comment *before* attribute, with type specified
attr4 = "test"
def __init__(self, param1, param2, param3):
# documented always after class declaration
self.attr1 = param1
self.attr2 = param2
self.attr3 = param3
@property
def readonly_property(self):
"""str: Properties should be documented in their getter method."""
return 'readonly_property'
@property
def readwrite_property(self):
""":obj:`list` of :obj:`str`: Properties with both a getter and setter
should only be documented in their getter method.
If the setter method contains notable behavior, it should be
mentioned here.
"""
return ['readwrite_property']
@readwrite_property.setter
def readwrite_property(self, value):
value
def example_method(self, param1, param2):
"""Class methods are similar to regular functions.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
True if successful, False otherwise.
"""
return True