本文整理汇总了Python中saas.utils.datetime_or_now函数的典型用法代码示例。如果您正苦于以下问题:Python datetime_or_now函数的具体用法?Python datetime_or_now怎么用?Python datetime_or_now使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了datetime_or_now函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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)
示例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)
示例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)
示例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')
示例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
)
示例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()
示例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
示例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
示例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
示例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)
示例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)
示例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)
}])
示例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))