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


Python Report.generate_file_name方法代码示例

本文整理汇总了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}
开发者ID:deti,项目名称:boss,代码行数:31,代码来源:report.py

示例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()
开发者ID:deti,项目名称:boss,代码行数:78,代码来源:customer.py


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