Skip to content

Commit

Permalink
Merge pull request #14 from CentreForDigitalHumanities/feature/episodes
Browse files Browse the repository at this point in the history
Feature/episodes
  • Loading branch information
XanderVertegaal authored Jan 29, 2024
2 parents 7d0bc8a + 99a6435 commit 80c7e31
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 102 deletions.
96 changes: 72 additions & 24 deletions backend/data/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,112 @@

class PersonNameAdmin(admin.StackedInline):
model = models.PersonName
fields = ['value', 'certainty', 'note']

fields = ["value", "certainty", "note"]


@admin.register(models.Person)
class PersonAdmin(admin.ModelAdmin):
inlines = [PersonNameAdmin]


class EpistolaryEventCategoryAdmin(admin.StackedInline):
model = models.EpistolaryEventCategory
fields = ['value', 'certainty', 'note']

class LetterActionCategoryAdmin(admin.StackedInline):
model = models.LetterActionCategory
fields = ["value", "certainty", "note"]
extra = 0
verbose_name = "category"
verbose_name_plural = "categories"


class EventDateAdmin(admin.StackedInline):
model = models.EpistolaryEventDate
fields = ['year_exact', 'year_lower', 'year_upper', 'certainty', 'note']
model = models.LetterEventDate
fields = ["year_exact", "year_lower", "year_upper", "certainty", "note"]
verbose_name = "date"
verbose_name_plural = "dates"


class RoleAdmin(admin.StackedInline):
model = models.Role
fields = [
'person',
'present',
'role',
'description',
'certainty',
'note',
"person",
"present",
"role",
"description",
"certainty",
"note",
]

extra = 0
verbose_name = "person/role"
verbose_name_plural = "persons/roles involved"


class EventLetterAdmin(admin.StackedInline):
model = models.EpistolaryEvent.letters.through
class LetterActionLettersAdmin(admin.StackedInline):
model = models.LetterAction.letters.through
extra = 0
verbose_name = "letter"
verbose_name_plural = "letters"

@admin.register(models.EpistolaryEvent)
class EpistolaryEventAdmin(admin.ModelAdmin):

@admin.register(models.LetterAction)
class LetterActionAdmin(admin.ModelAdmin):
inlines = [
EventLetterAdmin,
EpistolaryEventCategoryAdmin,
LetterActionLettersAdmin,
LetterActionCategoryAdmin,
EventDateAdmin,
RoleAdmin,
]
exclude = ["letters"]

exclude = ['letters']

# For use in Case Study form
class EpistolaryEventInline(admin.StackedInline):
model = models.CaseStudy.epistolary_events.through
extra = 0
verbose_name = "epistolary event"
verbose_name_plural = "epistolary events"


@admin.register(models.CaseStudy)
class CaseStudyAdmin(admin.ModelAdmin):
fields = ["name"]
inlines = [EpistolaryEventInline]
extra = 0


class EpistolaryEventCaseStudyInline(admin.StackedInline):
model = models.EpistolaryEvent.case_studies.through
extra = 0
verbose_name_plural = "case studies"
verbose_name = "relationship between a case study and an epistolary event"


class EpistolaryEventLetterActionInline(admin.StackedInline):
model = models.EpistolaryEvent.letter_actions.through
extra = 0
verbose_name_plural = "letter actions"
verbose_name = "relationship between a epistolary event and a letter action"

@admin.register(models.EpistolaryEvent)
class EpistolaryEventAdmin(admin.ModelAdmin):
fields = ["name", "note"]
inlines = [
EpistolaryEventCaseStudyInline,
EpistolaryEventLetterActionInline
]


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

# For use in LetterForm
class LetterActionInline(admin.StackedInline):
model = models.LetterAction
inlines = [RoleAdmin, EpistolaryEventAdmin]
extra = 0


@admin.register(models.Letter)
class LetterAdmin(admin.ModelAdmin):
inlines = [
LetterMaterialAdmin,
EventLetterAdmin,
]
47 changes: 37 additions & 10 deletions backend/data/conftest.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
import pytest

from . import models
from data.models import (
CaseStudy,
Letter,
EpistolaryEvent,
LetterAction,
LetterActionCategory,
Person,
)


