Skip to content
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

Feature/letter model updates #17

Merged
merged 7 commits into from
Feb 9, 2024
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
44 changes: 42 additions & 2 deletions backend/conftest.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
import pytest
from case_study.models import CaseStudy
from letter.models import Letter
from event.models import EpistolaryEvent, LetterAction, LetterActionCategory
from event.models import (
EpistolaryEvent,
LetterAction,
LetterActionCategory,
LetterEventDate,
)
from person.models import Person
from person.models import Person, PersonDateOfBirth, PersonName


@pytest.fixture()
def letter(db):
letter = Letter.objects.create()
letter.name = "letter for testing"
letter.save()
return letter


@pytest.fixture()
def person(db):
person = Person.objects.create()
person.name = "Bert"
person.save()
return person


@pytest.fixture()
def letter_action(db, letter, person):
def person_2(db):
person = Person.objects.create()
person.name = "Ernie"
person.save()
return person


@pytest.fixture()
def letter_action_writing(db, letter, person):
letter_action = LetterAction.objects.create()
letter_action.letters.add(letter)
letter_action.actors.add(person)
Expand All @@ -28,6 +46,28 @@ def letter_action(db, letter, person):
value="write",
)

LetterEventDate.objects.create(
year_lower=500, year_upper=500, year_exact=500, letter_action=letter_action
)

return letter_action


@pytest.fixture()
def letter_action_reading(db, letter, person_2):
letter_action = LetterAction.objects.create()
letter_action.letters.add(letter)
letter_action.actors.add(person_2)

LetterActionCategory.objects.create(
letter_action=letter_action,
value="read",
)

LetterEventDate.objects.create(
year_lower=505, year_upper=510, letter_action=letter_action
)

return letter_action


Expand Down
6 changes: 3 additions & 3 deletions backend/event/tests/test_event_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_letter_action_name(letter, letter_action):
action_str = str(letter_action)
def test_letter_action_name(letter, letter_action_writing):
action_str = str(letter_action_writing)

assert str(action_str) == f'writing of {str(letter)}'
assert str(action_str) == f"writing of {str(letter)}"
26 changes: 26 additions & 0 deletions backend/letter/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
from . import models


@admin.register(models.Category)
class CategoryAdmin(admin.ModelAdmin):
fields = ["label", "description"]


class LetterMaterialAdmin(admin.StackedInline):
model = models.LetterMaterial
fields = ["surface", "certainty", "note"]


class LetterCategoryAdmin(admin.StackedInline):
model = models.LetterCategory
fields = ["letter", "category", "certainty", "note"]


class LetterSenderAdmin(admin.StackedInline):
model = models.LetterSenders
fields = ["letter", "senders", "certainty", "note"]
filter_horizontal = ["senders"]


class LetterAddresseesAdmin(admin.StackedInline):
model = models.LetterAddressees
fields = ["letter", "addressees", "certainty", "note"]
filter_horizontal = ["addressees"]


@admin.register(models.Letter)
class LetterAdmin(admin.ModelAdmin):
readonly_fields = ["date_active", "date_written"]
inlines = [
LetterCategoryAdmin,
LetterMaterialAdmin,
LetterSenderAdmin,
LetterAddresseesAdmin,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Generated by Django 4.2.7 on 2024-01-31 17:02

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):
dependencies = [
("letter", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Category",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("label", models.CharField(max_length=200, unique=True)),
("description", models.TextField(blank=True)),
],
),
migrations.AddField(
model_name="letter",
name="name",
field=models.CharField(
help_text="a unique name to identify this letter in the database",
max_length=200,
null=True,
),
),
migrations.CreateModel(
name="LetterCategory",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"certainty",
models.IntegerField(
choices=[
(0, "uncertain"),
(1, "somewhat certain"),
(2, "certain"),
],
default=2,
help_text="How certain are you of this value?",
),
),
("note", models.TextField(blank=True, help_text="Additional notes")),
(
"category",
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="letter.category",
),
),
(
"letter",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE, to="letter.letter"
),
),
],
options={
"abstract": False,
},
),
]
20 changes: 20 additions & 0 deletions backend/letter/migrations/0003_populate_letter_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.7 on 2024-01-31 17:03

from django.db import migrations


def generate_name(apps, schema_editor):
Letter = apps.get_model("letter", "Letter")
for row in Letter.objects.all():
row.name = f"letter #{row.id}"
row.save(update_fields=["name"])


class Migration(migrations.Migration):
dependencies = [
("letter", "0002_category_letter_name_lettercategory"),
]

operations = [
migrations.RunPython(generate_name, reverse_code=migrations.RunPython.noop)
]
22 changes: 22 additions & 0 deletions backend/letter/migrations/0004_make_letter_name_unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.7 on 2024-01-31 17:03

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):
dependencies = [
("letter", "0003_populate_letter_name"),
]

operations = [
migrations.AlterField(
model_name="letter",
name="name",
field=models.CharField(
help_text="a unique name to identify this letter in the database",
max_length=200,
unique=True,
),
),
]
17 changes: 17 additions & 0 deletions backend/letter/migrations/0005_alter_category_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2024-01-31 17:25

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('letter', '0004_make_letter_name_unique'),
]

operations = [
migrations.AlterModelOptions(
name='category',
options={'verbose_name': 'letter category', 'verbose_name_plural': 'letter categories'},
),
]
41 changes: 41 additions & 0 deletions backend/letter/migrations/0006_lettersenders_letteraddressees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.2.7 on 2024-02-01 10:37

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('person', '0001_initial'),
('letter', '0005_alter_category_options'),
]

operations = [
migrations.CreateModel(
name='LetterSenders',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('certainty', models.IntegerField(choices=[(0, 'uncertain'), (1, 'somewhat certain'), (2, 'certain')], default=2, help_text='How certain are you of this value?')),
('note', models.TextField(blank=True, help_text='Additional notes')),
('letter', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='letter.letter')),
('senders', models.ManyToManyField(blank=True, help_text='persons that the letter names as the sender', to='person.person')),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='LetterAddressees',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('certainty', models.IntegerField(choices=[(0, 'uncertain'), (1, 'somewhat certain'), (2, 'certain')], default=2, help_text='How certain are you of this value?')),
('note', models.TextField(blank=True, help_text='Additional notes')),
('addressees', models.ManyToManyField(blank=True, help_text='persons that the letter names as the addressee', to='person.person')),
('letter', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='letter.letter')),
],
options={
'abstract': False,
},
),
]
Loading
Loading