Skip to content

Improve general docs #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,8 @@ Features

quickstart
apis
maykin_common/settings
maykin_common/checks
maykin_common/context_processors
maykin_common/django_two_factor_auth
maykin_common/migration_operations
maykin_common/throttling
maykin_common/pdf
maykin_common/views
maykin_common/templatetags
settings
reference/index


Indices and tables
Expand Down
7 changes: 0 additions & 7 deletions docs/maykin_common/settings.rst

This file was deleted.

94 changes: 92 additions & 2 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,108 @@
.. _quickstart:

==========
Quickstart
==========

maykin-common is based around the principle of "zero-cost" utilities and optional
dependency groups. A barebones installation gives you some useful bits, but depending
on you're project needs you likely want to install some extras.

.. note:: A quick recap: extra's in python packages are additional labels you can
pass between square brackets to opt-in to additional dependencies, like so:

.. code-block:: bash

pip install maykin-common[extra1,extra2]

Installation
============

Install from PyPI with pip:
You'll always want to install the base package, e.g.:

.. code-block:: bash

pip install maykin-common

However, the usefulness increases with each extra. Each one of them is described below.

.. tip:: default-project is pre-configured with the typical set of extras that apply
to the majority of projects:

.. code-block:: bash

pip install maykin-common[axes,mfa]

MFA
---

Install command:

.. code-block:: bash

pip install maykin-common[mfa]

The MFA (multi-factor authentication) extra integrates
`django-admin-index <https://pypi.org/project/django-admin-index>`_ and
`maykin-2fa <https://pypi.org/project/maykin-2fa>`_. In particular, it controls the
navigation menu when you're authenticated but not verified with your second factor yet.

These packages and this extra are by default enabled in default-project.

For more details, see :mod:`maykin_common.django_two_factor_auth`.

Axes
----

Install command:

.. code-block:: bash

pip install maykin-common[axes]

Used for the throttling view mixins.

`django-axes <https://pypi.org/project/django-axes>`_ is our standard solution to
prevent brute forced logins and is included by default via default-project. It provides
a helper to get the remote IP address of the person trying to log in, which is used in
the throttling implementation.

For more details, see :mod:`maykin_common.throttling`.

.. _quickstart_pdf:

PDF
---

Install command:

.. code-block:: bash

pip install maykin-common[pdf]

.. note:: You must define the setting ``PDF_BASE_URL_FUNCTION`` - a callable taking no
arguments that returns the absolute base URL where your site/project is running. It
is used to recognize references to your static assets (CSS and uploaded media).

The PDF extra provides an easy to use template-based PDF generation helper, using
`WeasyPrint <https://pypi.org/project/weasyprint>`_. It is optimized to load static
assets (CSS/images/...) from disk rather than making network roundtrips.

For details about the API, see :mod:`maykin_common.pdf`.

Usage
=====

<document how to use the app here>
All modules in maykin-common either only require Django to be available, or require some
optional dependencies. Optional modules have zero footprint as long as you don't import
them, and when you do use them, ensure you've installed the appropriate extra.

API projects (team bron)
------------------------

For API projects, see TODO.

Other
-----

See the reference documentation for details.
File renamed without changes.
35 changes: 35 additions & 0 deletions docs/reference/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. _reference_index:

=========
Reference
=========

Python API reference.

.. toctree::
:maxdepth: 1
:caption: Core utilities

checks
context_processors
migration_operations
views
templatetags

.. toctree::
:maxdepth: 1
:caption: MFA

django_two_factor_auth

.. toctree::
:maxdepth: 1
:caption: Axes

throttling

.. toctree::
:maxdepth: 1
:caption: PDF

pdf
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. _settings:

========
Settings
========

maykin-common requires a number of settings to function properly. These settings are
typically provided through default-project already.

.. automodule:: maykin_common.settings
:members:
:undoc-members:
4 changes: 4 additions & 0 deletions maykin_common/checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Custom Django system checks to prevent common mistakes.
"""

import os

from django.conf import settings
Expand Down
6 changes: 6 additions & 0 deletions maykin_common/django_two_factor_auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""
Combine maykin-2fa and django-admin-index utilities.

Depends on ``django-admin-index``.
"""

from django_admin_index.utils import (
should_display_dropdown_menu as default_should_display_dropdown_menu,
)
Expand Down
2 changes: 2 additions & 0 deletions maykin_common/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
with a context into a PDF document (bytes output). You can use "external" stylesheets
in these templates, and they will be resolved through django's staticfiles machinery
by the custom :class:`UrlFetcher`.

Depends on ``weasyprint``.
"""

import logging
Expand Down
31 changes: 23 additions & 8 deletions maykin_common/settings.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
from django.conf import settings

GOOGLE_ANALYTICS_ID = None
"""Google analytics id added to the request context"""

"""
Google analytics id added to the request context.
"""

SHOW_ENVIRONMENT = False
"""enable or disable the `environment_info` template tag."""
"""
Enable or disable the ``{% environment_info %}`` template tag.
"""

ENVIRONMENT_BACKGROUND_COLOR = "orange"
"""The background color of the `environment_info` template tag."""
"""
The background color of the ``{% environment_info %}`` template tag.
"""

ENVIRONMENT_FOREGROUND_COLOR = "black"
"""The foreground color of the `environment_info` template tag."""
"""
The foreground color of the ``{% environment_info %}`` template tag.
"""

ENVIRONMENT_LABEL = None
"""The foreground color of the `environment_info` template tag."""
"""
The textual content of the ``{% environment_info %}`` template tag.
"""

RELEASE = None
"""The environment label shown in the `version_info` template tag."""
"""
The release version shown in the ``{% version_info %}`` template tag.
"""

GIT_SHA = None
"""The git hash shown in the `version_info` template tag."""
"""
The commit hash shown in the ``{% version_info %}`` template tag.
"""

PDF_BASE_URL_FUNCTION = None
"""
Function that returns the base url needed to download/resolve custom fonts and/or any
image URLs included in the document to render.

Required for the :ref:`quickstart_pdf` extra.
"""


Expand Down
2 changes: 2 additions & 0 deletions maykin_common/throttling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
Provide mixins for throttling/rate limiting in views.

Depends on ``django-axes``.
"""

from collections.abc import Container
Expand Down