• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.datetime_or_now函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中saas.utils.datetime_or_now函数的典型用法代码示例。如果您正苦于以下问题:Python datetime_or_now函数的具体用法?Python datetime_or_now怎么用?Python datetime_or_now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: cache_fields

 def cache_fields(self, request):
     self.ends_at = datetime_or_now(parse_datetime(request.GET.get("ends_at", "").strip('"')))
     self.start_at = request.GET.get("start_at", None)
     if self.start_at:
         self.start_at = datetime_or_now(parse_datetime(self.start_at.strip('"')))
     else:
         self.start_at = self.ends_at + dateutil.relativedelta.relativedelta(months=-1)
开发者ID:shadowbw,项目名称:djaodjin-saas,代码行数:7,代码来源:mixins.py


示例2: get

    def get(self, request, subscriber_type, **kwargs):
        queryset_view = self.queryset_view_map[subscriber_type]

        class APIViewProxy(queryset_view):
            def __init__(self, provider):
                self.provider = provider
        view_proxy = APIViewProxy(self.get_organization())
        view_proxy.get_range_queryset = MethodType(
            queryset_view.get_range_queryset, view_proxy)

        start_date = datetime_or_now(
            parse_datetime(request.GET.get('start_date', None)))
        end_date = datetime_or_now(
            parse_datetime(request.GET.get('end_date', None)))

        content = StringIO()
        csv_writer = csv.writer(content)
        csv_writer.writerow(['Name', 'Email', 'Registration Date'])
        for org in view_proxy.get_range_queryset(start_date, end_date):
            csv_writer.writerow([
                org.full_name.encode('utf-8'),
                org.email.encode('utf-8'),
                org.created_at])
        content.seek(0)
        resp = HttpResponse(content, content_type='text/csv')
        resp['Content-Disposition'] = \
            'attachment; filename="subscribers-{}-{}.csv"'.format(
                subscriber_type, datetime.now().strftime('%Y%m%d'))
        return resp
开发者ID:marmida,项目名称:djaodjin-saas,代码行数:29,代码来源:metrics.py


示例3: get

    def get(self, request, *args, **kwargs):
        self.provider = self.get_organization()
        self.start_date = datetime_or_now(
            parse_datetime(request.GET.get('start_date', None).strip('"')))
        self.end_date = datetime_or_now(
            parse_datetime(request.GET.get('end_date', None).strip('"')))

        return super(AbstractSubscriberPipelineDownloadView, self).get(
            request, *args, **kwargs)
开发者ID:Qbitus,项目名称:djaodjin-saas,代码行数:9,代码来源:metrics.py


示例4: cache_fields

 def cache_fields(self, request): #pylint: disable=unused-argument
     self.organization = self.get_organization()
     self.start_at = self.request.GET.get('start_at', None)
     if self.start_at:
         self.start_at = parse_datetime(self.start_at)
     self.start_at = datetime_or_now(self.start_at)
     self.ends_at = self.request.GET.get('ends_at', None)
     if self.ends_at:
         self.ends_at = parse_datetime(self.ends_at)
     self.ends_at = datetime_or_now(self.ends_at)
开发者ID:letisiapangataa,项目名称:djaodjin-saas,代码行数:10,代码来源:mixins.py


示例5: get_queryset

 def get_queryset(self):
     '''
     Implement date range filtering
     '''
     qs = super(SmartTransactionListMixin, self).get_queryset()
     start = datetime_or_now(
         parse_datetime(self.request.GET.get('start_at', '').strip('"')))
     end = datetime_or_now(
         parse_datetime(self.request.GET.get('ends_at', '').strip('"')))
     return qs.filter(created_at__gte=start, created_at__lte=end)
开发者ID:StephaneRob,项目名称:djaodjin-saas,代码行数:10,代码来源:transactions.py


示例6: get_queryset

 def get_queryset(self):
     kwargs = {}
     start_at = self.request.GET.get('start_at', None)
     if start_at:
         start_at = datetime_or_now(parse_datetime(start_at))
         kwargs.update({'created_at__lt': start_at})
     ends_at = self.request.GET.get('ends_at', None)
     if ends_at:
         ends_at = parse_datetime(ends_at)
     ends_at = datetime_or_now(ends_at)
     return Subscription.objects.filter(
         plan__organization=self.get_organization(),
         ends_at__gte=ends_at, **kwargs).order_by('-ends_at')
开发者ID:letisiapangataa,项目名称:djaodjin-saas,代码行数:13,代码来源:mixins.py


