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

Python utils.now_datetime函数代码示例

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

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



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

示例1: get_error_report

def get_error_report(from_date=None, to_date=None, limit=10):
	from webnotes.utils import get_url, now_datetime, add_days
	
	if not from_date:
		from_date = add_days(now_datetime().date(), -1)
	if not to_date:
		to_date = add_days(now_datetime().date(), -1)
	
	errors = get_errors(from_date, to_date, limit)
	
	if errors:
		return 1, """<h4>Scheduler Failed Events (max {limit}):</h4>
			<p>URL: <a href="{url}" target="_blank">{url}</a></p><hr>{errors}""".format(
			limit=limit, url=get_url(), errors="<hr>".join(errors))
	else:
		return 0, "<p>Scheduler didn't encounter any problems.</p>"
开发者ID:Halfnhav,项目名称:wnframework,代码行数:16,代码来源:scheduler.py


示例2: get_post_list_html

def get_post_list_html(group, view, limit_start=0, limit_length=20):
	access = get_access(group)
	
	if isinstance(view, basestring):
		view = get_views()[view]
	
	view = webnotes._dict(view)
	
	# verify permission for paging
	if webnotes.local.form_dict.cmd == "get_post_list_html":
		if not access.get("read"):
			return webnotes.PermissionError
			
	if view.name == "feed":
		order_by = "p.creation desc"
	else:
		now = get_datetime_str(now_datetime())
		order_by = """(p.upvotes + post_reply_count - (timestampdiff(hour, p.creation, \"{}\") / 2)) desc, 
			p.creation desc""".format(now)
	
	posts = webnotes.conn.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name,
		(select count(pc.name) from `tabPost` pc where pc.parent_post=p.name) as post_reply_count
		from `tabPost` p, `tabProfile` pr
		where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
		order by {order_by} limit %s, %s""".format(order_by=order_by),
		(group, int(limit_start), int(limit_length)), as_dict=True)
		
	context = {"posts": posts, "limit_start": limit_start, "view": view}
	
	return webnotes.get_template("templates/includes/post_list.html").render(context)
开发者ID:bindscha,项目名称:wnframework_old,代码行数:30,代码来源:forum.py


示例3: get_post_list_html

def get_post_list_html(group, view, limit_start=0, limit_length=20):
	access = get_access(group)
	
	if isinstance(view, basestring):
		view = get_views()[view]
	
	view = webnotes._dict(view)
	
	# verify permission for paging
	if webnotes.local.form_dict.cmd == "get_post_list_html":
		if not access.get("read"):
			return webnotes.PermissionError
			
	if view.name=="upcoming":
		condition = "and p.event_datetime >= %s"
		order_by = "p.event_datetime asc"
	else:
		condition = "and p.event_datetime < %s"
		order_by = "p.event_datetime desc"
		
	# should show based on time upto precision of hour
	# because the current hour should also be in upcoming
	now = now_datetime().replace(minute=0, second=0, microsecond=0)
	
	posts = webnotes.conn.sql("""select p.*, pr.user_image, pr.first_name, pr.last_name,
		(select count(pc.name) from `tabPost` pc where pc.parent_post=p.name) as post_reply_count
		from `tabPost` p, `tabProfile` pr
		where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
		and p.is_event=1 {condition}
		order by {order_by} limit %s, %s""".format(condition=condition, order_by=order_by),
		(group, now, int(limit_start), int(limit_length)), as_dict=True)
		
	context = {"posts": posts, "limit_start": limit_start, "view": view}
	
	return webnotes.get_template("templates/includes/post_list.html").render(context)
开发者ID:bindscha,项目名称:wnframework_old,代码行数:35,代码来源:events.py


示例4: get_creation_count

	def get_creation_count(self, doctype, minutes):
		"""get count of records created in the last x minutes"""
		from webnotes.utils import now_datetime
		from dateutil.relativedelta import relativedelta
		
		return webnotes.conn.sql("""select count(name) from `tab{doctype}`
			where creation >= %s""".format(doctype=doctype),
			now_datetime() - relativedelta(minutes=minutes))[0][0]
开发者ID:bindscha,项目名称:wnframework_old,代码行数:8,代码来源:db.py


示例5: send

def send():
	from webnotes.model.code import get_obj
	now_date = now_datetime().date()
	
	for ed in webnotes.conn.sql("""select name from `tabEmail Digest`
			where enabled=1 and docstatus<2""", as_list=1):
		ed_obj = get_obj('Email Digest', ed[0])
		if (now_date == ed_obj.get_next_sending()):
			ed_obj.send()
开发者ID:smilekk,项目名称:erpnext,代码行数:9,代码来源:email_digest.py


示例6: validate_end_of_life

def validate_end_of_life(item_code, end_of_life=None, verbose=1):
	if not end_of_life:
		end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
	
	from webnotes.utils import getdate, now_datetime, formatdate
	if end_of_life and getdate(end_of_life) > now_datetime().date():
		msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \
			" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
			"in Item master") % {
				"item_code": item_code,
				"date": formatdate(end_of_life),
				"end_of_life_label": webnotes.get_doctype("Item").get_label("end_of_life")
			}
		
		_msgprint(msg, verbose)
开发者ID:jacara,项目名称:erpclone,代码行数:15,代码来源:utils.py


示例7: send

def send():
	from webnotes.model.code import get_obj
	from webnotes.utils import getdate
	now_date = now_datetime().date()
	
	from webnotes import conf
	if "expires_on" in conf and now_date > getdate(conf.expires_on):
		# do not send email digests to expired accounts
		return
	
	for ed in webnotes.conn.sql("""select name from `tabEmail Digest`
			where enabled=1 and docstatus<2""", as_list=1):
		ed_obj = get_obj('Email Digest', ed[0])
		if (now_date == ed_obj.get_next_sending()):
			ed_obj.send()
开发者ID:aalishanmatrix,项目名称:erpnext,代码行数:15,代码来源:email_digest.py


示例8: validate_hour

	def validate_hour(self):
		"""check if user is logging in during restricted hours"""
		login_before = int(webnotes.conn.get_value('Profile', self.user, 'login_before', ignore=True) or 0)
		login_after = int(webnotes.conn.get_value('Profile', self.user, 'login_after', ignore=True) or 0)
		
		if not (login_before or login_after):
			return
			
		from webnotes.utils import now_datetime
		current_hour = int(now_datetime().strftime('%H'))
				
		if login_before and current_hour > login_before:
			webnotes.msgprint('Not allowed to login after restricted hour', raise_exception=1)

		if login_after and current_hour < login_after:
			webnotes.msgprint('Not allowed to login before restricted hour', raise_exception=1)
开发者ID:saurabh6790,项目名称:omn-lib,代码行数:16,代码来源:auth.py


示例9: get_future_from_to_date

	def get_future_from_to_date(self):
		today = now_datetime().date()
		
		# decide from date based on email digest frequency
		if self.doc.frequency == "Daily":
			# from date, to_date is today
			from_date = to_date = today
		elif self.doc.frequency == "Weekly":
			# from date is the current week's monday
			from_date = today - timedelta(days=today.weekday())
			# to date is the current week's sunday
			to_date = from_date + timedelta(days=6)
		else:
			# from date is the 1st day of the current month
			from_date = today - relativedelta(days=today.day-1)
			# to date is the last day of the current month
			to_date = from_date + relativedelta(days=-1, months=1)
			
		return from_date, to_date
开发者ID:aalishanmatrix,项目名称:erpnext,代码行数:19,代码来源:email_digest.py


示例10: get_from_to_date

	def get_from_to_date(self):
		today = now_datetime().date()
		
		# decide from date based on email digest frequency
		if self.doc.frequency == "Daily":
			# from date, to_date is yesterday
			from_date = to_date = today - timedelta(days=1)
		elif self.doc.frequency == "Weekly":
			# from date is the previous week's monday
			from_date = today - timedelta(days=today.weekday(), weeks=1)
			# to date is sunday i.e. the previous day
			to_date = from_date + timedelta(days=6)
		else:
			# from date is the 1st day of the previous month
			from_date = today - relativedelta(days=today.day-1, months=1)
			# to date is the last day of the previous month
			to_date = today - relativedelta(days=today.day)

		return from_date, to_date
开发者ID:aalishanmatrix,项目名称:erpnext,代码行数:19,代码来源:email_digest.py


示例11: get_start_end_dates

	def get_start_end_dates(self):
		"""
			Returns start and end date depending on the frequency of email digest
		"""
		from datetime import datetime, date, timedelta
		from webnotes.utils import now_datetime
		today = now_datetime().date()
		year, month, day = today.year, today.month, today.day
		
		if self.doc.frequency == 'Daily':
			if self.sending:
				start_date = end_date = today - timedelta(days=1)
			else:
				start_date = end_date = today
		
		elif self.doc.frequency == 'Weekly':
			if self.sending:
				start_date = today - timedelta(days=today.weekday(), weeks=1)
				end_date = start_date + timedelta(days=6)
			else:
				start_date = today - timedelta(days=today.weekday())
				end_date = start_date + timedelta(days=6)

		else:
			import calendar
			
			if self.sending:
				if month == 1:
					year = year - 1
					prev_month = 12
				else:
					prev_month = month - 1
				start_date = date(year, prev_month, 1)
				last_day = calendar.monthrange(year, prev_month)[1]
				end_date = date(year, prev_month, last_day)
			else:
				start_date = date(year, month, 1)
				last_day = calendar.monthrange(year, month)[1]
				end_date = date(year, month, last_day)

		return start_date, end_date
开发者ID:antoxin,项目名称:erpnext,代码行数:41,代码来源:email_digest.py


示例12: test_get_value

	def test_get_value(self):
		from webnotes.utils import now_datetime
		import time
		webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""")
		
		now = now_datetime()
		
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<", now]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<=", now]}), "Administrator")

		time.sleep(2)
		if "Profile" in webnotes.local.test_objects:
			del webnotes.local.test_objects["Profile"]
		make_test_records("Profile")
		
		self.assertEquals("[email protected]", webnotes.conn.get_value("Profile", {"modified": [">", now]}))
		self.assertEquals("[email protected]", webnotes.conn.get_value("Profile", {"modified": [">=", now]}))
		
