def handle_register_or_upload(post_data, files, user, repository):
    """Process a `register` or `upload` comment issued via distutils.

    This method is called with the authenticated user.

    """
    name = post_data.get('name')
    version = post_data.get('version')

    if settings.LOCALSHOP_VERSIONING_TYPE:
        scheme = get_versio_versioning_scheme(settings.LOCALSHOP_VERSIONING_TYPE)
        try:
            Version(version, scheme=scheme)
        except AttributeError:
            response = HttpResponseBadRequest(
                reason="Invalid version supplied '{!s}' for '{!s}' scheme.".format(
                    version, settings.LOCALSHOP_VERSIONING_TYPE))
            return response

    if not name or not version:
        logger.info("Missing name or version for package")
        return HttpResponseBadRequest('No name or version given')

    try:
        condition = Q()
        for search_name in get_search_names(name):
            condition |= Q(name__iexact=search_name)

        package = repository.packages.get(condition)

        # Error out when we try to override a mirror'ed package for now
        # not sure what the best thing is
        if not package.is_local:
            return HttpResponseBadRequest(
                '%s is a pypi package!' % package.name)

        try:
            release = package.releases.get(version=version)
        except ObjectDoesNotExist:
            release = None
    except ObjectDoesNotExist:
        package = None
        release = None

    # Validate the data
    form = forms.ReleaseForm(post_data, instance=release)
    if not form.is_valid():
        return HttpResponseBadRequest(reason=form.errors.values()[0][0])

    if not package:
        pkg_form = forms.PackageForm(post_data, repository=repository)
        if not pkg_form.is_valid():
            return HttpResponseBadRequest(
                reason=six.next(six.itervalues(pkg_form.errors))[0])
        package = pkg_form.save()

    release = form.save(commit=False)
    release.package = package
    release.save()

    # If this is an upload action then process the uploaded file
    if files:
        files = {
            'distribution': files['content']
        }
        filename = files['distribution']._name
        try:
            release_file = release.files.get(filename=filename)
            if settings.LOCALSHOP_RELEASE_OVERWRITE is False:
                message = 'That it already released, please bump version.'
                return HttpResponseBadRequest(message)
        except ObjectDoesNotExist:
            release_file = models.ReleaseFile(
                release=release, filename=filename)

        form_file = forms.ReleaseFileForm(
            post_data, files, instance=release_file)
        if not form_file.is_valid():
            return HttpResponseBadRequest('ERRORS %s' % form_file.errors)
        release_file = form_file.save(commit=False)
        release_file.save()

    return HttpResponse()
def handle_register_or_upload ( post_data , files , user , repository ) : name = post_data . get ( 'name' ) version = post_data . get ( 'version' ) if settings . LOCALSHOP_VERSIONING_TYPE : scheme = get_versio_versioning_scheme ( settings . LOCALSHOP_VERSIONING_TYPE ) try : Version ( version , scheme = scheme ) except AttributeError : response = HttpResponseBadRequest ( reason = "Invalid version supplied '{!s}' for '{!s}' scheme." . format ( version , settings . LOCALSHOP_VERSIONING_TYPE ) ) return response if not name or not version : logger . info ( "Missing name or version for package" ) return HttpResponseBadRequest ( 'No name or version given' ) try : condition = Q ( ) for search_name in get_search_names ( name ) : condition |= Q ( name__iexact = search_name ) package = repository . packages . get ( condition ) if not package . is_local : return HttpResponseBadRequest ( '%s is a pypi package!' % package . name ) try : release = package . releases . get ( version = version ) except ObjectDoesNotExist : release = None except ObjectDoesNotExist : package = None release = None form = forms . ReleaseForm ( post_data , instance = release ) if not form . is_valid ( ) : return HttpResponseBadRequest ( reason = form . errors . values ( ) [ 0 ] [ 0 ] ) if not package : pkg_form = forms . PackageForm ( post_data , repository = repository ) if not pkg_form . is_valid ( ) : return HttpResponseBadRequest ( reason = six . next ( six . itervalues ( pkg_form . errors ) ) [ 0 ] ) package = pkg_form . save ( ) release = form . save ( commit = False ) release . package = package release . save ( ) if files : files = { 'distribution' : files [ 'content' ] } filename = files [ 'distribution' ] . _name try : release_file = release . files . get ( filename = filename ) if settings . LOCALSHOP_RELEASE_OVERWRITE is False : message = 'That it already released, please bump version.' return HttpResponseBadRequest ( message ) except ObjectDoesNotExist : release_file = models . ReleaseFile ( release = release , filename = filename ) form_file = forms . ReleaseFileForm ( post_data , files , instance = release_file ) if not form_file . is_valid ( ) : return HttpResponseBadRequest ( 'ERRORS %s' % form_file . errors ) release_file = form_file . save ( commit = False ) release_file . save ( ) return HttpResponse ( )
Process a `register` or `upload` comment issued via distutils.

    This method is called with the authenticated user.