Пример #1
0
    def form_valid(self, form):
        if self.stage != 'init':
            return super(CreateFromZip, self).form_valid(form)

        # Create fake component (needed to calculate path)
        fake = Component(
            project=form.cleaned_data['project'],
            slug=form.cleaned_data['slug'],
            name=form.cleaned_data['name'],
        )

        # Create repository
        try:
            LocalRepository.from_zip(fake.full_path,
                                     form.cleaned_data['zipfile'])
        except BadZipfile:
            form.add_error('zipfile', _('Failed to parse uploaded ZIP file.'))
            return self.form_invalid(form)

        # Move to discover phase
        self.stage = 'discover'
        self.initial = form.cleaned_data
        self.initial['vcs'] = 'local'
        self.initial['repo'] = 'local:'
        self.initial.pop('zipfile')
        self.request.method = 'GET'
        return self.get(self, self.request)
Пример #2
0
    def form_valid(self, form):
        if self.stage != "init":
            return super().form_valid(form)

        # Create fake component (needed to calculate path)
        fake = Component(
            project=form.cleaned_data["project"],
            slug=form.cleaned_data["slug"],
            name=form.cleaned_data["name"],
        )

        # Create repository
        try:
            LocalRepository.from_zip(fake.full_path, form.cleaned_data["zipfile"])
        except BadZipfile:
            form.add_error("zipfile", _("Failed to parse uploaded ZIP file."))
            return self.form_invalid(form)

        # Move to discover phase
        self.stage = "discover"
        self.initial = form.cleaned_data
        self.initial["vcs"] = "local"
        self.initial["repo"] = "local:"
        self.initial.pop("zipfile")
        self.request.method = "GET"
        return self.get(self, self.request)
Пример #3
0
def create_component_from_zip(data):
    # Create fake component (needed to calculate path)
    fake = Component(
        project=data["project"],
        slug=data["slug"],
        name=data["name"],
    )

    # Create repository
    LocalRepository.from_zip(fake.full_path, data["zipfile"])
    return fake