示例7: get_queryset

 def get_queryset(self):
     kwargs = {}
     start_at = self.request.GET.get("start_at", None)
     if start_at:
         start_at = datetime_or_now(parse_datetime(start_at))
         kwargs.update({"created_at__lt": start_at})
     ends_at = self.request.GET.get("ends_at", None)
     if ends_at:
         ends_at = parse_datetime(ends_at)
     ends_at = datetime_or_now(ends_at)
     return Subscription.objects.filter(
         organization__slug=self.kwargs.get("organization"), ends_at__gte=ends_at, **kwargs
     )
开发者ID:shadowbw,项目名称:djaodjin-saas,代码行数:13,代码来源:mixins.py


示例8: get_queryset

 def get_queryset(self):
     kwargs = {}
     start_at = self.request.GET.get('start_at', None)
     if start_at:
         start_at = datetime_or_now(parse_datetime(start_at))
         kwargs.update({'created_at__lt': start_at})
     ends_at = self.request.GET.get('ends_at', None)
     if ends_at:
         ends_at = parse_datetime(ends_at)
     ends_at = datetime_or_now(ends_at)
     return User.objects.exclude(
         Q(manages__subscription__created_at__lt=ends_at) |
         Q(contributes__subscription__created_at__lt=ends_at)).order_by(
             '-date_joined', 'last_name').distinct()
开发者ID:StephaneRob,项目名称:djaodjin-saas,代码行数:14,代码来源:metrics.py


示例9: get_queryset

    def get_queryset(self):
        """
        GET displays the balance due by a subscriber.

        Template:

        To edit the layout of this page, create a local \
        ``saas/billing/balance.html`` (`example <https://github.com/djaodjin\
/djaodjin-saas/tree/master/saas/templates/saas/billing/balance.html>`__).

        Template context:
          - organization
          - request

        POST attempts to charge the card for the balance due.
        """
        self.customer = self.get_organization()
        invoicables = []
        created_at = datetime_or_now()
        for subscription in Subscription.objects.active_for(self.customer):
            options = self.get_invoicable_options(subscription, created_at)
            if len(options) > 0:
                invoicables += [{
                    'subscription': subscription,
                    'name': 'cart-%s' % subscription.plan.slug,
                    'lines': [],
                    'options': options}]
        return invoicables
开发者ID:letisiapangataa,项目名称:djaodjin-saas,代码行数:28,代码来源:billing.py


示例10: month_periods

def month_periods(nb_months=12, from_date=None):
    """constructs a list of (nb_months + 1) dates in the past that fall
    on the first of each month until *from_date* which is the last entry
    of the list returned."""
    dates = []
    if from_date and isinstance(from_date, basestring):
        from_date = parse_datetime(from_date)
    from_date = datetime_or_now(from_date)
    dates.append(from_date)
    last = datetime(
        day=from_date.day, month=from_date.month, year=from_date.year,
        tzinfo=utc)
    if last.day != 1:
        last = datetime(day=1, month=last.month, year=last.year, tzinfo=utc)
        dates.append(last)
        nb_months = nb_months - 1
    for _ in range(0, nb_months):
        year = last.year
        month = last.month - 1
        if month < 1:
            year = last.year - month / 12 - 1
            month = 12 - (month % 12)
        last = datetime(day=1, month=month, year=year, tzinfo=utc)
        dates.append(last)
    dates.reverse()
    return dates
开发者ID:altuzar,项目名称:djaodjin-saas,代码行数:26,代码来源:metrics.py


示例11: get_queryset

    def get_queryset(self):
        """
        GET displays the balance due by a subscriber.

        Template:

        To edit the layout of this page, create a local \
        ``saas/billing/balance.html`` (`example <https://github.com/djaodjin\
/djaodjin-saas/tree/master/saas/templates/saas/billing/balance.html>`__).

        Template context:
          - ``STRIPE_PUB_KEY`` Public key to send to stripe.com
          - ``invoicables`` List of items to be invoiced (with options)
          - ``organization`` The provider of the product
          - ``request`` The HTTP request object

        POST attempts to charge the card for the balance due.
        """
        self.customer = self.get_organization()
        invoicables = []
        created_at = datetime_or_now()
        for subscription in Subscription.objects.active_for(self.customer):
            options = self.get_invoicable_options(subscription, created_at)
            if len(options) > 0:
                invoicables += [{
                    'subscription': subscription,
                    'name': 'cart-%s' % subscription.plan.slug,
                    'lines': [],
                    'options': options}]
        return invoicables
开发者ID:irwinlove,项目名称:djaodjin-saas,代码行数:30,代码来源:billing.py


示例12: create_transfer

 def create_transfer(organization, amount, descr=None):
     """
     Transfer *amount* into the organization bank account.
     """
     LOGGER.debug("create_transfer(organization=%s, amount=%s, descr=%s)", organization, amount, descr)
     created_at = datetime_or_now()
     return (generate_random_slug(), created_at)
开发者ID:altuzar,项目名称:djaodjin-saas,代码行数:7,代码来源:fake_processor.py


