fix PEP8 / code style (#32533)
This commit is contained in:
parent
831469db1b
commit
39c2b61daf
|
@ -1,8 +1,25 @@
|
|||
# passerelle - uniform access to multiple data sources and services
|
||||
# Copyright (C) 2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||
from django.forms import models as model_forms
|
||||
from django.views.generic import *
|
||||
from django.views.generic import (
|
||||
DetailView, ListView, CreateView, UpdateView, DeleteView, FormView)
|
||||
from django.http import Http404
|
||||
|
||||
from .models import ApiUser, AccessRight, LoggingParameters, AvailabilityParameters, ResourceStatus
|
||||
|
@ -25,12 +42,11 @@ class ResourceView(DetailView):
|
|||
def get_context_data(self, slug=None, **kwargs):
|
||||
context = super(ResourceView, self).get_context_data(**kwargs)
|
||||
context['site_base_uri'] = '%s://%s' % (
|
||||
'https' if self.request.is_secure() else 'http',
|
||||
self.request.get_host())
|
||||
'https' if self.request.is_secure() else 'http',
|
||||
self.request.get_host())
|
||||
context['absolute_uri'] = '%s%s' % (
|
||||
context['site_base_uri'],
|
||||
self.request.path)
|
||||
|
||||
context['site_base_uri'],
|
||||
self.request.path)
|
||||
return context
|
||||
|
||||
|
||||
|
@ -110,8 +126,8 @@ class LoggingParametersUpdateView(FormView):
|
|||
|
||||
def get_form_class(self):
|
||||
form_class = model_forms.modelform_factory(
|
||||
LoggingParameters,
|
||||
fields=['log_level', 'trace_emails'])
|
||||
LoggingParameters,
|
||||
fields=['log_level', 'trace_emails'])
|
||||
form_class.base_fields['trace_emails'].widget.attrs['rows'] = '3'
|
||||
return form_class
|
||||
|
||||
|
@ -151,8 +167,8 @@ class ManageAvailabilityView(FormView):
|
|||
|
||||
def get_form_class(self):
|
||||
form_class = model_forms.modelform_factory(
|
||||
AvailabilityParameters,
|
||||
fields=['run_check'])
|
||||
AvailabilityParameters,
|
||||
fields=['run_check'])
|
||||
return form_class
|
||||
|
||||
def get_initial(self):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# passerelle - uniform access to multiple data sources and services
|
||||
# Copyright (C) 2016 Entr'ouvert
|
||||
# Copyright (C) 2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
|
@ -17,6 +17,7 @@
|
|||
from django.utils.text import slugify
|
||||
from django import forms
|
||||
|
||||
|
||||
class GenericConnectorForm(forms.ModelForm):
|
||||
def save(self, commit=True):
|
||||
if not self.instance.slug:
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
# passerelle - uniform access to multiple data sources and services
|
||||
# Copyright (C) 2019 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import hashlib
|
||||
import inspect
|
||||
|
@ -9,10 +25,11 @@ from django.core.cache import cache
|
|||
from django.core.exceptions import PermissionDenied
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect, Http404
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic import (RedirectView, View, TemplateView, CreateView,
|
||||
DeleteView, UpdateView, DetailView, ListView)
|
||||
from django.views.generic import (
|
||||
RedirectView, View, TemplateView, CreateView, DeleteView, UpdateView,
|
||||
DetailView, ListView)
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
from django.conf import settings
|
||||
from django.shortcuts import resolve_url
|
||||
|
@ -26,29 +43,31 @@ from django.forms.widgets import ClearableFileInput
|
|||
from dateutil import parser as date_parser
|
||||
from jsonschema import validate, ValidationError
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
from mellon.utils import get_idps
|
||||
else:
|
||||
get_idps = lambda: []
|
||||
|
||||
from passerelle.base.models import BaseResource, ResourceLog
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
from .utils import to_json, response_for_json, is_authorized
|
||||
from .utils import to_json, is_authorized
|
||||
from .forms import GenericConnectorForm
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
from mellon.utils import get_idps
|
||||
else:
|
||||
def get_idps():
|
||||
return []
|
||||
|
||||
|
||||
def get_all_apps():
|
||||
return [x for x in apps.get_models() if issubclass(x, BaseResource) and \
|
||||
x.is_enabled() ]
|
||||
return [x for x in apps.get_models() if issubclass(x, BaseResource) and x.is_enabled()]
|
||||
|
||||
|
||||
def login(request, *args, **kwargs):
|
||||
if any(get_idps()):
|
||||
if not 'next' in request.GET:
|
||||
if 'next' not in request.GET:
|
||||
return HttpResponseRedirect(resolve_url('mellon_login'))
|
||||
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' + request.GET.get('next'))
|
||||
return auth_views.login(request, *args, **kwargs)
|
||||
|
||||
|
||||
def logout(request, next_page=None):
|
||||
if any(get_idps()):
|
||||
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
||||
|
@ -59,12 +78,16 @@ def logout(request, next_page=None):
|
|||
next_page = '/'
|
||||
return HttpResponseRedirect(next_page)
|
||||
|
||||
|
||||
def menu_json(request):
|
||||
label = _('Web Services')
|
||||
json_str = json.dumps([{'label': force_text(label),
|
||||
'slug': 'passerelle',
|
||||
'url': request.build_absolute_uri(reverse('manage-home'))
|
||||
}])
|
||||
json_str = json.dumps([
|
||||
{
|
||||
'label': force_text(label),
|
||||
'slug': 'passerelle',
|
||||
'url': request.build_absolute_uri(reverse('manage-home'))
|
||||
}
|
||||
])
|
||||
content_type = 'application/json'
|
||||
for variable in ('jsonpCallback', 'callback'):
|
||||
if variable in request.GET:
|
||||
|
@ -122,23 +145,23 @@ class GenericConnectorMixin(object):
|
|||
if hasattr(app, 'get_form_class'):
|
||||
self.form_class = app.get_form_class()
|
||||
else:
|
||||
self.form_class = modelform_factory(self.model,
|
||||
form=GenericConnectorForm, exclude=('slug', 'users'))
|
||||
self.form_class = modelform_factory(
|
||||
self.model,
|
||||
form=GenericConnectorForm,
|
||||
exclude=('slug', 'users'))
|
||||
for field in self.form_class.base_fields.values():
|
||||
if isinstance(field.widget, ClearableFileInput):
|
||||
field.widget.template_with_initial = ''\
|
||||
'%(initial_text)s: %(initial)s '\
|
||||
'%(clear_template)s<br />%(input_text)s: %(input)s'
|
||||
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
self.init_stuff(request, *args, **kwargs)
|
||||
return super(GenericConnectorMixin, self).dispatch(
|
||||
request, *args, **kwargs)
|
||||
request, *args, **kwargs)
|
||||
|
||||
|
||||
class GenericConnectorView(GenericConnectorMixin, DetailView):
|
||||
|
||||
def get_context_data(self, slug=None, **kwargs):
|
||||
context = super(GenericConnectorView, self).get_context_data(**kwargs)
|
||||
context['has_check_status'] = not hasattr(
|
||||
|
@ -193,13 +216,13 @@ class GenericViewLogsConnectorView(GenericConnectorMixin, ListView):
|
|||
|
||||
def get_queryset(self):
|
||||
qs = ResourceLog.objects.filter(
|
||||
appname=self.kwargs['connector'],
|
||||
slug=self.kwargs['slug']).order_by('-timestamp')
|
||||
appname=self.kwargs['connector'],
|
||||
slug=self.kwargs['slug']).order_by('-timestamp')
|
||||
query = self.request.GET.get('q')
|
||||
if query:
|
||||
try:
|
||||
date = date_parser.parse(query, dayfirst=True)
|
||||
except:
|
||||
except Exception:
|
||||
qs = qs.filter(message__icontains=query)
|
||||
else:
|
||||
date = make_aware(date)
|
||||
|
@ -225,9 +248,9 @@ class GenericLogView(GenericConnectorMixin, DetailView):
|
|||
context = super(GenericLogView, self).get_context_data(**kwargs)
|
||||
try:
|
||||
context['logline'] = ResourceLog.objects.get(
|
||||
pk=self.kwargs['log_pk'],
|
||||
appname=self.kwargs['connector'],
|
||||
slug=self.kwargs['slug'])
|
||||
pk=self.kwargs['log_pk'],
|
||||
appname=self.kwargs['connector'],
|
||||
slug=self.kwargs['slug'])
|
||||
except ResourceLog.DoesNotExist:
|
||||
raise Http404()
|
||||
return context
|
||||
|
@ -281,7 +304,7 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View):
|
|||
if self.endpoint.endpoint_info.parameters:
|
||||
# check and convert parameter values
|
||||
for parameter, parameter_info in self.endpoint.endpoint_info.parameters.items():
|
||||
if not parameter in d:
|
||||
if parameter not in d:
|
||||
continue
|
||||
if parameter_info.get('type') == 'bool':
|
||||
if d[parameter].lower() in ('true', 'on'):
|
||||
|
@ -312,7 +335,6 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View):
|
|||
self.init_stuff(request, *args, **kwargs)
|
||||
connector = self.get_object()
|
||||
self.endpoint = None
|
||||
endpoints = []
|
||||
for name, method in inspect.getmembers(connector):
|
||||
if not hasattr(method, 'endpoint_info'):
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue