Files
mizan/django
Ryth Azhur 5a56d7a4a5 Update shapes tests for pk abstraction, strict Diff, and diff_many
13 new tests covering three changes from claude.ai:
- pk abstraction: _pk_field resolved from model._meta, _get_pk helper
- Strict Diff.__getattr__: typos raise AttributeError with valid names,
  nested() method raises KeyError for explicit access
- diff_many: batched query (assertNumQueries(1)), mixed new/existing,
  empty list, all-new, nonexistent raises

38 shapes tests total, all passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 02:25:27 -04:00
..

djarea (Python)

Django server functions framework. See the monorepo root for full documentation.

Install

uv add "djarea[channels,allauth] @ git+https://git.impactsoundworks.com/isw/djarea.git#subdirectory=django"

Setup

# settings.py
INSTALLED_APPS = ["djarea", ...]

# urls.py
path("api/djarea/", include("djarea.urls"))

# asgi.py (optional, for WebSocket)
from djarea import wrap_asgi
application = wrap_asgi(get_asgi_application())

Define Functions

from djarea.client import client
from djarea.setup.registry import register
from pydantic import BaseModel

class Output(BaseModel):
    message: str

@client
def echo(request, text: str) -> Output:
    return Output(message=text)

register(echo, "echo")

Register in apps.py:

def ready(self):
    import myapp.djarea_clients

Auth

@client(auth=True)          # requires authentication
@client(auth='staff')       # requires is_staff
@client(auth='superuser')   # requires is_superuser
@client(auth=my_callable)   # custom check

Contexts

@client(context='global')   # fetched once, SSR-hydrated, becomes useCurrentUser()
@client(context='local')    # fetched with params, becomes <GreetProvider>

Forms

from djarea.forms import DjareaFormMixin, DjareaFormMeta

class ContactForm(DjareaFormMixin, forms.Form):
    djarea = DjareaFormMeta(name="contact", title="Contact Us")
    name = forms.CharField()
    email = forms.EmailField()

    def on_submit_success(self, request):
        return {"sent": True}

Auto-registers contact.schema, contact.validate, contact.submit. Generates useContactForm() with Zod validation.

Channels

from djarea.channels import ReactChannel

class ChatChannel(ReactChannel):
    class Params(BaseModel):
        room: str
    class DjangoMessage(BaseModel):
        text: str

    def authorize(self, params):
        return self.user.is_authenticated
    def group(self, params):
        return f"chat_{params.room}"

Generates useChatChannel({ room }).

Running Tests

uv sync --extra dev --extra channels
uv run pytest