feat(formbuilder): fix tenancy bugs, add admin + services
Fix multi-tenancy/integrity bugs in the models: Form.slug and Field.key were globally unique (unique=True), so two clubs couldn't reuse a form slug and two forms couldn't reuse a field key — make slug unique per club (constraint already present) and key unique per form. Add a (submission, field) uniqueness constraint on Answer. Register all four models in the admin (Field inline on Form, Answer inline on Submission) and add formbuilder to the admin registration smoke test. Add a service layer: - submit_form(form, member, data): enforces is_active / login_required / open window / max_submissions, validates required + choice fields, and writes a Submission with Answers atomically (FormSubmissionError carries per-field errors). - build_form(form): a live django.forms.Form built from a Form's active fields, mapping each FieldType to the matching form field. - form_report(form): a tabular overview of every submission's answers plus per-value tallies for choice-type fields. Full suite at 100% coverage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
31
formbuilder/migrations/0003_fix_tenant_uniqueness.py
Normal file
31
formbuilder/migrations/0003_fix_tenant_uniqueness.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 6.0.6 on 2026-07-12 19:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('formbuilder', '0002_alter_answer_field_alter_submission_member'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='field',
|
||||
name='key',
|
||||
field=models.SlugField(verbose_name='key'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='form',
|
||||
name='slug',
|
||||
field=models.SlugField(verbose_name='slug'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='answer',
|
||||
constraint=models.UniqueConstraint(fields=('submission', 'field'), name='unique_answer_per_field_per_submission'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='field',
|
||||
constraint=models.UniqueConstraint(fields=('form', 'key'), name='unique_field_key_per_form'),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user