示例13: create_charges_for_balance

def create_charges_for_balance(until=None):
    """
    Create charges for all accounts payable.
    """
    until = datetime_or_now(until)
    for organization in Organization.objects.all():
        charges = Charge.objects.filter(customer=organization).exclude(
            state=Charge.DONE).aggregate(Sum('amount'))
        inflight_charges = charges['amount__sum']
        # We will create charges only when we have no charges
        # already in flight for this customer.
        if not inflight_charges:
            balance_t = Transaction.objects.get_organization_payable(
                organization, until=until)
            if balance_t.dest_amount > 50:
                LOGGER.info('CHARGE %dc to %s',
                    balance_t.dest_amount, balance_t.dest_organization)
                # Stripe will not processed charges less than 50 cents.
                try:
                    balance_t.save()
                    Charge.objects.charge_card(
                        balance_t.dest_organization, balance_t)
                except:
                    raise
            else:
                LOGGER.info('SKIP   %s (less than 50c)',
                    balance_t.dest_organization)
        else:
            LOGGER.info('SKIP   %s (one charge already in flight)',
                balance_t.dest_organization)
开发者ID:Qbitus,项目名称:djaodjin-saas,代码行数:30,代码来源:charge.py


示例14: get

 def get(self, request, *args, **kwargs): #pylint: disable=unused-argument
     organization = self.get_organization()
     at_date = datetime_or_now(request.DATA.get('at', None))
     return Response([{
         'key': Transaction.INCOME,
         'values': monthly_balances(
                     organization, Transaction.INCOME, at_date)
         }])
开发者ID:wshcdr,项目名称:djaodjin-saas,代码行数:8,代码来源:metrics.py


示例15: create_charge_on_card

 def create_charge_on_card(card, amount, unit,
     descr=None, stmt_descr=None):
     #pylint: disable=too-many-arguments,unused-argument
     LOGGER.debug('create_charge_on_card(amount=%s, unit=%s, descr=%s)',
         amount, unit, descr)
     created_at = datetime_or_now()
     return (generate_random_slug(), created_at,
         '1234', created_at + datetime.timedelta(days=365))
开发者ID:StephaneRob,项目名称:djaodjin-saas,代码行数:8,代码来源:fake_processor.py


示例16: get

 def get(self, request, *args, **kwargs): #pylint: disable=unused-argument
     organization = self.get_organization()
     start_at = request.GET.get('start_at', None)
     if start_at:
         start_at = parse_datetime(start_at)
     start_at = datetime_or_now(start_at)
     ends_at = request.GET.get('ends_at', None)
     if ends_at:
         ends_at = parse_datetime(ends_at)
     ends_at = datetime_or_now(ends_at)
     result = []
     for key in [Transaction.INCOME, Transaction.BACKLOG,
                 Transaction.RECEIVABLE]:
         result += [{
             'key': key,
             'values': monthly_balances(organization, key, ends_at)
         }]
     return Response({'title': "Balances",
         'unit': "$", 'scale': 0.01, 'table': result})
开发者ID:StephaneRob,项目名称:djaodjin-saas,代码行数:19,代码来源:metrics.py


示例17: recognize_income

def recognize_income(until=None):
    """
    Create all ``Transaction`` necessary to recognize revenue
    on each ``Subscription`` until date specified.
    """
    until = datetime_or_now(until)
    for subscription in Subscription.objects.filter(created_at__lte=until, ends_at__gt=until):
        with transaction.atomic():
            # [``recognize_start``, ``recognize_end``[ is one period over which
            # revenue is recognized. It will slide over the subscription
            # lifetime from ``created_at`` to ``until``.
            to_recognize_amount = 0
            recognize_period = relativedelta(months=1)
            order_subscribe_beg = subscription.created_at
            recognize_start = subscription.created_at
            recognize_end = recognize_start + recognize_period
            for order in Transaction.objects.get_subscription_receivable(subscription):
                # [``order_subscribe_beg``, ``order_subscribe_end``[ is
                # the subset of the subscription lifetime the order paid for.
                # It covers ``total_periods`` plan periods.
                total_periods = order.get_event().plan.period_number(order.descr)
                order_subscribe_end = subscription.plan.end_of_period(order_subscribe_beg, nb_periods=total_periods)
                min_end = min(order_subscribe_end, until)
                while recognize_end <= min_end:
                    # we use ``<=`` here because we compare that bounds
                    # are equal instead of searching for points within
                    # the interval.
                    nb_periods = subscription.nb_periods(recognize_start, recognize_end)
                    to_recognize_amount = (nb_periods * order.dest_amount) / total_periods
                    recognized_amount, _ = Transaction.objects.get_subscription_income_balance(
                        subscription, starts_at=recognize_start, ends_at=recognize_end
                    )
                    # We are not computing a balance sheet here but looking for
                    # a positive amount to compare with the revenue that should
                    # have been recognized.
                    recognized_amount = abs(recognized_amount)
                    if to_recognize_amount > recognized_amount:
                        # We have some amount of revenue to recognize here.
                        # ``at_time`` is set just before ``recognize_end``
                        # so we do not include the newly created transaction
                        # in the subsequent period.
                        Transaction.objects.create_income_recognized(
                            subscription,
                            amount=to_recognize_amount - recognized_amount,
                            at_time=recognize_end - relativedelta(seconds=1),
                            descr=DESCRIBE_RECOGNIZE_INCOME
                            % {"period_start": recognize_start, "period_end": recognize_end},
                        )
                    recognize_start = recognize_end
                    recognize_end += recognize_period
                order_subscribe_beg = order_subscribe_end
                if recognize_end >= until:
                    break
