Skip to content

Commit

Permalink
fix(apis_entities, apis_metainfo)!: drop texts
Browse files Browse the repository at this point in the history
Closes: #228, #7
  • Loading branch information
b1rger committed Sep 13, 2023
1 parent 7bc4a29 commit 063412f
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 347 deletions.
5 changes: 1 addition & 4 deletions apis_core/apis_entities/detail_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
LabelTableBase,
)
from apis_core.utils.utils import access_for_all
from .views import get_highlighted_texts
from apis_core.apis_relations.models import TempTriple
from apis_core.utils import caching
from apis_core.utils.settings import get_entity_settings_by_modelname
Expand Down Expand Up @@ -73,7 +72,6 @@ def get(self, request, *args, **kwargs):

# TODO RDF : Check / Adapt the following code to rdf architecture
object_lod = Uri.objects.filter(root_object=self.instance)
object_texts, ann_proj_form = get_highlighted_texts(request, self.instance)
object_labels = Label.objects.filter(temp_entity=self.instance)
tb_label = LabelTableBase(data=object_labels, prefix=entity.title()[:2] + "L-")
tb_label_open = request.GET.get("PL-page", None)
Expand All @@ -87,7 +85,7 @@ def get(self, request, *args, **kwargs):
)
tei = getattr(settings, "APIS_TEI_TEXTS", [])
if tei:
tei = set(tei) & set([x.kind.name for x in self.instance.text.all()])
tei = set(tei)
ceteicean_css = getattr(settings, "APIS_CETEICEAN_CSS", None)
ceteicean_js = getattr(settings, "APIS_CETEICEAN_JS", None)
openseadragon_js = getattr(settings, "APIS_OSD_JS", None)
Expand Down Expand Up @@ -160,7 +158,6 @@ def get_relevant_fields(instance):
"right_card": side_bar,
"no_merge_labels": no_merge_labels,
"object_lables": object_labels,
"object_texts": object_texts,
"object_lod": object_lod,
"tei": tei,
"ceteicean_css": ceteicean_css,
Expand Down
20 changes: 3 additions & 17 deletions apis_core/apis_entities/edit_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
get_generic_triple_table,
LabelTableEdit,
)
from .forms import get_entities_form, FullTextForm, GenericEntitiesStanbolForm
from .views import get_highlighted_texts
from .forms import get_entities_form, GenericEntitiesStanbolForm
from .views import set_session_variables
from ..apis_vocabularies.models import TextType
from apis_core.utils import caching
Expand Down Expand Up @@ -90,7 +89,6 @@ def get(self, request, *args, **kwargs):
)
form = get_entities_form(self.entity.title())
form = form(instance=self.instance)
form_text = FullTextForm(entity=self.entity.title(), instance=self.instance)
if "apis_highlighter" in settings.INSTALLED_APPS:
form_ann_agreement = SelectAnnotatorAgreement()
else:
Expand All @@ -114,7 +112,6 @@ def get(self, request, *args, **kwargs):
apis_bibsonomy = False
object_revisions = Version.objects.get_for_object(self.instance)
object_lod = Uri.objects.filter(root_object=self.instance)
object_texts, ann_proj_form = get_highlighted_texts(request, self.instance)
object_labels = Label.objects.filter(temp_entity=self.instance)
tb_label = LabelTableEdit(
data=object_labels, prefix=self.entity.title()[:2] + "L-"
Expand All @@ -126,13 +123,10 @@ def get(self, request, *args, **kwargs):
context = {
"entity_type": self.entity,
"form": form,
"form_text": form_text,
"instance": self.instance,
"right_card": side_bar,
"object_revisions": object_revisions,
"object_texts": object_texts,
"object_lod": object_lod,
"ann_proj_form": ann_proj_form,
"form_ann_agreement": form_ann_agreement,
"apis_bibsonomy": apis_bibsonomy,
}
Expand All @@ -143,10 +137,8 @@ def get(self, request, *args, **kwargs):
def post(self, request, *args, **kwargs):
form = get_entities_form(self.entity.title())
form = form(request.POST, instance=self.instance)
form_text = FullTextForm(request.POST, entity=self.entity.title())
if form.is_valid() and form_text.is_valid():
if form.is_valid():
entity_2 = form.save()
form_text.save(entity_2)
return redirect(
reverse(
"apis:apis_entities:generic_entities_edit_view",
Expand All @@ -158,7 +150,6 @@ def post(self, request, *args, **kwargs):
context = {
"form": form,
"entity_type": self.entity,
"form_text": form_text,
"instance": self.instance,
}
if self.entity.lower() != "place":
Expand All @@ -175,7 +166,6 @@ class GenericEntitiesCreateView(EntityMixin, View):
def get(self, request, *args, **kwargs):
form = get_entities_form(self.entity.title())
form = form()
form_text = FullTextForm(entity=self.entity.title())
permissions = {
"create": request.user.has_perm("entities.add_{}".format(self.entity))
}
Expand All @@ -187,18 +177,15 @@ def get(self, request, *args, **kwargs):
"entity_type": self.entity,
"permissions": permissions,
"form": form,
"form_text": form_text,
},
)
)

