Skip to content

Commit

Permalink
Merge pull request #107 from CentreForDigitalHumanities/feature/contr…
Browse files Browse the repository at this point in the history
…ibutions-in-db

Feature/contributions in db
  • Loading branch information
lukavdplas authored Aug 13, 2024
2 parents 6adcafa + 1111a18 commit e2b5bce
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 6 deletions.
6 changes: 5 additions & 1 deletion backend/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
},
)

contributions_fieldset = ("Contributors", {"fields": ["contributors"]})

date_fields = ["year_lower", "year_upper", "year_exact"]

field_fields = ["certainty", "note"]
Expand All @@ -27,9 +29,11 @@

class EntityDescriptionAdmin(admin.ModelAdmin):
list_display = ["name", "description", "source"]
list_filter = ["source"]
list_filter = ["source", "contributors"]
search_fields = ["name", "description"]
filter_horizontal = ["contributors"]
fieldsets = [
named_fieldset,
contributions_fieldset,
description_source_fieldset,
]
14 changes: 14 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.core.validators import MinValueValidator, MaxValueValidator
from django.contrib.postgres.fields import ArrayField

from user.models import User


class Field(models.Model):
"""
Expand Down Expand Up @@ -105,6 +107,12 @@ class HistoricalEntity(Named, models.Model):
help_text="Whether this entity is identifiable (i.e. can be cross-referenced between descriptions), or a generic description",
)

contributors = models.ManyToManyField(
to=User,
blank=True,
help_text="Users who contributed to this entry",
)

class Meta:
abstract = True

Expand Down Expand Up @@ -162,6 +170,12 @@ class EntityDescription(Named, models.Model):
help_text="The page number or page range in the source",
)

contributors = models.ManyToManyField(
to=User,
blank=True,
help_text="Users who contributed to this entry",
)

class Meta:
abstract = True

Expand Down
13 changes: 13 additions & 0 deletions backend/core/types/EntityDescriptionType.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from core.models import EntityDescription
from core.types.AbstractDjangoObjectType import AbstractDjangoObjectType
from core.types.NamedType import NamedType
from graphene import List, ResolveInfo, NonNull
from django.db.models import QuerySet

from user.models import User
from user.types.UserType import UserType

class EntityDescriptionType(NamedType, AbstractDjangoObjectType):
"""
Type for models that extend the EntityDescription model.
Should not be queried directly, but should be extended by other types.
"""

contributors = List(NonNull(UserType), required=True)

class Meta:
model = EntityDescription
fields = [
Expand All @@ -18,4 +24,11 @@ class Meta:
"book",
"chapter",
"page",
"contributors",
] + NamedType.fields()

@staticmethod
def resolve_contributors(
parent: EntityDescription, info: ResolveInfo
) -> QuerySet[User]:
return parent.contributors.all()
6 changes: 5 additions & 1 deletion backend/core/types/HistoricalEntityType.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from graphene import Boolean, ObjectType
from graphene import List, NonNull

from core.models import HistoricalEntity
from core.types.AbstractDjangoObjectType import AbstractDjangoObjectType
from core.types.NamedType import NamedType
from user.types.UserType import UserType


class HistoricalEntityType(NamedType, AbstractDjangoObjectType):
Expand All @@ -11,8 +12,11 @@ class HistoricalEntityType(NamedType, AbstractDjangoObjectType):
Should not be queried directly, but should be extended by other types.
"""

contributors = List(NonNull(UserType), required=True)

class Meta:
model = HistoricalEntity
fields = [
"identifiable",
"contributors",
] + NamedType.fields()
20 changes: 20 additions & 0 deletions backend/event/migrations/0022_episode_contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.7 on 2024-08-06 10:02

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('event', '0021_rename_eventdescriptionagent_episodeagent_and_more'),
]