开发者ID:altuzar,项目名称:djaodjin-saas,代码行数:53,代码来源:charge.py


示例18: get_queryset

 def get_queryset(self):
     self.customer = self.get_organization()
     created_at = datetime_or_now()
     prorate_to_billing = False
     prorate_to = None
     if prorate_to_billing:
         # XXX First we add enough periods to get the next billing date later
         # than created_at but no more than one period in the future.
         prorate_to = self.customer.billing_start
     invoicables = []
     for cart_item in CartItem.objects.get_cart(user=self.request.user):
         if cart_item.email:
             full_name = ' '.join([
                     cart_item.first_name, cart_item.last_name]).strip()
             for_descr = ', for %s (%s)' % (full_name, cart_item.email)
             organization_queryset = Organization.objects.filter(
                 email=cart_item.email)
             if organization_queryset.exists():
                 organization = organization_queryset.get()
             else:
                 organization = Organization(
                     full_name='%s %s' % (
                         cart_item.first_name, cart_item.last_name),
                     email=cart_item.email)
         else:
             for_descr = ''
             organization = self.customer
         try:
             subscription = Subscription.objects.get(
                 organization=organization, plan=cart_item.plan)
         except Subscription.DoesNotExist:
             ends_at = prorate_to
             if not ends_at:
                 ends_at = created_at
             subscription = Subscription.objects.new_instance(
                 organization, cart_item.plan, ends_at=ends_at)
         lines = []
         options = self.get_invoicable_options(subscription, created_at,
             prorate_to=prorate_to, coupon=cart_item.coupon)
         if cart_item.nb_periods > 0:
             # The number of periods was already selected so we generate
             # a line instead.
             for line in options:
                 if line.orig_amount == cart_item.nb_periods:
                     line.descr += for_descr
                     lines += [line]
                     options = []
                     break
         invoicables += [{
             'name': cart_item.name, 'descr': cart_item.descr,
             'subscription': subscription,
             "lines": lines, "options": options}]
     return invoicables
开发者ID:wshcdr,项目名称:djaodjin-saas,代码行数:53,代码来源:billing.py


示例19: pass_paid_subscription

def pass_paid_subscription(request, organization=None, plan=None):
    #pylint: disable=unused-argument
    if organization and not isinstance(organization, Organization):
        organization = get_object_or_404(Organization, slug=organization)
    if plan and not isinstance(plan, Plan):
        plan = get_object_or_404(Plan, slug=plan)
    subscribed_at = datetime_or_now()
    subscriptions = Subscription.objects.filter(
        organization=organization, plan=plan,
        ends_at__gt=subscribed_at)
    if not subscriptions.exists():
        raise Http404("%(organization)s has no subscription to %(plan)s'\
' as of %(date)s" % {'organization': organization,
                     'plan': plan, 'date': subscribed_at})
    return not subscriptions.first().is_locked
开发者ID:shadowbw,项目名称:djaodjin-saas,代码行数:15,代码来源:decorators.py


示例20: redeem

 def redeem(request, coupon_code):
     now = datetime_or_now()
     coupon_applied = False
     for item in CartItem.objects.get_cart(request.user):
         coupon = Coupon.objects.filter(
             Q(ends_at__isnull=True) | Q(ends_at__gt=now),
             code__iexact=coupon_code, # case incensitive search.
             organization=item.plan.organization).first()
         if coupon and (not coupon.plan or (coupon.plan == item.plan)):
             # Coupon can be restricted to a plan or apply to all plans
             # of an organization.
             coupon_applied = True
             item.coupon = coupon
             item.save()
     return coupon_applied
开发者ID:wshcdr,项目名称:djaodjin-saas,代码行数:15,代码来源:coupons.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.validate_redirect_url函数代码示例发布时间:2022-05-27
下一篇:
Python s3validators.IS_NUMBER类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap