#########################################################################
#
# Copyright (C) 2016 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
"""
Provide views for doing an upload.
The upload process may be multi step so views are all handled internally here
by the view function.
The pattern to support separation of view/logic is each step in the upload
process is suffixed with "_step". The view for that step is suffixed with
"_step_view". The goal of separation of view/logic is to support various
programmatic uses of this API. The logic steps should not accept request objects
or return response objects.
State is stored in a UploaderSession object stored in the user's session.
This needs to be made more stateful by adding a model.
"""
import logging
from django.shortcuts import get_object_or_404
from django.core.exceptions import PermissionDenied
from django.contrib.auth.decorators import login_required
from .models import Upload
from .utils import json_response
[docs]
logger = logging.getLogger(__name__)
@login_required
[docs]
def delete(req, id):
upload = get_object_or_404(Upload, id=id)
if (not req.user.is_superuser and req.user != upload.user) or not req.user.is_authenticated:
raise PermissionDenied()
upload.delete()
return json_response(
dict(
success=True,
)
)