def post(self, request, *args, **kwargs):
form = get_entities_form(self.entity.title())
form = form(request.POST)
form_text = FullTextForm(request.POST, entity=self.entity.title())
if form.is_valid() and form_text.is_valid():
if form.is_valid():
entity_2 = form.save()
form_text.save(entity_2)
return redirect(
reverse(
"apis:apis_entities:generic_entities_detail_view",
Expand All @@ -218,7 +205,6 @@ def post(self, request, *args, **kwargs):
context={
"permissions": permissions,
"form": form,
"form_text": form_text,
},
)
)
Expand Down
63 changes: 1 addition & 62 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.forms import ModelMultipleChoiceField, ModelChoiceField
from django.urls import reverse

from apis_core.apis_metainfo.models import Text, Uri, Collection
from apis_core.apis_metainfo.models import Uri, Collection
from apis_core.apis_vocabularies.models import TextType
from apis_core.utils import DateParser, caching
from .fields import ListSelect2, Select2Multiple
Expand Down Expand Up @@ -271,67 +271,6 @@ def __init__(self, entity, *args, **kwargs):
)


class FullTextForm(forms.Form):
def save(self, entity):
cd = self.cleaned_data
text = None
for f in cd.keys():
text_type = TextType.objects.get(pk=f.split("_")[1])
text = Text.objects.filter(tempentityclass=entity, kind=text_type)
if text.count() == 1:
text = text[0]
text.text = cd[f]
text.save()
elif text.count() == 0:
text = Text(text=cd[f], kind=text_type)
text.save()
entity.text.add(text)
return text

def __init__(self, *args, **kwargs):
if "entity" in kwargs.keys():
entity = kwargs.pop("entity", None)
else:
entity = None
if "instance" in kwargs.keys():
instance = kwargs.pop("instance", None)
else:
instance = None
super(FullTextForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = "FullTextForm"
self.helper.form_tag = False
self.helper.help_text_inline = True
collections = []
if instance:
for i in instance.collection.all():
collections.append(i)
try:
if len(collections) > 0:
# TODO : make this filter call respect entity class hierarchy
# Here texttypes are searched for a given entity. But since this is an exact search
# for the entity, it does not regard any subclasses of the class to which a texttype
# was assigned
q = TextType.objects.filter(
entity__iexact=entity, collections__in=collections
)
else:
q = TextType.objects.filter(entity__iexact=entity)
for txt in q:
self.fields["text_" + str(txt.pk)] = forms.CharField(
label=txt.name,
help_text=txt.description,
required=False,
widget=forms.Textarea,
)
if instance:
for t in instance.text.all():
if "text_" + str(t.kind.pk) in self.fields.keys():
self.fields["text_" + str(t.kind.pk)].initial = t.text
except:
pass


class PersonResolveUriForm(forms.Form):
# person = forms.CharField(label=False, widget=al.TextWidget('PersonAutocomplete'))
person = forms.CharField(label=False)
Expand Down
1 change: 0 additions & 1 deletion apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class TempEntityClass(AbstractEntity):
verbose_name="End",
)
# TODO RDF: Make Text also a Subclass of RootObject
text = models.ManyToManyField("apis_metainfo.Text", blank=True)
collection = models.ManyToManyField("apis_metainfo.Collection")
status = models.CharField(max_length=100)
source = models.ForeignKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,48 +320,13 @@ <h4 class="card-title">{{ obj.0 }}</h4>
</div>
</div>
<div class="card">
<div class="card-header">
<h2>Texts</h2>
</div>
<div class="card-body">

