Exemplo n.º 1
0
    def browse_repository(self, request: HttpRequest, rid, repo_slug, query_string='', state_slug=None) -> HttpResponse:
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        result = self.browse_repo_inner(rid, query_string, state_slug=state_slug)
        if isinstance(result, str):  # sha1/sha256/md5
            return HttpResponse(result)
        elif isinstance(result, Element):
            return get_file(request, eid=result.pk, element=result)
        assert isinstance(result, dict)

        new_query_string = ''
        bread_crumbs = [(_('Root'), self.get_browse_url(repo, new_query_string, state_slug=state_slug))]
        while len(result) == 1 and isinstance(result, dict):
            path_component, result = result.popitem()
            new_query_string += path_component + '/'
            bread_crumbs.append((path_component, self.get_browse_url(repo, new_query_string, state_slug=state_slug)))
        if isinstance(result, set):
            url_list = []
            for elt in result:
                new_gavf_elt_filename = new_query_string + elt.filename
                elt_url = self.get_browse_url(repo, new_gavf_elt_filename, state_slug=state_slug)
                url_list += [(new_gavf_elt_filename, elt_url, elt.id),
                             (new_gavf_elt_filename + '.sha1', elt_url + '.sha1', None),
                             (new_gavf_elt_filename + '.sha256', elt_url + '.sha256', None),
                             (new_gavf_elt_filename + '.md5', elt_url + '.md5', None),
                             ]
        else:
            assert isinstance(result, dict)
            url_list = [(new_query_string + key,
                         self.get_browse_url(repo, new_query_string + key, state_slug=state_slug), None)
                        for key in result]
        template_values = {'repo': repo, 'upload_allowed': repo.upload_allowed(request), 'repo_slug': repo_slug,
                           'admin': True, 'paths': url_list, 'request_path': new_query_string, 'state_slug': state_slug,
                           'bread_crumbs': bread_crumbs, }
        status_code = 200 if url_list else 404
        return TemplateResponse(request, 'repositories/maven3/browse.html', template_values, status=status_code)
Exemplo n.º 2
0
    def browse_repository(self, request: HttpRequest, rid, repo_slug, query_string='', state_slug=None) -> HttpResponse:
        repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
        result = self.browse_repo_inner(rid, query_string, state_slug=state_slug)
        if isinstance(result, str):  # sha1/sha256/md5
            return HttpResponse(result)
        elif isinstance(result, Element):
            return get_file(request, eid=result.pk, element=result)
        assert isinstance(result, dict)

        new_query_string = ''
        bread_crumbs = [(_('Root'), self.get_browse_url(repo, new_query_string, state_slug=state_slug))]
        while len(result) == 1 and isinstance(result, dict):
            path_component, result = result.popitem()
            new_query_string += path_component + '/'
            bread_crumbs.append((path_component, self.get_browse_url(repo, new_query_string, state_slug=state_slug)))
        if isinstance(result, set):
            url_list = []
            for elt in result:
                new_gavf_elt_filename = new_query_string + elt.filename
                elt_url = self.get_browse_url(repo, new_gavf_elt_filename, state_slug=state_slug)
                url_list += [(new_gavf_elt_filename, elt_url, elt.id),
                             (new_gavf_elt_filename + '.sha1', elt_url + '.sha1', None),
                             (new_gavf_elt_filename + '.sha256', elt_url + '.sha256', None),
                             (new_gavf_elt_filename + '.md5', elt_url + '.md5', None),
                             ]
        else:
            assert isinstance(result, dict)
            url_list = [(new_query_string + key,
                         self.get_browse_url(repo, new_query_string + key, state_slug=state_slug), None)
                        for key in result]
        template_values = {'repo': repo, 'upload_allowed': repo.upload_allowed(request), 'repo_slug': repo_slug,
                           'admin': True, 'paths': url_list, 'request_path': new_query_string, 'state_slug': state_slug,
                           'bread_crumbs': bread_crumbs, }
        status_code = 200 if url_list else 404
        return TemplateResponse(request, 'repositories/maven3/browse.html', template_values, status=status_code)
Exemplo n.º 3
0
 def download(self, request, rid, repo_slug, state_slug=None, filename=None):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState, repository=repo, name=state_slug)
         base_query = base_query.filter(states=state)
     element = get_object_or_404(base_query, filename=filename)
     from moneta.views import get_file
     return get_file(request, element.pk)
Exemplo n.º 4
0
 def get_file(self, request, rid, repo_slug, state_slug, folder, filename):
     """
     Return a HttpResponse
     :param request: HttpRequest
     :raise:
     """
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     q = Element.objects.filter(repository__id=rid, filename=filename)[0:1]
     q = list(q)
     if len(q) == 0:
         raise Http404
     element = q[0]
     return get_file(request, element.id, compression=None, path='', element=element, name=None)
Exemplo n.º 5
0
 def get_box(self, request: HttpRequest, rid, repo_slug, eid, archive,
             version, provider):
     repo = get_object_or_404(Repository.reader_queryset(request),
                              id=rid,
                              archive_type=self.archive_type)
     elements = list(Element.objects.filter(repository=repo, pk=eid)[0:1])
     if not elements:
         return JsonResponse({
             'errors': [
                 'Not found',
             ],
         })
     return get_file(request, eid, element=elements[0])
Exemplo n.º 6
0
 def get_box(self, request: HttpRequest, rid, repo_slug, eid, archive, version, provider):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     # noinspection PyUnusedLocal
     archive = archive
     # noinspection PyUnusedLocal
     provider = provider
     # noinspection PyUnusedLocal
     version = version
     repo = get_object_or_404(Repository.reader_queryset(request), id=rid, archive_type=self.archive_type)
     elements = list(Element.objects.filter(repository=repo, pk=eid)[0:1])
     if not elements:
         return JsonResponse({'errors': ['Not found', ], })
     return get_file(request, eid, element=elements[0])
Exemplo n.º 7
0
 def download(self,
              request,
              rid,
              repo_slug,
              state_slug=None,
              filename=None):
     # noinspection PyUnusedLocal
     repo_slug = repo_slug
     repo = get_object_or_404(Repository.reader_queryset(request),
                              id=rid,
                              archive_type=self.archive_type)
     base_query = Element.objects.filter(repository=repo)
     if state_slug:
         state = get_object_or_404(ArchiveState,
                                   repository=repo,
                                   name=state_slug)
         base_query = base_query.filter(states=state)
     element = get_object_or_404(base_query, filename=filename)
     from moneta.views import get_file
     return get_file(request, element.pk)
Exemplo n.º 8
0
 def get_file(self, request, rid, repo_slug, state_slug, folder, filename):
     """
     Return a HttpResponse
     :param request: HttpRequest
     :raise:
     """
     repo = get_object_or_404(Repository.reader_queryset(request),
                              id=rid,
                              archive_type=self.archive_type)
     q = Element.objects.filter(repository__id=rid, filename=filename)[0:1]
     q = list(q)
     if len(q) == 0:
         raise Http404
     element = q[0]
     return get_file(request,
                     element.id,
                     compression=None,
                     path='',
                     element=element,
                     name=None)
Exemplo n.º 9
0
    def get_filename(request, eid):
        from moneta.views import get_file

        return get_file(request, eid)
Exemplo n.º 10
0
    def get_filename(request, eid):
        from moneta.views import get_file

        return get_file(request, eid)