Skip to content

Commit

Permalink
feat: crud configurable via pyproject.toml\n\nResolves #55
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Jan 31, 2024
1 parent c1ec156 commit 32c17e3
Show file tree
Hide file tree
Showing 16 changed files with 401 additions and 265 deletions.
2 changes: 1 addition & 1 deletion blueprints/falco_blueprint_basic_bootstrap
46 changes: 46 additions & 0 deletions docs/the_cli/crud.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,52 @@ accessible and you can update it as you see fit. The idea is to accelerate proje

If you want to see an example of the generated code, check out the `source code of the demo project <https://github.com/Tobi-De/falco/tree/main/demo/demo/products>`_.

Configuration
^^^^^^^^^^^^^

There are some options that you may want to set each time you generate ``CRUD`` views for a model. For instance, most of your views might require user
login, or you might have a specific set of HTML templates that you use every time you run the command. Typing the same options repeatedly can be tedious.
For such scenarios, some of the CLI options can be configured via the ``pyproject.toml`` file.

Here is an example illustrating all available configurations:

.. tabs::

.. tab:: ``pyproject.toml``

.. code-block:: toml
[tool.falco.crud]
utils-path = "apps_dir/core"
blueprints = "blueprints"
login-required = true
skip-git-check = true
always-migrate = true
.. note::

All options are optional.

.. tab:: description

.. admonition:: Keys description
:class: note

**utils-path**: This will be written by the ``install-crud-utils`` command. Unless you are changing where the utils are installed, you don't need to worry about this.

**blueprints**: If you are using custom blueprints for your ``html``, set the path here. It works exactly the same as the equivalent CLI option.

**login-required**: Always generate views that are decorated with the ``login_required`` decorator.

**skip-git-check**: (Not recommended) This option is for those who like to live dangerously. It will always skip the git check.

**always-migrate**: This option can only be set in the ``pyproject.toml`` file. My current workflow is to create a new app, add fields to a model and then run ``crud``.
I often forget to ``makemigrations`` and ``migrate``. This can cause the ``admin`` generation code to fail. With this option set, the ``crud`` command will first try to
run ``makemigrations`` and ``migrate``. If either of these operations fails, the command will stop and print the error.




Python code
^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion src/falco/commands/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def clean_git_repo(*, ignore_dirty: bool = False) -> None:
if ignore_dirty:
return
return
with suppress(subprocess.CalledProcessError):
result = subprocess.run(["git", "status", "--porcelain"], capture_output=True, text=True, check=True)
if result.stdout.strip() == "":
Expand Down
10 changes: 5 additions & 5 deletions src/falco/commands/crud/install_crud_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from typing import Annotated

import cappa
from falco.utils import FalcoConfig
from falco.config import FalcoConfig
from falco.config import read_falco_config
from falco.config import write_falco_config
from falco.utils import get_project_name
from falco.utils import get_pyproject_file
from falco.utils import read_falco_config
from falco.utils import simple_progress
from falco.utils import write_falco_config
from rich import print as rich_print

from .utils import extract_python_file_templates
Expand All @@ -33,7 +33,7 @@ def __call__(self, project_name: Annotated[str, cappa.Dep(get_project_name)]):

output_dir = self.install(project_name=project_name, falco_config=falco_config)
if pyproject_path:
write_falco_config(pyproject_path=pyproject_path, crud_utils=str(output_dir))
write_falco_config(pyproject_path=pyproject_path, crud={"utils_path": str(output_dir)})

rich_print(f"[green]CRUD Utils installed successfully to {output_dir}.")

Expand Down Expand Up @@ -66,6 +66,6 @@ def install(self, project_name: str, falco_config: FalcoConfig) -> Path:

@classmethod
def get_install_path(cls, project_name: str, falco_config: FalcoConfig) -> tuple[Path, bool]:
if _import_path := falco_config.get("crud_utils"):
if _import_path := falco_config.get("crud", {}).get("utils_path"):
return Path(_import_path), True
return Path(f"{project_name}/core"), False
Loading

0 comments on commit 32c17e3

Please sign in to comment.