Ejemplo n.º 1
0
def upload_handler(request):
    view_url = reverse('upload.views.upload_handler')
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
        return HttpResponseRedirect(view_url)

    upload_url, upload_data = prepare_upload(request, view_url)
    form = UploadForm()
    return direct_to_template(request, 'upload/upload.html',
        {'form': form, 'upload_url': upload_url, 'upload_data': upload_data,
         'uploads': UploadModel.objects.all()})
Ejemplo n.º 2
0
def upload_handler(request):
    view_url = reverse('upload.views.upload_handler')
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        try:
            if form.is_valid():
                form.save()
            else:
                view_url += '?error=Not a valid image'
            return HttpResponseRedirect(view_url)
        except Exception,e:
            import logging
            logger = logging.getLogger(__name__)
            logger.error('caught %s in image upload',e)
            raise e
Ejemplo n.º 3
0
def upload_new(request):
    if request.method == "POST":
        form = UploadForm(request.POST, request.FILES)
        filename = request.FILES['projectFile'].name
        print(filename)

        if form.is_valid():
            post = form.save(commit=False)
            #post.email = request.user
            post.save()

            f = open(settings.MEDIA_ROOT + '/files/' + filename,
                     'r',
                     encoding='utf8')
            result = SnRdata(f)
            print("=============json=============")
            '''
            for i in range(len(result)):
                print("DATA_"+str(i))
                print(result)
                '''
            print(result)
            print("=============json=============")
            f.close()
        '''
            #if(request.contentType == 'text/html'
            #return redirect('upload_base', pk=post.pk)
            #return "{success: 'ok'}"
        '''
    else:
        form = UploadForm()
    return render(request, 'upload_new.html', {'form': form})
Ejemplo n.º 4
0
def index(request):
    if request.method == 'POST':
        print("-- post --")
        form = UploadForm(request.POST or None)
        if form.is_valid():
            print("valid")
            image_file = ImageFileModel()
            image_file.image = request.FILES['image']
            image_file.published_date = timezone.now()

            image_file.save()
            form.save()
            render(request, 'upload/index.html', {'form': form})
        else:
            print("not")
            form = UploadForm()
            render(request, 'upload/index.html', {'form': form})
    else:
        form = UploadForm()
    return render(request, 'upload/index.html', {'form': form})
Ejemplo n.º 5
0
def upload(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            upload = form.save(commit=False)
            upload.ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
            upload.save()
            messages.success(request, "Upload was successful!")
            return HttpResponseRedirect(reverse('upload-detail', args=[upload.id]))
    else:
        form = UploadForm()

    return render_to_response('upload/index.html', {
        'form': form,  
        'latest': Upload.objects.order_by('-created')[:20],
    }, context_instance=RequestContext(request))
Ejemplo n.º 6
0
    def test_0_form_workflow_add_manually(self):
        # test just the form
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file_dict = {
            NAME_JSON: SimpleUploadedFile(upload_file.name, upload_file.read())
        }

        # get category IDs for the select Category field
        categories = Category.objects.all()
        category0 = categories[0]
        category1 = categories[1]
        #category0 = Category.objects.get(name=self.data[CATEGORY][0])
        #category1 = Category.objects.get(name=self.data[CATEGORY][1])
        # new workflow name
        workFlowName = 'workflow999'
        data_dict = {
            NAME_NAME: workFlowName,
            NAME_CATEGORY: [category0.id, category1.id],
            NAME_KEYWORDS: self.populate.getParragraph(1, 14),
            NAME_DESCRIPTION: self.populate.getParragraph(23, 123),
            NAME_VERSION: '3.1415',
        }

        # form with fieldfields has two independent dictionaries
        form = WorkFlowFormBase(data=data_dict, files=file_dict)
        self.assertTrue(form.is_valid(), form.errors)
        if form.is_valid():
            file_data = form.cleaned_data["json"].read().decode("utf-8")
            # modify object json value
            form.instance.json = file_data
        newWorkflow = form.save()
        self.assertEqual(newWorkflow.name, workFlowName)