Example #1
0
def echoUploadFilename(request):
    """ This funtion is to preview the attachment parsed for user, and user can modify some fields before last submission.
    In here, get the parameters from "uploadFilename" via global variable, I think it is NOT the best choice.
    """
    if request.method == 'POST':
        postDict = request.POST
        Color_Print('magenta', '[%s]' % request.POST)
        # uneditable fields
        testUser = postDict.get('testUser')
        testComment = postDict.get('testComment')
        testRecordTime = datetime.datetime.strptime(
            postDict.get('testRecordTime'), '%Y-%m-%d %H:%M:%S')
        fileName = postDict.get('fileName')
        testResultDetailLink = postDict.get('testResultDetailLink')

        # editable fields
        testTime = datetime.datetime.strptime(postDict.get('testTime'),
                                              '%Y-%m-%d %H:%M:%S')
        testType = postDict.get('testType')
        testConfiguration = postDict.get('testConfiguration')
        testSoftware = postDict.get('testSoftware')

        # These test Items is dynamically added as below

        # update the data into UF()
        curTime = time.strftime('%Y-%m-%d/%H-%M-%S')
        ufObject = UF()
        ufObject.testUser = testUser
        ufObject.testComment = testComment
        ufObject.testRecordTime = testRecordTime
        ufObject.filename = curTime + '/' + fileName
        ufObject.testResultDetailLink = testResultDetailLink
        ufObject.save()

        # upload the data into SR()
        srObject = SR()
        srObject.testUser, srObject.testComment, srObject.testRecordTime, srObject.testResultDetailLink = testUser, testComment, testRecordTime, testResultDetailLink
        srObject.save()
        foreignKeyID = srObject.id

        # upload the data into SI()
        siObject = SI()
        siObject.testResult_id, siObject.testTime, siObject.testType, siObject.testConfiguration, siObject.testSoftware = foreignKeyID, testTime, testType, testConfiguration, testSoftware
        # TODO: this is the test Items, it can NOT code before ensuring the table fields
        for singleTestItem in getAllFieldsMap(SI, getAll=False):
            try:
                siObject.__setattr__(singleTestItem,
                                     float(postDict.get(singleTestItem)))
            except:
                siObject.__setattr__(singleTestItem, -9.99)
        siObject.save()
        return HttpResponseRedirect(
            reverse('demo_application.views.postUploadFilename'))
Example #2
0
def echoUploadFilename(request):
    """ This funtion is to preview the attachment parsed for user, and user can modify some fields before last submission.
    In here, get the parameters from "uploadFilename" via global variable, I think it is NOT the best choice.
    """
    if request.method == 'POST':
        postDict = request.POST
        Color_Print('magenta', '[%s]' % request.POST)
        # uneditable fields
        testUser = postDict.get('testUser')
        testComment = postDict.get('testComment')
        testRecordTime = datetime.datetime.strptime(postDict.get('testRecordTime'), '%Y-%m-%d %H:%M:%S')
        fileName = postDict.get('fileName')
        testResultDetailLink = postDict.get('testResultDetailLink')

        # editable fields
        testTime = datetime.datetime.strptime(postDict.get('testTime'), '%Y-%m-%d %H:%M:%S')
        testType = postDict.get('testType')
        testConfiguration = postDict.get('testConfiguration')
        testSoftware = postDict.get('testSoftware')

        # These test Items is dynamically added as below

        # update the data into UF()
        curTime = time.strftime('%Y-%m-%d/%H-%M-%S')
        ufObject = UF()
        ufObject.testUser = testUser
        ufObject.testComment = testComment
        ufObject.testRecordTime = testRecordTime
        ufObject.filename = curTime + '/'+ fileName
        ufObject.testResultDetailLink = testResultDetailLink
        ufObject.save()

        # upload the data into SR()
        srObject = SR()
        srObject.testUser, srObject.testComment, srObject.testRecordTime, srObject.testResultDetailLink = testUser, testComment, testRecordTime, testResultDetailLink
        srObject.save()
        foreignKeyID = srObject.id

        # upload the data into SI()
        siObject = SI()
        siObject.testResult_id, siObject.testTime, siObject.testType, siObject.testConfiguration, siObject.testSoftware = foreignKeyID, testTime, testType, testConfiguration, testSoftware 
        # TODO: this is the test Items, it can NOT code before ensuring the table fields
        for singleTestItem in getAllFieldsMap(SI, getAll = False):
            try:
                siObject.__setattr__(singleTestItem, float(postDict.get(singleTestItem)))
            except:
                siObject.__setattr__(singleTestItem, -9.99)
        siObject.save()
        return HttpResponseRedirect(reverse('demo_application.views.postUploadFilename'))
