69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
# passerelle - uniform access to multiple data sources and services
|
|
# Copyright (C) 2015-2016 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 json
|
|
|
|
from django.core.files.storage import default_storage
|
|
from django.core.urlresolvers import reverse
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.generic.detail import SingleObjectMixin, DetailView
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
|
from django.views.generic.base import View
|
|
|
|
from passerelle import utils
|
|
|
|
from .models import ParisPocGru
|
|
from .forms import ParisPocGruForm
|
|
|
|
class ParisPocGruCreateView(CreateView):
|
|
model = ParisPocGru
|
|
form_class = ParisPocGruForm
|
|
template_name = 'passerelle/manage/service_form.html'
|
|
|
|
|
|
class ParisPocGruUpdateView(UpdateView):
|
|
model = ParisPocGru
|
|
form_class = ParisPocGruForm
|
|
|
|
|
|
class ParisPocGruDeleteView(DeleteView):
|
|
model = ParisPocGru
|
|
|
|
def get_success_url(self):
|
|
return reverse('manage-home')
|
|
|
|
|
|
class ParisPocGruDetailView(DetailView):
|
|
model = ParisPocGru
|
|
|
|
|
|
class EndpointView(View, SingleObjectMixin):
|
|
model = ParisPocGru
|
|
|
|
@method_decorator(csrf_exempt)
|
|
def dispatch(self, request, *args, **kwargs):
|
|
filename = 'paris-poc-gru-dump-%s.txt' % self.get_object().slug
|
|
with default_storage.open(filename, mode='a') as fp:
|
|
fp.write('%(datetime)s %(method)s %(qs)s\n%(body)s\n\n' % {
|
|
'datetime': datetime.datetime.now(),
|
|
'method': request.method,
|
|
'qs': request.environ.get('QUERY_STRING'),
|
|
'body': request.body,
|
|
})
|
|
return utils.response_for_json(request, {})
|