admin: add source delete view
This commit is contained in:
parent
61b79e90e5
commit
e44f6cff7e
|
@ -9,11 +9,9 @@ urlpatterns = [
|
|||
name='applications'),
|
||||
path('applications/create/', applications.ApplicationCreateView.as_view(),
|
||||
name='application-create'),
|
||||
path('sources/', sources.SourceListView.as_view(),
|
||||
name='sources'),
|
||||
path('sources/create/', sources.SourceCreateView.as_view(),
|
||||
name='source-create'),
|
||||
path('sources/<uuid:pk>/', sources.SourceUpdateView.as_view(),
|
||||
name='source-update'),
|
||||
path('sources/', sources.SourceListView.as_view(), name='sources'),
|
||||
path('sources/create/', sources.SourceCreateView.as_view(), name='source-create'),
|
||||
path('sources/<uuid:pk>/update/', sources.SourceUpdateView.as_view(), name='source-update'),
|
||||
path('sources/<uuid:pk>/delete/', sources.SourceDeleteView.as_view(), name='source-delete'),
|
||||
# path('api/v1/', include('passbook.admin.api.v1.urls'))
|
||||
]
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
"""passbook Source administration"""
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.http import Http404
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import CreateView, ListView, UpdateView
|
||||
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||||
|
||||
from passbook.admin.mixins import AdminRequiredMixin
|
||||
from passbook.core.models import Source
|
||||
|
@ -31,6 +32,8 @@ class SourceCreateView(SuccessMessageMixin, AdminRequiredMixin, CreateView):
|
|||
def get_form_class(self):
|
||||
source_type = self.request.GET.get('type')
|
||||
model = next(x if x.__name__ == source_type else None for x in Source.__subclasses__())
|
||||
if not model:
|
||||
raise Http404
|
||||
return path_to_class(model.form)
|
||||
|
||||
|
||||
|
@ -50,3 +53,16 @@ class SourceUpdateView(SuccessMessageMixin, AdminRequiredMixin, UpdateView):
|
|||
def get_object(self, queryset=None):
|
||||
obj = Source.objects.get(pk=self.kwargs.get('pk'))
|
||||
return obj.cast()
|
||||
|
||||
|
||||
class SourceDeleteView(SuccessMessageMixin, AdminRequiredMixin, DeleteView):
|
||||
"""Delete source"""
|
||||
|
||||
model = Source
|
||||
|
||||
success_url = reverse_lazy('passbook_admin:sources')
|
||||
success_message = _('Successfully updated Source')
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
obj = Source.objects.get(pk=self.kwargs.get('pk'))
|
||||
return obj.cast()
|
||||
|
|
Reference in a new issue