Skip to content

How to add a check?

Corentin Bettiol edited this page Dec 9, 2019 · 14 revisions

Each of our checks is a file located in the /path/to/your/site-packages/django-check-seo/checks_list/ folder (see wiki - How does it work?), and need to follow some guidelines:


Custom checks

The launch_checks.py file tries to import the checks_list folder located in your django project (same level than manage.py).

If it does not exist, nothing happens.

If it exists, it will execute the important & run functions in each of the modules that start with checks..

To properly reference the modules, you will need to create a __init__.py file in your folder (otherwise there will be checks in sys.modules, and not checks.yourmodule).

__init__.py (raw file)

# Standard Library
import glob
from os.path import basename, dirname, isfile, join
import sys, json

from django.conf import settings

# list files
modules = glob.glob(join(dirname(__file__), "*.py"))

__all__ = []

# add them to __all__ so they can be imported
for module in modules:
    if (
        isfile(module)
        and not module.endswith("__init__.py")
    ):
        __all__.append(basename(module)[:-3])

Example of configuration:

image


How to add a problem/warning/success?

Each problem/warning/success is in fact a CustomList object.

Importing

Since django-check-seo uses dashes in its name, just importing a submodule using from django-check-seo.checks import custom_list won't work.
Use importlib instead:

import importlib
custom_list = importlib.import_module("django-check-seo.checks.custom_list")

Description:

image

Name Description
name Name of the check (str)
settings Settings of the check (short str)
found What was found during the check (short str)
searched_in The studied data (list - warning: a string is a list of chars!)
description Description of the check (long str)

Example:

This code:

image

... will create this success:

image


Wanna see some custom checks examples?

Take a look at the Custom Checks page, or follow this direct link to a working gist.