Example #3
0
def uploadFilename(request):
    """ Two mode for user's submission: "Preview Before Submit" and "Sumbit Directly"
    "Preview Before Sumbit": parse the attachment and return a review, user can modify some fields before last submission;
    "Sumbit Directly": parse the attachment and insert all useful into databases.
    """

    if request.method == "POST":
        uploadFileFormObject = uploadFileForm(request.POST, request.FILES)
        #XXX: "Option" is defined in "upload_index.html" 
        uploadOption = request.POST['Option']
        if uploadFileFormObject.is_valid():
            testUser = uploadFileFormObject.cleaned_data['testUser']
            testComment = uploadFileFormObject.cleaned_data['testComment']
            testRecordTime = uploadFileFormObject.cleaned_data['testRecordTime']
            fileName = uploadFileFormObject.cleaned_data['filename']
            testResultDetailLink = uploadFileFormObject.cleaned_data['testResultDetailLink']

            #XXX: DO NOT use absolute path to open the file because the file will not save into filesystem before UF.save() 
            attachmentDictNotItem, attachmentDictItem = extractInformationFromAttachment(fileName) 

            if 'Preview' in uploadOption:
                Color_Print('green', 'Preview Buttom')
                #global echoParseParameter
                echoParseParameter = {}
                editableParameter = {}
                uneditableParameter = {}
                editableParameterNotItem = deepcopy(attachmentDictNotItem)
                editableParameterItem = deepcopy(attachmentDictItem)

                formatTime = editableParameterNotItem['testTime'][1].strftime('%Y-%m-%d %H:%M:%S')
                editableParameterNotItem['testTime'] = ['When Did The Test', formatTime]

                uneditableParameter['testUser'] = testUser
                uneditableParameter['testComment'] = testComment
                uneditableParameter['testRecordTime'] = testRecordTime.strftime('%Y-%m-%d %H:%M:%S')
                uneditableParameter['fileName'] = os.path.basename(fileName.name)
                uneditableParameter['testResultDetailLink'] = testResultDetailLink

                echoParseParameter['STATIC_URL'] = STATIC_URL
                echoParseParameter['uneditableParameter'] = uneditableParameter
                echoParseParameter['editableParameterNotItem'] = editableParameterNotItem
                echoParseParameter['editableParameterItem'] = editableParameterItem
                return render_to_response('demo_application/upload/upload_echo.html', echoParseParameter)
            else: # Sumbit Directly ===> it is OK if ensure the table fields name
                Color_Print('green', 'Sumbit Directly')
                # update the data into UF()    
                ufObject = UF()
                ufObject.testUser = testUser
                ufObject.testComment = testComment
                ufObject.testRecordTime = testRecordTime
                ufObject.filename = fileName
                ufObject.testResultDetailLink = testResultDetailLink
                ufObject.save()

                # upload the data into SR()
                srObject = SR()
                srObject.testUser, srObject.testComment, srObject.testRecordTime, srObject.testResultDetailLink = testUser, testComment, testRecordTime, testResultDetailLink
                srObject.save()
                foreignKeyID = srObject.id

                # upload the data into SI()
                siObject = SI()
                siObject.testResult_id, siObject.testTime, siObject.testType, siObject.testConfiguration, siObject.testSoftware = foreignKeyID, attachmentDictNotItem['testTime'][1], attachmentDictNotItem['testType'][1], attachmentDictNotItem['testConfiguration'][1], attachmentDictNotItem['testSoftware'][1]
                # TODO: this is the test Items, it can NOT code before ensuring the table fields

                for singleTestItem in getAllFieldsMap(SI, getAll=False):
                    siObject.__setattr__(singleTestItem, attachmentDictItem[singleTestItem][1])
                siObject.save()
                return HttpResponseRedirect(reverse('demo_application.views.postUploadFilename'))
    else:
        uploadFileFormObject = uploadFileForm()
    return render_to_response('demo_application/upload/upload_index.html', {'uploadFileFormObject': uploadFileFormObject, 'STATIC_URL':STATIC_URL})
