示例#1
0
def list_packages(request, page_no = 1):
  package_list = Package.objects.order_by('id').reverse()
  has_package = (len(package_list) > 0)
  return render_to_response('package_list.html', {
      'package_list': package_list,
      'has_package': has_package,
      'STATIC_URL': STATIC_URL.rstrip('/'),
  })
示例#2
0
def upload_package(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            artifact = request.POST.get('artifact')
            revision_no = request.POST.get('revision')
            file_obj = request.FILES.get('file')

            error_message = str()
            if not artifact:
                error_message = 'Artifact should not be empty'
            elif not revision_no:
                error_message = 'Revison should not be empty'

            if error_message:
                return render_to_response(
                    'upload.html', {
                        'error_message': error_message,
                        'STATIC_URL': STATIC_URL.rstrip('/'),
                    })
            else:
                package_name = os.path.basename(file_obj.name)
                checksum = generate_checksum(file_obj)
                time = generate_timestamp()
                file_obj.seek(0)
                package = Package(artifact=artifact,
                                  name=package_name,
                                  revision=revision_no,
                                  timestamp=time,
                                  checksum=checksum,
                                  file=file_obj)
                package.save()
                return render_to_response(
                    'upload.html', {
                        'upload_success': True,
                        'package': package,
                        'STATIC_URL': STATIC_URL.rstrip('/'),
                    })
    else:
        form = UploadFileForm()

    return render_to_response('upload.html', {
        'form': form,
        'STATIC_URL': STATIC_URL.rstrip('/'),
    })
示例#3
0
def upload_package(request):
  if request.method == 'POST':
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
      artifact = request.POST.get('artifact')
      revision_no = request.POST.get('revision')
      file_obj = request.FILES.get('file')

      error_message = str()
      if not artifact:
        error_message = 'Artifact should not be empty'
      elif not revision_no:
        error_message = 'Revison should not be empty'

      if error_message:
        return render_to_response('upload.html', {
          'error_message': error_message,
          'STATIC_URL': STATIC_URL.rstrip('/'),
        })
      else:
        package_name = os.path.basename(file_obj.name)
        checksum = generate_checksum(file_obj)
        time = generate_timestamp()
        file_obj.seek(0)
        package = Package(artifact=artifact, name=package_name,
            revision=revision_no, timestamp=time,
            checksum=checksum, file=file_obj)
        package.save()
        return render_to_response('upload.html', {
          'upload_success': True,
          'package': package,
          'STATIC_URL': STATIC_URL.rstrip('/'),
        })
  else:
    form = UploadFileForm()

  return render_to_response('upload.html', {
      'form': form,
      'STATIC_URL': STATIC_URL.rstrip('/'),
  })