Skip to content

Commit

Permalink
refactor(apis_metainfo): drop Uri customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Mar 1, 2024
1 parent 5672ea9 commit 17bfcd2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 94 deletions.
11 changes: 0 additions & 11 deletions apis_core/apis_metainfo/filters.py

This file was deleted.

9 changes: 9 additions & 0 deletions apis_core/apis_metainfo/filtersets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import django_filters
from apis_core.generic.filtersets import GenericFilterSet


class UriFilterSet(GenericFilterSet):
uri = django_filters.CharFilter(lookup_expr="icontains")

class Meta(GenericFilterSet.Meta):
fields = ("uri",)
29 changes: 3 additions & 26 deletions apis_core/apis_metainfo/forms.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from dal import autocomplete
from django import forms
from django.core.exceptions import ValidationError
from apis_core.generic.forms import GenericModelForm

from .models import Uri


class UriForm(forms.ModelForm):
class Meta:
model = Uri
fields = "__all__"
widgets = {
"entity": autocomplete.ModelSelect2(
url="apis_core:apis_metainfo-ac:apis_tempentity-autocomplete"
),
}

class UriForm(GenericModelForm):
def __init__(self, *args, **kwargs):
super(UriForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = True
super().__init__(*args, **kwargs)
self.helper.form_class = "form-horizontal"
self.helper.label_class = "col-md-3"
self.helper.field_class = "col-md-9"
self.helper.add_input(
Submit("submit", "save"),
)


class UriFilterFormHelper(FormHelper):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.form_method = "GET"
self.helper.form_tag = False
self.add_input(Submit("filter", "Filter"))


class UriGetOrCreateForm(forms.Form):
Expand Down
10 changes: 4 additions & 6 deletions apis_core/apis_metainfo/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import django_tables2 as tables
from django.db.models import F
from django.utils.html import format_html
from apis_core.generic.tables import GenericTable

from .models import Uri

Expand Down Expand Up @@ -100,8 +101,7 @@ def generic_render_end_date_written(self, record, value):
)


class UriTable(tables.Table):
id = tables.LinkColumn()
class UriTable(GenericTable):
entity = tables.TemplateColumn(
"<a href='{{ record.root_object.get_absolute_url }}'>{{ record.root_object }}</a>",
orderable=True,
Expand All @@ -113,8 +113,6 @@ class UriTable(tables.Table):
verbose_name="Entity Type",
)

class Meta:
class Meta(GenericTable.Meta):
model = Uri
sequence = ("id", "uri")
fields = ("id", "uri", "entity", "ent_type")
attrs = {"class": "table table-responsive table-hover"}
fields = ["id", "desc", "entity", "ent_type"]
5 changes: 0 additions & 5 deletions apis_core/apis_metainfo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@
app_name = "apis_metainfo"

urlpatterns = [
path("apis/metainfo/uri/", views.UriListView.as_view(), name="uri_browse"),
path("uri/detail/<int:pk>", views.UriDetailView.as_view(), name="uri_detail"),
path("uri/create/", views.UriCreate.as_view(), name="uri_create"),
path("uri/edit/<int:pk>", views.UriUpdate.as_view(), name="uri_edit"),
path("uri/delete/<int:pk>", views.UriDelete.as_view(), name="uri_delete"),
path("uri/getorcreate/", views.UriGetOrCreate.as_view(), name="uri_get_or_create"),
]
48 changes: 2 additions & 46 deletions apis_core/apis_metainfo/views.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,6 @@
from django.conf import settings
from django.urls import reverse_lazy
from django.views.generic.detail import DetailView
from django.views.generic.edit import DeleteView, FormView, CreateView, UpdateView
from django.contrib.auth.mixins import LoginRequiredMixin
from django_tables2 import SingleTableMixin
from django_filters.views import FilterView
from django.views.generic.edit import FormView

from .filters import UriListFilter
from .forms import UriFilterFormHelper, UriForm, UriGetOrCreateForm
from .models import Uri
from .tables import UriTable


class UriListView(SingleTableMixin, FilterView):
model = Uri
filterset_class = UriListFilter
formhelper_class = UriFilterFormHelper
table_class = UriTable
template_name = getattr(settings, "APIS_LIST_VIEW_TEMPLATE", "generic_list.html")

def get_filterset(self, filterset_class):
kwargs = self.get_filterset_kwargs(filterset_class)
filterset = filterset_class(**kwargs)
filterset.form.helper = self.formhelper_class()
return filterset


class UriDetailView(DetailView):
model = Uri
template_name = "apis_metainfo/uri_detail.html"


class UriCreate(LoginRequiredMixin, CreateView):
model = Uri
form_class = UriForm


class UriUpdate(LoginRequiredMixin, UpdateView):
model = Uri
form_class = UriForm


class UriDelete(LoginRequiredMixin, DeleteView):
model = Uri
template_name = "confirm_delete.html"
success_url = reverse_lazy("apis_core:apis_metainfo:uri_browse")
from .forms import UriGetOrCreateForm


class UriGetOrCreate(FormView):
Expand Down

0 comments on commit 17bfcd2

Please sign in to comment.