Example #4
0
def uploadFilename(request):
    """ Two mode for user's submission: "Preview Before Submit" and "Sumbit Directly"
    "Preview Before Sumbit": parse the attachment and return a review, user can modify some fields before last submission;
    "Sumbit Directly": parse the attachment and insert all useful into databases.
    """

    if request.method == "POST":
        uploadFileFormObject = uploadFileForm(request.POST, request.FILES)
        #XXX: "Option" is defined in "upload_index.html"
        uploadOption = request.POST['Option']
        if uploadFileFormObject.is_valid():
            testUser = uploadFileFormObject.cleaned_data['testUser']
            testComment = uploadFileFormObject.cleaned_data['testComment']
            testRecordTime = uploadFileFormObject.cleaned_data[
                'testRecordTime']
            fileName = uploadFileFormObject.cleaned_data['filename']
            testResultDetailLink = uploadFileFormObject.cleaned_data[
                'testResultDetailLink']

            #XXX: DO NOT use absolute path to open the file because the file will not save into filesystem before UF.save()
            attachmentDictNotItem, attachmentDictItem = extractInformationFromAttachment(
                fileName)

            if 'Preview' in uploadOption:
                Color_Print('green', 'Preview Buttom')
                #global echoParseParameter
                echoParseParameter = {}
                editableParameter = {}
                uneditableParameter = {}
                editableParameterNotItem = deepcopy(attachmentDictNotItem)
                editableParameterItem = deepcopy(attachmentDictItem)

                formatTime = editableParameterNotItem['testTime'][1].strftime(
                    '%Y-%m-%d %H:%M:%S')
                editableParameterNotItem['testTime'] = [
                    'When Did The Test', formatTime
                ]

                uneditableParameter['testUser'] = testUser
                uneditableParameter['testComment'] = testComment
                uneditableParameter[
                    'testRecordTime'] = testRecordTime.strftime(
                        '%Y-%m-%d %H:%M:%S')
                uneditableParameter['fileName'] = os.path.basename(
                    fileName.name)
                uneditableParameter[
                    'testResultDetailLink'] = testResultDetailLink

                echoParseParameter['STATIC_URL'] = STATIC_URL
                echoParseParameter['uneditableParameter'] = uneditableParameter
                echoParseParameter[
                    'editableParameterNotItem'] = editableParameterNotItem
                echoParseParameter[
                    'editableParameterItem'] = editableParameterItem
                return render_to_response(
                    'demo_application/upload/upload_echo.html',
                    echoParseParameter)
            else:  # Sumbit Directly ===> it is OK if ensure the table fields name
                Color_Print('green', 'Sumbit Directly')
                # update the data into UF()
                ufObject = UF()
                ufObject.testUser = testUser
                ufObject.testComment = testComment
                ufObject.testRecordTime = testRecordTime
                ufObject.filename = fileName
                ufObject.testResultDetailLink = testResultDetailLink
                ufObject.save()

                # upload the data into SR()
                srObject = SR()
                srObject.testUser, srObject.testComment, srObject.testRecordTime, srObject.testResultDetailLink = testUser, testComment, testRecordTime, testResultDetailLink
                srObject.save()
                foreignKeyID = srObject.id

                # upload the data into SI()
                siObject = SI()
                siObject.testResult_id, siObject.testTime, siObject.testType, siObject.testConfiguration, siObject.testSoftware = foreignKeyID, attachmentDictNotItem[
                    'testTime'][1], attachmentDictNotItem['testType'][
                        1], attachmentDictNotItem['testConfiguration'][
                            1], attachmentDictNotItem['testSoftware'][1]
                # TODO: this is the test Items, it can NOT code before ensuring the table fields

                for singleTestItem in getAllFieldsMap(SI, getAll=False):
                    siObject.__setattr__(singleTestItem,
                                         attachmentDictItem[singleTestItem][1])
                siObject.save()
                return HttpResponseRedirect(
                    reverse('demo_application.views.postUploadFilename'))
    else:
        uploadFileFormObject = uploadFileForm()
    return render_to_response('demo_application/upload/upload_index.html', {
        'uploadFileFormObject': uploadFileFormObject,
        'STATIC_URL': STATIC_URL
    })