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

refactor!: drop stanbol related code functionality #467

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
45 changes: 1 addition & 44 deletions apis_core/apis_entities/edit_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
get_generic_triple_table,
LabelTableEdit,
)
from .forms import get_entities_form, GenericEntitiesStanbolForm
from .forms import get_entities_form
from .views import set_session_variables
from ..apis_vocabularies.models import TextType
from apis_core.utils import caching
Expand Down Expand Up @@ -120,8 +120,6 @@ def get(self, request, *args, **kwargs):
"object_lod": object_lod,
"apis_bibsonomy": apis_bibsonomy,
}
form_merge_with = GenericEntitiesStanbolForm(self.entity, ent_merge_pk=self.pk)
context["form_merge_with"] = form_merge_with
return HttpResponse(template.render(request=request, context=context))

def post(self, request, *args, **kwargs):
Expand All @@ -142,12 +140,6 @@ def post(self, request, *args, **kwargs):
"entity_type": self.entity,
"instance": self.instance,
}
if self.entity.lower() != "place":
form_merge_with = GenericEntitiesStanbolForm(
self.entity, ent_merge_pk=self.pk
)
context["form_merge_with"] = form_merge_with
return TemplateResponse(request, template, context=context)
return HttpResponse(template.render(request=request, context=context))


Expand Down Expand Up @@ -200,41 +192,6 @@ def post(self, request, *args, **kwargs):
)


@method_decorator(login_required, name="dispatch")
class GenericEntitiesCreateStanbolView(EntityMixin, View):
def post(self, request, *args, **kwargs):
ent_merge_pk = kwargs.get("ent_merge_pk", False)
if ent_merge_pk:
form = GenericEntitiesStanbolForm(
self.entity, request.POST, ent_merge_pk=ent_merge_pk
)
else:
form = GenericEntitiesStanbolForm(self.entity, request.POST)
# form = form(request.POST)
if form.is_valid():
entity_2 = form.save()
if ent_merge_pk:
entity_2.merge_with(int(ent_merge_pk))
return redirect(
reverse(
"apis:apis_entities:generic_entities_edit_view",
kwargs={"pk": entity_2.pk, "entity": self.entity},
)
)
else:
permissions = {
"create": request.user.has_perm(
"apis_entities.add_{}".format(self.entity)
)
}
template = get_template("apis_entities/create_generic.html")
return HttpResponse(
template.render(
request=request, context={"permissions": permissions, "form": form}
)
)


@method_decorator(login_required, name="dispatch")
class GenericEntitiesDeleteView(EntityInstanceMixin, DeleteView):
# model = ContentType.objects.get(
Expand Down
44 changes: 0 additions & 44 deletions apis_core/apis_entities/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,50 +242,6 @@ def save(self, *args, **kwargs):
return GenericEntitiesForm


class GenericEntitiesStanbolForm(forms.Form):
def save(self, *args, **kwargs):
form_uri = self.cleaned_data["entity"]
uri, _ = Uri.objects.get_or_create(uri=form_uri)
return uri.root_object

def __init__(self, entity, *args, **kwargs):

attrs = {
"data-placeholder": "Type to get suggestions",
"data-minimum-input-length": getattr(settings, "APIS_MIN_CHAR", 3),
"data-html": True,
"style": "width: auto",
}
ent_merge_pk = kwargs.pop("ent_merge_pk", False)
super(GenericEntitiesStanbolForm, self).__init__(*args, **kwargs)
self.entity = entity
self.helper = FormHelper()
form_kwargs = {"entity": entity}
url = reverse(
"apis:apis_entities:generic_entities_autocomplete",
args=[entity.title(), "remove"],
)
label = "Create {} from reference resources".format(entity.title())
button_label = "Create"
if ent_merge_pk:
form_kwargs["ent_merge_pk"] = ent_merge_pk
url = reverse(
"apis:apis_entities:generic_entities_autocomplete",
args=[entity.title(), ent_merge_pk],
)
label = "Search for {0} in reference resources or db".format(entity.title())
button_label = "Merge"
self.helper.form_action = reverse(
"apis:apis_entities:generic_entities_stanbol_create", kwargs=form_kwargs
)
self.helper.add_input(Submit("submit", button_label))
self.fields["entity"] = autocomplete.Select2ListCreateChoiceField(
label=label,
widget=ListSelect2(url=url, attrs=attrs),
validators=[URLValidator],
)


class PersonResolveUriForm(forms.Form):
# person = forms.CharField(label=False, widget=al.TextWidget('PersonAutocomplete'))
person = forms.CharField(label=False)
Expand Down
11 changes: 0 additions & 11 deletions apis_core/apis_entities/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
)

# from .views import ReversionCompareView TODO: add again when import is fixed
from .edit_generic import GenericEntitiesCreateStanbolView
from .api_views import GetOrCreateEntity

app_name = "apis_entities"
Expand Down Expand Up @@ -46,16 +45,6 @@
]

autocomplete_patterns = [
path(
"createstanbol/<slug:entity>/<int:ent_merge_pk>/",
GenericEntitiesCreateStanbolView.as_view(),
name="generic_entities_stanbol_create",
),
path(
"createstanbol/<slug:entity>/",
GenericEntitiesCreateStanbolView.as_view(),
name="generic_entities_stanbol_create",
),
path(
"<slug:entity>/<int:ent_merge_pk>/",
GenericEntitiesAutocomplete.as_view(),
Expand Down
3 changes: 0 additions & 3 deletions apis_core/apis_entities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from .forms import (
GenericFilterFormHelper,
PersonResolveUriForm,
GenericEntitiesStanbolForm,
)
from .tables import get_entities_table
from apis_core.utils.helpers import get_member_for_entity
Expand Down Expand Up @@ -158,8 +157,6 @@ def get_context_data(self, **kwargs):
context["app_name"] = "apis_entities"
context["docstring"] = f"{model.__doc__}"

context["entity_create_stanbol"] = GenericEntitiesStanbolForm(self.entity)

if "browsing" in settings.INSTALLED_APPS:
from browsing.models import BrowsConf

Expand Down
12 changes: 0 additions & 12 deletions apis_core/apis_metainfo/templates/generic_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -359,17 +359,5 @@ <h1>{{ data.title }}</h1>

{% if 'entities' in APPS %}{% endif %}

{% if user.is_authenticated %}

{% if entity_create_stanbol %}
<div class="card">
<div class="card-header">
<h4>Import new {{ entity|title }} from GND</h4>
</div>
<div class="card-body">{% crispy entity_create_stanbol entity_create_stanbol.helper %}</div>
</div>
{% endif %}
{% endif %}

</div>
{% endblock %}
Loading