Fediversity/panel
Valentin Gagarin 6100b278b6 generate Python data models from module options (#285)
this shows a proof of concept for generating Django forms from NixOS modules

note that the form behavior is still rather clumsy and doesn't exactly map to the module semantics:
- since forms can only be sent wholesale, empty form fields will show up as empty strings
  and break validation without additional cleanup (not done here)
- it's not possible to faithfully translate `type = submodule { /* ... */}; default = {};`, since the default
  is translated to an empty dict `{}`. this is because the JSON schema converter does not preserve type information.
  this can be added by making it use `$defs` [1], but that would likely amount to half a rewrite
- there's a glitch in enum default values that needs to be fixed in `datamodel-code-generator` [0]

[0]: dd44480359/src/datamodel_code_generator/parser/base.py (L1015)
[1]: https://json-schema.org/understanding-json-schema/structuring#defs

a generated file will be placed into the source (by the development shell and the package respectively)
that declares Pydantic types from which to render the form. it looks something like this:

```python
from __future__ import annotations

from enum import Enum
from typing import Optional

from pydantic import BaseModel, Extra, Field
from drf_pydantic import BaseModel

class Domain(Enum):
    fediversity_net = 'fediversity.net'

# ...

class Model(BaseModel):
    class Config:
        extra = Extra.forbid

    domain: Optional[Domain] = Field(
        'fediversity.net',
        description='Apex domain under which the services will be deployed.\n',
    )

  # ...
```
2025-05-01 01:26:52 +02:00
..
nix generate Python data models from module options (#285) 2025-05-01 01:26:52 +02:00
src generate Python data models from module options (#285) 2025-05-01 01:26:52 +02:00
.envrc add .envrc files 2025-02-13 14:48:21 +01:00
.gitignore generate Python data models from module options (#285) 2025-05-01 01:26:52 +02:00
default.nix programmatically place generated files in development environment 2025-04-22 16:24:12 +02:00
env.nix refactor variables (#269) 2025-03-24 10:04:43 +01:00
README.md add debug toolbar 2025-02-18 18:25:37 +01:00
shell.nix scaffold Django web service 2025-02-13 00:26:28 +01:00

Fediversity Panel

The Fediversity Panel is a web service for managing Fediversity deployments with a graphical user interface, written in Django.

Development

  • To obtain all tools related to this project, enter the development environment with nix-shell.

    If you want to do that automatically on entering this directory:

    • Set up direnv

    • Run direnv allow in the directory where repository is stored on your machine

      Note

      This is a security boundary, and allows automatically running code from this repository on your machine.

  • Run NixOS integration tests and Django unit tests:

    nix-build -A tests
    
  • List all available Django management commands with:

    manage
    
  • With a fresh database, run:

    manage migrate
    
  • Run the server locally:

    manage runserver
    
  • Create an admin user:

    manage createsuperuser
    

    and log in at http://localhost:8000/admin.

  • After changing the database schema, add migrations and apply them:

    manage makemigrations
    manage migrate
    
  • Use the Django Debug Toolbar for troubleshooting in the browser