當前位置: 首頁>>代碼示例>>Python>>正文


Python Point.retrieve_one方法代碼示例

本文整理匯總了Python中models.point.Point.retrieve_one方法的典型用法代碼示例。如果您正苦於以下問題:Python Point.retrieve_one方法的具體用法?Python Point.retrieve_one怎麽用?Python Point.retrieve_one使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.point.Point的用法示例。


在下文中一共展示了Point.retrieve_one方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import retrieve_one [as 別名]
class Point_Controller:
	def __init__(self, db):
		self.db = db
		self.point_hook = Point(db)
		self.pv_hook = PV(db)

	# Utility
	def get_current_pv_id(self):
		cookie_data = request.get_cookie('spvm', dict(), secret='secret')

		if not isinstance(cookie_data, dict) and cookie_is_encoded(cookie_data):
			cookie_data = cookie_decode(cookie_data, 'key')

		if 'pv_id' not in cookie_data or cookie_data['pv_id'] is None:
			redirect('/')

		return cookie_data['pv_id']

	### New
	def get_new_point(self):
		points = self.point_hook.retrieve(where={'pv_id':pv_id, 'parent_id':''}, order="rank ASC", recursion=3)

		return template('point/new', title="New point", pv_id=self.get_current_pv_id(), points=points, errors=dict())
	get_new_point.route = '/point/new'
	get_new_point.method = 'GET'

	def ajax_get_new_point(self):
		points = self.point_hook.retrieve(where={'pv_id':self.get_current_pv_id(), 'parent_id':''}, order="rank ASC", recursion=3)

		return template('point/new', ajax=True, title="New point", pv_id=self.get_current_pv_id(), points=points, errors=dict())
	ajax_get_new_point.route = '/point/ajax/new'
	ajax_get_new_point.method = 'GET'

	def post_new_point(self):
		fields = dict()
		fields['pv_id'] = request.forms.pv_id
		fields['title'] = request.forms.title
		fields['description'] = request.forms.description
		fields['rank'] = request.forms.rank
		fields['parent_id'] = request.forms.parent_id

		validation_result = self.point_hook.create(fields)

		if isinstance(validation_result, dict):
			points = self.point_hook.retrieve(where={'pv_id':fields['pv_id']})

			return template('point/new', pv_id=fields['pv_id'], points=points, errors=validation_result)
		else:
			redirect('/pv/'+fields['pv_id'])
	post_new_point.route = '/point/new'
	post_new_point.method = 'POST'

	def ajax_post_new_point(self):
		fields = dict()
		fields['pv_id'] = request.forms.pv_id
		fields['title'] = request.forms.title
		fields['description'] = request.forms.description
		fields['rank'] = request.forms.rank
		fields['parent_id'] = request.forms.parent_id

		validation_result = self.point_hook.create(fields)

		if isinstance(validation_result, dict):
			return validation_result
		else:
			record = self.point_hook.retrieve_one(where={'id':validation_result})

			return {'id': validation_result, 'parent_id': record['parent_id'], 'number': self.point_hook.get_numbering(int(validation_result))}
	ajax_post_new_point.route = '/point/ajax/new'
	ajax_post_new_point.method = 'POST'

	### Edit
	def get_edit_point(self, point_id=None):
		data = self.point_hook.retrieve_one(where={'id':point_id})

		points = self.point_hook.retrieve(where={'pv_id':data['pv_id']})

		return template('point/edit', title="Edit point", data=data, points=points, errors=dict())
	get_edit_point.route = '/point/edit/<point_id>'
	get_edit_point.method = 'GET'

	def ajax_get_edit_point(self):
		data = self.point_hook.retrieve_one(where={'id':request.query.point_id})

		points = self.point_hook.retrieve(where={'pv_id':data['pv_id']})

		return template('point/edit', ajax=True, title="Edit point", data=data, points=points, errors=dict())
	ajax_get_edit_point.route = '/point/ajax/edit'
	ajax_get_edit_point.method = 'GET'

	def post_edit_point(self):
		fields = dict()
		fields['id'] = request.forms.point_id
		fields['pv_id'] = request.forms.pv_id
		fields['title'] = request.forms.title
		fields['description'] = request.forms.description
		fields['rank'] = request.forms.rank
		fields['parent_id'] = request.forms.parent_id

		validation_result = self.point_hook.update(fields, {'id': fields['id']})
#.........這裏部分代碼省略.........
開發者ID:sirzerator,項目名稱:spvm,代碼行數:103,代碼來源:point.py


注:本文中的models.point.Point.retrieve_one方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。