|
1 |
# passerelle - uniform access to multiple data sources and services
|
|
2 |
# Copyright (C) 2019 Entr'ouvert
|
|
3 |
#
|
|
4 |
# This program is free software: you can redistribute it and/or modify it
|
|
5 |
# under the terms of the GNU Affero General Public License as published
|
|
6 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU Affero General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU Affero General Public License
|
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
|
|
17 |
from django.utils import functional
|
|
18 |
|
|
19 |
|
|
20 |
class ResourceChildViewMixin(object):
|
|
21 |
'''Mixin to help implementing view for child objects of resource objets.'''
|
|
22 |
|
|
23 |
@property
|
|
24 |
def resource_class(self):
|
|
25 |
field = self.model._meta.get_field('resource')
|
|
26 |
return field.related_model
|
|
27 |
|
|
28 |
@property
|
|
29 |
def model_verbose_name(self):
|
|
30 |
return self.model._meta.verbose_name
|
|
31 |
|
|
32 |
@property
|
|
33 |
def model_verbose_name_plural(self):
|
|
34 |
return self.model._meta.verbose_name_plural
|
|
35 |
|
|
36 |
@functional.cached_property
|
|
37 |
def resource(self):
|
|
38 |
return self.resource_class.objects.get(slug=self.kwargs['slug'])
|
|
39 |
|
|
40 |
def get_queryset(self):
|
|
41 |
qs = super(ResourceChildViewMixin, self).get_queryset()
|
|
42 |
return qs.filter(resource=self.resource)
|
|
43 |
|
|
44 |
def get_success_url(self):
|
|
45 |
return self.resource.get_absolute_url()
|
|
46 |
|
|
47 |
|
0 |
|
-
|