Skip to content

Commit

Permalink
Merge pull request #14 from CentreForDigitalHumanities/feature/contin…
Browse files Browse the repository at this point in the history
…ued-annotations2

Continued annotations and more
  • Loading branch information
tijmenbaarda authored Nov 24, 2023
2 parents baece0b + f0c8b32 commit 7357f5b
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install setuptools # requirement for iso639-lang on Python>=3.12
- name: Lint with ruff
run: |
pip install ruff
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.db
*.sqlite3
__pycache__/
.python-version
118 changes: 112 additions & 6 deletions lidiabrowser/lidia/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import List, Type
from django.contrib import admin
from django.http import HttpRequest

from .models import (
Annotation,
Expand All @@ -16,7 +18,7 @@ class ContinuationInline(admin.TabularInline):
model = ContinuationAnnotation
fk_name = "start_annotation"
ordering = ("sort_index",)
fields = ["textselection", "sort_index"]
fields = ["zotero_annotation", "textselection", "sort_index"]
extra = 0


Expand All @@ -29,22 +31,126 @@ class TermGroupInline(admin.TabularInline):


class AnnotationAdmin(admin.ModelAdmin):
list_display = ["zotero_annotation", "lidia_id", "parent_attachment", "argname", "arglang", "page_start"]
list_filter = ["parent_attachment", "arglang"]
list_display = ["parent_attachment_display", "argname_display", "description", "arglang", "page_range_complete", "summary_of_term_groups", "relation_display"]
list_display_links = ["argname_display"]
list_filter = ["parent_attachment", "arglang", "termgroups__articleterm__term", "termgroups__lidiaterm__term", "termgroups__category__category"]
ordering = ("parent_attachment", "sort_index")
inlines = [
ContinuationInline,
TermGroupInline,
]
search_fields = [
"argname",
"description",
"termgroups__lidiaterm__term",
"termgroups__articleterm__term",
"termgroups__category__category",
]
readonly_fields = [
"page_range",
"page_range_in_pdf",
"full_quotation",
"all_zotero_ids",
] # Necessary for callables

@admin.display(
ordering="argname",
description="name",
empty_value="(no name)"
)
def argname_display(self, obj: Annotation):
return obj.argname if obj.argname else "(no name)"

@admin.display(
ordering="parent_attachment",
description="publication",
)
def parent_attachment_display(self, obj: Annotation):
if not obj.parent_attachment:
return "(undefined)"
title = obj.parent_attachment.title
if not title:
return "(no title)"
elif len(title) > 50:
return title[0:45] + "…"
else:
return title

@admin.display(
description="relation",
)
def relation_display(self, obj: Annotation):
if not obj.relation_type:
return None
return f"{obj.get_relation_type_display()} {obj.relation_to}"

@admin.display(
description="page range",
ordering="page_start"
)
def page_range_complete(self, obj: Annotation):
return f"{obj.page_range} ({obj.page_range_in_pdf})"

def get_fieldsets(self, request: HttpRequest, obj=None):
fieldsets = [
(
None, {
"fields": [
"parent_attachment",
"argname",
"full_quotation",
"description",
"page_range",
"page_range_in_pdf",
"arglang",
],
}
), (
"Relation to other annotation", {
"fields": [
"relation_type",
"relation_to",
],
}
), (
"Technical details", {
"fields": [
"lidia_id",
"all_zotero_ids",
]
}
)
]
if request.user.is_superuser: # type: ignore
# Only show link to annotation in sync to superuser
fieldsets[2][1]["fields"].append("zotero_annotation")
return fieldsets

def get_inlines(self, request: HttpRequest, obj=None):
inlines: List[Type[admin.TabularInline]] = [TermGroupInline]
if request.user.is_superuser: # type: ignore
# Only show continuation annotations to superuser because
# for normal users this distinction is irrelevant
inlines.append(ContinuationInline)
return inlines

class PublicationAdmin(admin.ModelAdmin):
list_display = ["zotero_id", "attachment_id", "title"]
list_display = ["zotero_publication", "attachment_id", "title"]
change_form_template = "lidia/change_form_publication.html"


class LidiaTermAdmin(admin.ModelAdmin):
list_display = ["term", "vocab"]
list_filter = ["vocab"]


class LanguageAdmin(admin.ModelAdmin):
list_display = ["code", "name"]


admin.site.register(Annotation, AnnotationAdmin)
admin.site.register(Publication, PublicationAdmin)
admin.site.register(Language)
admin.site.register(Language, LanguageAdmin)
admin.site.register(Category)
admin.site.register(LidiaTerm)
admin.site.register(LidiaTerm, LidiaTermAdmin)
admin.site.register(ArticleTerm)
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 4.2.7 on 2023-11-22 12:04

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


class Migration(migrations.Migration):

dependencies = [
('sync', '0001_initial'),
('lidia', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='category',
options={'verbose_name_plural': 'categories'},
),
migrations.RemoveField(
model_name='publication',
name='zotero_id',
),
migrations.AddField(
model_name='publication',
name='zotero_publication',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='sync.publication', to_field='zotero_id', verbose_name='Zotero publication'),
),
migrations.AlterField(
model_name='annotation',
name='relation_type',
field=models.CharField(choices=[('', 'none'), ('contradicts', 'contradicts'), ('generalizes', 'generalizes'), ('invalidates', 'invalidates'), ('specialcase', 'is a special case of'), ('supports', 'supports')], default='', max_length=11),
),
migrations.AlterField(
model_name='articleterm',
name='term',
field=models.CharField(max_length=100, unique=True, verbose_name='article term'),
),
migrations.AlterField(
model_name='baseannotation',
name='textselection',
field=models.TextField(default=''),
),
migrations.AlterField(
model_name='continuationannotation',
name='start_annotation',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='continuation_annotations', to='lidia.annotation'),
),
migrations.AlterField(
model_name='lidiaterm',
name='term',
field=models.CharField(max_length=100, verbose_name='LIDIA term'),
),
migrations.AlterField(
model_name='lidiaterm',
name='vocab',
field=models.CharField(choices=[('lol', 'Lexicon of Linguistics'), ('custom', 'custom')], max_length=6, verbose_name='vocabulary'),
),
migrations.AlterField(
model_name='termgroup',
name='annotation',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='termgroups', to='lidia.annotation'),
),
migrations.AlterField(
model_name='termgroup',
name='articleterm',
field=models.ForeignKey(help_text='Term that was used in the resource', null=True, on_delete=django.db.models.deletion.CASCADE, to='lidia.articleterm', verbose_name='article term'),
),
migrations.AlterField(
model_name='termgroup',
name='lidiaterm',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='lidia.lidiaterm', verbose_name='LIDIA term'),
),
migrations.AlterField(
model_name='termgroup',
name='termtype',
field=models.CharField(choices=[('definiendum', 'Definiendum'), ('definiens', 'Definiens'), ('other', 'Other')], max_length=11, null=True, verbose_name='term type'),
),
]
Loading

0 comments on commit 7357f5b

Please sign in to comment.