@pytest.fixture()
def letter(db):
letter = models.Letter.objects.create()
letter = Letter.objects.create()
return letter


@pytest.fixture()
def epistolary_event(db, letter):
event = models.EpistolaryEvent.objects.create()
def person(db):
person = Person.objects.create()
return person


models.EpistolaryEventCategory.objects.create(
value='write',
event=event
@pytest.fixture()
def letter_action(db, letter, person):
letter_action = LetterAction.objects.create()
letter_action.letters.add(letter)
letter_action.actors.add(person)

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

event.letters.add(letter)
return letter_action


@pytest.fixture()
def case_study(db):
case_study = CaseStudy.objects.create(name="Test Case Study")
return case_study


@pytest.fixture()
def epistolary_event(db, letter, case_study):
epistolary_event = EpistolaryEvent.objects.create(
name="Test Epistolary event", note="Test note", case_studies=[case_study]
)

return event
return epistolary_event
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Generated by Django 4.2.7 on 2024-01-29 09:35

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


class Migration(migrations.Migration):

dependencies = [
('data', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='CaseStudy',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=256)),
],
options={
'verbose_name': 'case study',
'verbose_name_plural': 'case studies',
},
),
migrations.CreateModel(
name='LetterAction',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='LetterActionCategory',
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')),
('value', models.CharField(choices=[('write', 'writing'), ('transport', 'transporting'), ('deliver', 'delivering'), ('read', 'reading'), ('sign', 'signing'), ('eat', 'eating')], help_text='The type of event')),
('letter_action', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='categories', to='data.letteraction')),
],
options={
'verbose_name_plural': 'letter action categories',
},
),
migrations.CreateModel(
name='LetterEventDate',
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')),
('year_lower', models.IntegerField(default=400, help_text='The earliest possible year for the letter action', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_upper', models.IntegerField(default=800, help_text='The latest possible year for the letter action', validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('year_exact', models.IntegerField(blank=True, help_text='The exact year of the letter action (if known)', null=True, validators=[django.core.validators.MinValueValidator(400), django.core.validators.MaxValueValidator(800)])),
('letter_action', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='date', to='data.letteraction')),
],
options={
'abstract': False,
},
),
migrations.RemoveField(
model_name='epistolaryeventdate',
name='event',
),
migrations.RemoveField(
model_name='epistolaryevent',
name='actors',
),
migrations.RemoveField(
model_name='epistolaryevent',
name='letters',
),
migrations.RemoveField(
model_name='role',
name='event',
),
migrations.AddField(
model_name='epistolaryevent',
name='name',
field=models.CharField(default='unnamed event', max_length=256),
preserve_default=False,
),
migrations.AddField(
model_name='epistolaryevent',
name='note',
field=models.TextField(blank=True, help_text='Additional notes that describe the event and what connects the letter actions it comprises.'),
),
migrations.DeleteModel(
name='EpistolaryEventCategory',
),
migrations.DeleteModel(
name='EpistolaryEventDate',
),
migrations.AddField(
model_name='letteraction',
name='actors',
field=models.ManyToManyField(related_name='events', through='data.Role', to='data.person'),
),
migrations.AddField(
model_name='letteraction',
name='epistolary_events',
field=models.ManyToManyField(help_text='epistolary events this letter action belongs to', related_name='letter_actions', to='data.epistolaryevent'),
),
migrations.AddField(
model_name='letteraction',
name='letters',
field=models.ManyToManyField(help_text='letters involved in this event', related_name='events', to='data.letter'),
),
migrations.AddField(
model_name='epistolaryevent',
name='case_studies',
field=models.ManyToManyField(help_text='case studies this event belongs to', related_name='epistolary_events', to='data.casestudy'),
),
migrations.AddField(
model_name='role',
name='letter_action',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='data.letteraction'),
preserve_default=False,
),
migrations.AddConstraint(
model_name='letteractioncategory',
constraint=models.UniqueConstraint(models.F('value'), models.F('letter_action'), name='unique_categories_for_letter_action'),
),
]
Loading

0 comments on commit 80c7e31

Please sign in to comment.