operations = [
migrations.AddField(
model_name='episode',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
]
11 changes: 10 additions & 1 deletion backend/graphql_app/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
from person.queries import PersonQueries
from source.queries import SourceQueries
from space.queries import SpaceQueries
from user.queries import UserQueries
from source.mutations.UpdateOrCreateSourceMutation import UpdateOrCreateSourceMutation


class Query(SourceQueries, PersonQueries, EventQueries, LetterQueries, SpaceQueries, ObjectType):
class Query(
SourceQueries,
PersonQueries,
EventQueries,
LetterQueries,
SpaceQueries,
UserQueries,
ObjectType,
):
pass


Expand Down
3 changes: 2 additions & 1 deletion backend/letter/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class PreservedLetterRoleAdmin(admin.StackedInline):
@admin.register(models.PreservedLetter)
class PreservedLetterAdmin(admin.ModelAdmin):
list_display = ["name", "description"]
fields = ["name", "description"]
fields = ["name", "description", "contributors"]
filter_horizontal = ["contributors"]
inlines = [
PreservedLetterRoleAdmin,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 4.2.7 on 2024-08-06 10:02

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('letter', '0017_alter_giftdescriptioncategory_category_and_more'),
]

operations = [
migrations.AddField(
model_name='giftdescription',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='letterdescription',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='preservedletter',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
]
5 changes: 3 additions & 2 deletions backend/person/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ class PersonDateOfDeathAdmin(admin.StackedInline):
class HistoricalPersonAdmin(admin.ModelAdmin):
list_display = ["name", "description"]
search_fields = ["name", "description"]
filter_horizontal = ["contributors"]
list_filter = ["contributors"]
fieldsets = [
core_admin.named_fieldset,
core_admin.contributions_fieldset,
]
inlines = [
PersonDateOfBirthAdmin,
PersonDateOfDeathAdmin,
]




class AgentDescriptionGenderAdmin(admin.StackedInline):
model = models.AgentDescriptionGender
fields = ["gender"] + core_admin.description_field_fields
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.7 on 2024-08-06 10:02

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("person", "0019_alter_agentdescriptionlocation_agent"),
]

operations = [
migrations.AddField(
model_name="agentdescription",
name="contributors",
field=models.ManyToManyField(
blank=True,
help_text="Users who contributed to this entry",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AddField(
model_name="historicalperson",
name="contributors",
field=models.ManyToManyField(
blank=True,
help_text="Users who contributed to this entry",
to=settings.AUTH_USER_MODEL,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.7 on 2024-08-06 10:02

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('space', '0016_settlement_regions'),
]

operations = [
migrations.AddField(
model_name='region',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='settlement',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='spacedescription',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='structure',
name='contributors',
field=models.ManyToManyField(blank=True, help_text='Users who contributed to this entry', to=settings.AUTH_USER_MODEL),
),
]
27 changes: 27 additions & 0 deletions backend/user/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from graphene import Field, List, ResolveInfo
from django.db.models import QuerySet
from graphene import ID, Field, List, NonNull, ObjectType, ResolveInfo
from django.db.models import QuerySet
from user.types.UserType import UserType
from user.models import User


class UserQueries(ObjectType):
user_description = Field(UserType, id=ID(required=True))
user_descriptions = List(NonNull(UserType), required=True)

@staticmethod
def resolve_user_description(
parent: None, info: ResolveInfo, id: str
) -> User | None:
try:
return UserType.get_queryset(User.objects, info).get(id=id)
except User.DoesNotExist:
return None

@staticmethod
def resolve_user_descriptions(
parent: None,
info: ResolveInfo,
) -> QuerySet[User]:
return UserType.get_queryset(User.objects, info)
21 changes: 21 additions & 0 deletions backend/user/types/UserType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from graphene import ResolveInfo
from graphene_django import DjangoObjectType

from django.db.models import QuerySet
from user.models import User


class UserType(DjangoObjectType):
class Meta:
model = User
fields = [
"id",
"first_name",
"last_name",
]

@classmethod
def get_queryset(
cls, queryset: QuerySet[User], info: ResolveInfo
) -> QuerySet[User]:
return queryset.all()
Loading

0 comments on commit e2b5bce

Please sign in to comment.