当前位置: 首页>>代码示例>>Python>>正文


Python Report.username方法代码示例

本文整理汇总了Python中models.Report.username方法的典型用法代码示例。如果您正苦于以下问题:Python Report.username方法的具体用法?Python Report.username怎么用?Python Report.username使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Report的用法示例。


在下文中一共展示了Report.username方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: default

# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import username [as 别名]
def default(request):

        applicationFolder = getApplicationFolder()

        #if the request is POST -> file is being uploaded
        if str(request.method).lower() == 'post':
                form = UploadFileForm(request.POST, request.FILES)
                #if there is file for uploading
                if form.is_valid():

                        #uplaod the file on the server
                        tarPath = handle_uploaded_file(request.FILES['file'])

                        reportMetaData = {}

                        #here check it could be zip or tar.gz
                        isTar = (tarPath.endswith('tar.gz') or tarPath.endswith('tgz'))
                        isZip = tarPath.endswith('.zip')

                        #get metadata depending on the archive
                        if isTar:
                                reportMetaData = getReportMetadataTar(tarPath)
                        elif isZip:
                                reportMetaData = getReportMetadataZip(tarPath)
                        
                        #create new Report object set its metadata and save it
                        report = Report()
                        report.username = reportMetaData['user']
                        report.ganga_version = reportMetaData['version']
                        report.job_uuid = reportMetaData['uuid']
                        report.date_uploaded = datetime.now()
                        report.save()

                        #save the report's mon links
                        monlinks = reportMetaData['monlinks']
                        
                        for key, value in monlinks.items():

                                monlink = MonitoringLink()
                                monlink.report = report
                                monlink.monitoring_link_name = key
                                monlink.monitoring_link_path = value            
                                monlink.save()
                        
                        #rename the uploaded file on the server with the report id 
                        if isTar:
                                rename_file(tarPath, report.id, 'tar')

                        elif isZip:
                                rename_file(tarPath, report.id, 'zip')

                        #sets the download path that will be shown to the user
                        serverDownloadPath = os.path.join(settings.SERVER_DOWNLOAD_PATH, str(report.id))

                        community, debug = getCommunityAndDebugMode()[0], getCommunityAndDebugMode()[1]
                        if community == 'CMS' and debug == False :
                                #because for CMS there is different DNS
                                serverDownloadPath = os.path.join(settings_HOST+"cmserrorreports/download", str(report.id))
                        elif community == 'CMS':
                                serverDownloadPath = serverDownloadPath.replace('errorreports', 'cmserrorreports')

                        renderToResponse = render_to_response('%s/upload.html' % applicationFolder, {'form': form, 'path': serverDownloadPath }, context_instance = RequestContext(request))    

                        logServerResponse(str(renderToResponse))

                        return renderToResponse
                        
                else:
                    errors=""
                    for key, value in form.errors.iteritems():
                        errors += str(key) + ": "
                        for i in value:
                            errors += str(i) + ", "
                        errors += "     "
                    return render_to_response('%s/upload.html' % applicationFolder, {'form': form, 'path' : 'invalid form: %s' % errors }, context_instance = RequestContext(request))

        else:
            #user = User.objects.create_user('gosho', '[email protected]', 'gosho')
            #user.save()

            form = UploadFileForm()

            return render_to_response('%s/upload.html' % applicationFolder, { 'form' : form, 'path' : 'Method: %s' % request.method }, context_instance = RequestContext(request))
开发者ID:ganga-devs,项目名称:gangamon,代码行数:85,代码来源:views.py


注:本文中的models.Report.username方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。