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

Add tables.py #70

Merged
merged 3 commits into from
Dec 9, 2024
Merged
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
108 changes: 108 additions & 0 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import logging

import django_tables2 as tables
from apis_core.apis_entities.tables import AbstractEntityTable
from django_tables2.utils import A

from .models import (
Event,
Expression,
Group,
Item,
Manifestation,
Person,
Place,
Poster,
Work,
)

logger = logging.getLogger(__name__)


class SortableColumn(tables.Column):
linkify = {
"viewname": "apis_core:generic:detail",
"args": [A("self_contenttype"), A("pk")],
}

def __init__(self, *args, **kwargs):
super().__init__(
linkify=self.linkify,
*args,
**kwargs,
)


class BaseEntityTable(AbstractEntityTable):
"""
Base class for entity tables.
"""

id = SortableColumn()

class Meta(AbstractEntityTable.Meta):
exclude = ["desc"]
sequence = (
"...",
"id",
"view",
"edit",
"delete",
"noduplicate",
)


class TitleFieldsMixin(tables.Table):
class Meta:
fields = ["title", "subtitle"]


class WorkTable(BaseEntityTable):
class Meta(TitleFieldsMixin.Meta, BaseEntityTable.Meta):
model = Work


class ExpressionTable(BaseEntityTable):
class Meta(TitleFieldsMixin.Meta, BaseEntityTable.Meta):
model = Expression


class ManifestationTable(BaseEntityTable):
class Meta(TitleFieldsMixin.Meta, BaseEntityTable.Meta):
model = Manifestation


class ItemTable(BaseEntityTable):
class Meta(TitleFieldsMixin.Meta, BaseEntityTable.Meta):
model = Item


class PersonTable(BaseEntityTable):
class Meta(BaseEntityTable.Meta):
model = Person
fields = ["forename", "surname"]
order_by = "surname"


class PlaceTable(BaseEntityTable):
class Meta(BaseEntityTable.Meta):
model = Place
fields = ["label"]


class GroupTable(BaseEntityTable):
class Meta(BaseEntityTable.Meta):
model = Group
fields = ["label"]


class EventTable(BaseEntityTable):
class Meta(BaseEntityTable.Meta):
model = Event
fields = ["label"]


class PosterTable(BaseEntityTable):
class Meta(BaseEntityTable.Meta):
model = Poster
fields = ["label"]
Loading