开发者ID:bindscha,项目名称:wnframework_old,代码行数:20,代码来源:test_db.py


示例13: send

def send():
	"""

	"""
	edigest_list = webnotes.conn.sql("""
		SELECT name FROM `tabEmail Digest`
		WHERE enabled=1 and docstatus<2
	""", as_list=1)

	from webnotes.model.code import get_obj
	from webnotes.utils import now_datetime

	now_date = now_datetime().date()
	
	for ed in edigest_list:
		if ed[0]:
			ed_obj = get_obj('Email Digest', ed[0])
			ed_obj.sending = True
			send_date = ed_obj.get_next_sending()
			#webnotes.msgprint([ed[0], now_date, send_date])

			if (now_date == send_date):
				ed_obj.send()
开发者ID:antoxin,项目名称:erpnext,代码行数:23,代码来源:email_digest.py


示例14: test_recurring_invoice

	def test_recurring_invoice(self):
		from webnotes.utils import now_datetime, get_first_day, get_last_day, add_to_date
		today = now_datetime().date()
		
		base_si = webnotes.bean(copy=test_records[0])
		base_si.doc.fields.update({
			"convert_into_recurring_invoice": 1,
			"recurring_type": "Monthly",
			"notification_email_address": "[email protected], [email protected], [email protected]",
			"repeat_on_day_of_month": today.day,
			"posting_date": today,
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(today)
		})
		
		# monthly
		si1 = webnotes.bean(copy=base_si.doclist)
		si1.insert()
		si1.submit()
		self._test_recurring_invoice(si1, True)
		
		# monthly without a first and last day period
		si2 = webnotes.bean(copy=base_si.doclist)
		si2.doc.fields.update({
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, days=30)
		})
		si2.insert()
		si2.submit()
		self._test_recurring_invoice(si2, False)
		
		# quarterly
		si3 = webnotes.bean(copy=base_si.doclist)
		si3.doc.fields.update({
			"recurring_type": "Quarterly",
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(add_to_date(today, months=3))
		})
		si3.insert()
		si3.submit()
		self._test_recurring_invoice(si3, True)
		
		# quarterly without a first and last day period
		si4 = webnotes.bean(copy=base_si.doclist)
		si4.doc.fields.update({
			"recurring_type": "Quarterly",
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, months=3)
		})
		si4.insert()
		si4.submit()
		self._test_recurring_invoice(si4, False)
		
		# yearly
		si5 = webnotes.bean(copy=base_si.doclist)
		si5.doc.fields.update({
			"recurring_type": "Yearly",
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(add_to_date(today, years=1))
		})
		si5.insert()
		si5.submit()
		self._test_recurring_invoice(si5, True)
		
		# yearly without a first and last day period
		si6 = webnotes.bean(copy=base_si.doclist)
		si6.doc.fields.update({
			"recurring_type": "Yearly",
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, years=1)
		})
		si6.insert()
		si6.submit()
		self._test_recurring_invoice(si6, False)
		
		# change posting date but keep recuring day to be today
		si7 = webnotes.bean(copy=base_si.doclist)
		si7.doc.fields.update({
			"posting_date": add_to_date(today, days=-3)
		})
		si7.insert()
		si7.submit()
		
		# setting so that _test function works
		si7.doc.posting_date = today
		self._test_recurring_invoice(si7, True)
开发者ID:BillTheBest,项目名称:erpnext,代码行数:86,代码来源:test_sales_invoice.py


示例15: validate_posting_time

	def validate_posting_time(self):
		if not self.doc.posting_time:
			self.doc.posting_time = now_datetime().strftime('%H:%M:%S')
开发者ID:rajatkapoor,项目名称:erpnext,代码行数:3,代码来源:transaction_base.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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