{% if object.text.all %}
<div class="card-body">
<legend>Texts</legend>
{% for x in object.text.all %}
<div class="card card-default">
<div class="card-heading">

{% if x.kind.name in tei %}
<h4 class="card-title">TEI</h4>
{% else %}
<h4 class="card-title">{{ x.kind }}</h4>
{% endif %}

</div>

{% if x.kind.name in tei %}
<div class="card-body tei" id="teisource">{{ x.text }}</div>
<div id="teiviewer"></div>
{% else %}
<div class="card-body tei-text">{{ x.text }}</div>
{% endif %}

</div>
{% endfor %}
</div>
{% else %}
<div class="card-body">
<legend>No text provided for this {{ entity }}</legend>
</div>
{% endif %}

{% if iiif %}
<div class="card-body">
<div id="iiif" style="width: 100%; height: 400px" /></div>
{% endif %}
{% if iiif %}
<div class="card-body">
<div id="iiif" style="width: 100%; height: 400px"></div>
</div>
{% endif %}

</div>
</div>
</div>
{% endblock content %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ <h4 class="card-title">
class="card-collapse collapse"
role="tabcard"
aria-labelledby="headingFour">
<div class="card-body">

{% block texts %}
{% crispy form_text %}
{% endblock %}

</div>
<div class="card-body"></div>
</div>

{% block linkedOpenData %}
Expand Down
4 changes: 1 addition & 3 deletions apis_core/apis_entities/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
from rest_framework.test import APIClient
from django.contrib.auth.models import Permission

from apis_core.apis_metainfo.models import Text, Collection
from apis_core.apis_metainfo.models import Collection


class PermissionsModelTestCase(TestCase):
name = "test name"
first_name = "test first name"
text = "kjhkjsdhaslkdhadh lasdjalsk alsjdhaksjdh"
col_name = "Test collection"
start_date = "1.3.1930"
end_date = "4.6.1960"

@classmethod
def setUpTestData(cls):
# Set up data for the whole TestCase
cls.txt = Text.objects.create(text=cls.text)
cls.col = Collection.objects.create(name=cls.col_name)
cls.user = User.objects.create_user("testuser", "apisdev16")
pe = Permission.objects.get(name="Can change person")
Expand Down
35 changes: 1 addition & 34 deletions apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from apis_core.core.mixins import ListViewObjectFilterMixin

from apis_core.apis_metainfo.models import Uri, Text
from apis_core.apis_metainfo.models import Uri
from apis_core.utils.stanbolQueries import retrieve_obj
from apis_core.utils.utils import (
access_for_all,
Expand Down Expand Up @@ -66,39 +66,6 @@ def set_session_variables(request):
return request


@user_passes_test(access_for_all_function)
def get_highlighted_texts(request, instance):
if "apis_highlighter" in settings.INSTALLED_APPS:
set_ann_proj = request.session.get("annotation_project", 1)
entity_types_highlighter = request.session.get("entity_types_highlighter", None)
users_show = request.session.get("users_show_highlighter", None)
object_texts = [
{
"text": highlight_text_new(
x,
set_ann_proj=set_ann_proj,
types=entity_types_highlighter,
users_show=users_show,
)[0].strip(),
"id": x.pk,
"kind": x.kind,
}
for x in Text.objects.filter(tempentityclass=instance)
]
ann_proj_form = SelectAnnotationProject(
set_ann_proj=set_ann_proj,
entity_types_highlighter=entity_types_highlighter,
users_show_highlighter=users_show,
)
return object_texts, ann_proj_form
else:
object_texts = [
{"text": x.text, "id": x.pk, "kind": x.kind}
for x in Text.objects.filter(tempentityclass=instance)
]
return object_texts, False


############################################################################
############################################################################
#
Expand Down
3 changes: 1 addition & 2 deletions apis_core/apis_metainfo/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.contrib import admin

from .models import Source, Collection, Text, Uri
from .models import Source, Collection, Uri

admin.site.register(Source)
admin.site.register(Collection)
admin.site.register(Text)
admin.site.register(Uri)
Loading

0 comments on commit 063412f

Please sign in to comment.