def post(self, request, container_name): _set_user_props(request.user) container = get_object_or_404(models.Container, name=container_name) upload_form = forms.SFTMFileUpload(request.POST, request.FILES) edit_form = forms.ContainerCreateForm(request.POST, instance=container) if 'upload' in request.POST: if not request.user.can_upload: raise PermissionDenied if upload_form.is_valid(): uploaded_file = upload_form.save() url = reverse('container', args=[container_name]) return redirect('%s?highlight=%s' % (url, uploaded_file.id)) elif 'description' in request.POST: if edit_form.is_valid(): if not container.name: container.name = str(uuid.uuid4()) edit_form.save() return redirect(reverse('container', args=[container.name])) files = models.SFTMFile.objects.filter(container=container) env = _get_env({ 'container': container, 'files': files, 'upload_form': upload_form, 'edit_form': edit_form }) return render(request, 'container.html', env)
def get(self, request): _set_user_props(request.user) if request.user.can_download: containers = self._list_containers(request) else: containers = [] form = forms.ContainerCreateForm() env = _get_env({'containers': containers, 'form': form}) return render(request, 'containers.html', env)
def post(self, request): _set_user_props(request.user) if not request.user.can_upload: raise PermissionDenied form = forms.ContainerCreateForm(request.POST) if form.is_valid(): container = form.save(commit=False) if not container.name: container.name = str(uuid.uuid4()) container.save() return redirect(reverse('container', args=[container.name])) containers = self._list_containers(request) env = _get_env({'containers': containers, 'form': form}) return render(request, 'containers.html', env)
def get(self, request, container_name): _set_user_props(request.user) if not request.user.can_download: raise Http404 container = get_object_or_404(models.Container, name=container_name) if container.requires_auth and not request.user.is_authenticated: raise Http404 files = models.SFTMFile.objects.filter(container=container) upload_form = forms.SFTMFileUpload(initial={'container': container}) edit_form = forms.ContainerCreateForm(instance=container) env = _get_env({ 'container': container, 'files': files, 'upload_form': upload_form, 'edit_form': edit_form }) return render(request, 'container.html', env)
def post(self, request, container_name): _set_user_props(request.user) upload_form = forms.SFTMFileUpload(request.POST, request.FILES) if upload_form.is_valid(): if not request.user.can_upload: raise PermissionDenied uploaded_file = upload_form.save(commit=False) try: container = models.Container.objects.get(name=container_name) except models.Container.DoesNotExist: # if container does not exist, we create it container_form = forms.ContainerCreateForm() container = container_form.save(commit=False) container.name = container_name container.listable = True container.requires_auth = True container.save() uploaded_file.container = container uploaded_file.save() return Response("file correctly upload in " + container_name, status=200) return Response(upload_form.errors, status=500)