Skip to content

Commit

Permalink
Merge pull request #7 from CentreForDigitalHumanities/feature/admin
Browse files Browse the repository at this point in the history
Feature/admin
  • Loading branch information
tijmenbaarda authored Nov 10, 2023
2 parents 4acf7be + 58f4bb7 commit ba1a75f
Show file tree
Hide file tree
Showing 19 changed files with 698 additions and 145 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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
41 changes: 38 additions & 3 deletions lidiabrowser/lidia/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
from django.contrib import admin

from .models import Annotation, Publication
from .models import (
Annotation,
ArticleTerm,
ContinuationAnnotation,
LidiaTerm,
Publication,
Language,
TermGroup,
Category,
)


class ContinuationInline(admin.TabularInline):
model = ContinuationAnnotation
fk_name = "start_annotation"
ordering = ("sort_index",)
fields = ["textselection", "sort_index"]
extra = 0


class TermGroupInline(admin.TabularInline):
model = TermGroup
fk_name = "annotation"
ordering = ("index",)
fields = ["termtype", "articleterm", "category", "lidiaterm"]
extra = 0


class AnnotationAdmin(admin.ModelAdmin):
pass
list_display = ["zotero_annotation", "lidia_id", "parent_attachment", "argname", "arglang", "page_start"]
list_filter = ["parent_attachment", "arglang"]
ordering = ("parent_attachment", "sort_index")
inlines = [
ContinuationInline,
TermGroupInline,
]


class PublicationAdmin(admin.ModelAdmin):
pass
list_display = ["zotero_id", "attachment_id", "title"]


admin.site.register(Annotation, AnnotationAdmin)
admin.site.register(Publication, PublicationAdmin)
admin.site.register(Language)
admin.site.register(Category)
admin.site.register(LidiaTerm)
admin.site.register(ArticleTerm)
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions lidiabrowser/lidia/management/commands/initgroups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group, Permission


class Command(BaseCommand):
help = "Create user groups that allow viewing all or restricted "\
"annotation data"

def handle(self, *args, **options):
# For now, only create a 'view all' group - no distinction yet
# between all or restricted access
view_all, _ = Group.objects.get_or_create(name="view_all")
models = [
'publication', 'language', 'annotation', 'articleterm',
'lidiaterm', 'category', 'termgroup'
]
permissions = []
for model in models:
permissions.append(Permission.objects.get_by_natural_key(
"view_" + model, "lidia", model
))
view_all.permissions.add(*permissions)
Loading

0 comments on commit ba1a75f

Please sign in to comment.