本文整理汇总了Python中models.Report.date_uploaded方法的典型用法代码示例。如果您正苦于以下问题:Python Report.date_uploaded方法的具体用法?Python Report.date_uploaded怎么用?Python Report.date_uploaded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Report
的用法示例。
在下文中一共展示了Report.date_uploaded方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: default
# 需要导入模块: from models import Report [as 别名]
# 或者: from models.Report import date_uploaded [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))