本文整理汇总了Python中report.Report.generate_file_name方法的典型用法代码示例。如果您正苦于以下问题:Python Report.generate_file_name方法的具体用法?Python Report.generate_file_name怎么用?Python Report.generate_file_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类report.Report
的用法示例。
在下文中一共展示了Report.generate_file_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report
# 需要导入模块: from report import Report [as 别名]
# 或者: from report.Report import generate_file_name [as 别名]
def report(self, start, finish, report_type, report_format, locale=None):
if start >= finish:
raise errors.StartShouldBeEarlierFinish()
if not Report.is_supported(report_type, report_format):
raise errors.ReportFormatIsNotSupported()
report_cache = ReportCache()
report_task = ReportTask()
report_id = ReportId(start, finish, report_type, report_format, locale)
data = report_cache.get_report(report_id)
if data:
if report_format == "json":
return {"status": "completed",
"report": json.loads(data.decode("utf-8"))}
filename = Report.generate_file_name(report_type, start, finish, report_format)
content_disposition = make_content_disposition(filename, bottle.request.environ.get('HTTP_USER_AGENT'))
return bottle.HTTPResponse(body=data, content_type=Report.content_types[report_format],
content_disposition=content_disposition)
status = report_task.task_status(report_id)
if not status:
result = report_file_generate.delay(report_id)
logbook.info("Created report_file task {} for {}", result.id, report_id)
report_task.set(report_id, result.id)
status = "started"
return {"status": status}
示例2: customer_auto_report
# 需要导入模块: from report import Report [as 别名]
# 或者: from report.Report import generate_file_name [as 别名]
def customer_auto_report(customer_id, time_now):
from model import Customer, ScheduledTask
from task.mail import send_email
customer = Customer.get_by_id(customer_id)
if not customer:
logbook.error("Can't find customer {} for report generation", customer_id)
return
report_task = ScheduledTask.get_by_customer(customer_id, Customer.AUTO_REPORT_TASK)
if not report_task:
logbook.error("Can't find auto report task for customer {}", customer_id)
return
logbook.debug("Start auto-report task for customer {}: {}", customer, report_task)
report_task.start()
previous_next_send = report_task.next_scheduled.replace(tzinfo=utc)
if previous_next_send is None or previous_next_send > time_now:
logbook.warning("Looks like report for customer {} already sent. Next send: {}, current time {}",
customer, previous_next_send, time_now)
report_task.completed(now=time_now)
return
report_begin = day_start(report_task.last or time_now)
_, report_end = report_task.task_range(time_now, previous_interval=True)
report_end = day_start(report_end)
report_id = CustomerReportId(customer.customer_id, report_begin, report_end,
conf.customer.report.type, conf.customer.report.format, customer.locale)
report_file_generate(report_id)
# report_file_generate closed session so we should initialize customer again
customer = Customer.get_by_id(customer_id)
report_task = ScheduledTask.get_by_customer(customer_id, Customer.AUTO_REPORT_TASK)
report_cache = ReportCache()
report = report_cache.get_report_aggregated(report_id)
if not report or not report["tariffs"]:
logbook.info("Report is empty for customer {}", customer)
report_task.completed(now=time_now)
return
report_file = report_cache.get_report(report_id)
if not report_file:
logbook.error("Report generation failed")
report_task.completed(False)
return
filename = Report.generate_file_name(customer.get_name(), report_begin, report_end, conf.customer.report.format)
subject, body = MessageTemplate.get_rendered_message(
MessageTemplate.CUSTOMER_AUTO_REPORT, customer.locale_language(),
customer_name=customer.get_name(), currency=customer.tariff.currency,
report_start=report_begin, report_end=report_end)
subscription_info = customer.subscription_info()['billing']
if subscription_info["enable"]:
send_email.delay(subscription_info["email"], subject, body, attachments=[(filename, report_file)])
report_task.completed(now=time_now)
comment_fmt = "%s - %s" % (report_begin.strftime('%Y-%m-%d'), report_end.strftime('%Y-%m-%d'))
for currency, amount in report["total"].items():
amount = Decimal(amount)
customer.modify_balance(-amount, currency, None, comment_fmt)
account = customer.get_account(currency)
account.charge(-amount)
db.session.commit()