Ejemplo n.º 1
0
    def get(self, request, filetype, project_slug,
            contractor_slug, filename):
        project = get_object_or_404(Project, slug=project_slug)
        if contractor_slug == 'x':
            contractor = None
        else:
            contractor = get_object_or_404(Contractor, slug=contractor_slug)

        if not has_access(request.user, project, contractor):
            return HttpResponseForbidden()

        if filetype == 'reports':
            directory = directories.reports_dir(project, contractor)
        elif filetype == 'results':
            directory = directories.reports_dir(project, contractor)
        elif filetype == 'locations':
            logger.debug("Looking for {0}".format(filename))
            directory = directories.location_shapefile_dir(project, contractor)
            logger.debug("Trying in {0}".format(directory))
            for path in directories.all_files_in(directory):
                logger.debug("... {0}".format(path))
                if os.path.basename(path) == filename:
                    directory = os.path.dirname(path)
                    break
            else:
                raise http.Http404()
        elif filetype == 'organization':
            directory = directories.organization_files_dir(
                project.organization)
        elif filetype == 'hydrovakken':
            directory = directories.hydrovakken_dir(project)
            for path in directories.all_files_in(directory):
                if os.path.basename(path) == filename:
                    directory = os.path.dirname(path)
                    break
            else:
                raise http.Http404()
        elif filetype == 'contractor_hydrovakken':
            directory = directories.shapefile_dir(project, contractor)
            for path in directories.all_files_in(directory):
                if os.path.basename(path) == filename:
                    directory = os.path.dirname(path)
                    break
            else:
                raise http.Http404()
        else:
            return HttpResponseForbidden()

        path = os.path.join(directory, filename)

        if not os.path.exists(path):
            raise http.Http404()

        return serve(request, path, '/')
Ejemplo n.º 2
0
 def _reports_files(self):
     for contractor in self.project.contractor_set.all():
         if has_access(self.user, self.project, contractor):
             for path in directories.files_in(
                 directories.reports_dir(self.project, contractor)):
                     yield {
                     'type': 'Rapporten {0}'.format(
                         contractor.organization.name),
                     'filename': os.path.basename(path),
                     'size': directories.human_size(path),
                     'url': self._make_url('reports',
                                           self.project,
                                           contractor,
                                           path)
                     }
Ejemplo n.º 3
0
 def get_directory(contractor):
     return directories.reports_dir(contractor.project, contractor)