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


Python Point.create方法代码示例

本文整理汇总了Python中models.point.Point.create方法的典型用法代码示例。如果您正苦于以下问题:Python Point.create方法的具体用法?Python Point.create怎么用?Python Point.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.point.Point的用法示例。


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

示例1: post

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import create [as 别名]
    def post(self):
        user = self.current_user
        resultJSON = json.dumps({'result': False, 'error': 'Not authorized'})
        if user:
            if not self.request.get('title'):                
                resultJSON = json.dumps({'result': False, 'error': 'Your point must have a title'})
            else:
                sourcesURLs=json.loads(self.request.get('sourcesURLs')) if self.request.get('sourcesURLs') else None
                sourcesNames=json.loads(self.request.get('sourcesNames')) if self.request.get('sourcesNames') else None
                newPoint, newPointRoot = Point.create(
                    title=self.request.get('title'),
                    nodetype=self.request.get('nodetype'),                 
                    content=self.request.get('content'),
                    summaryText=self.request.get('plainText'),
                    user=user,
                    imageURL=self.request.get('imageURL'),
                    imageAuthor=self.request.get('imageAuthor'),
                    imageDescription=self.request.get('imageDescription'),
                    sourceURLs=sourcesURLs,
                    sourceNames=sourcesNames)
                if newPoint:
                    resultJSON = json.dumps({'result': True, 
                                     'pointURL': newPoint.url,
                                     'rootKey': newPointRoot.key.urlsafe()})
                else:
                    resultJSON = json.dumps({'result': False, 'error': 'Failed to create point.'})
        else:
            resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'})

        self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
        self.response.out.write(resultJSON)
开发者ID:aaronlifshin,项目名称:howtosavedemocaracy,代码行数:33,代码来源:newpoint.py

示例2: post

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import create [as 别名]
    def post(self):
        jsonOutput = {'result': False}
        oldPoint, oldPointRoot = Point.getCurrentByUrl(
            self.request.get('pointUrl'))
        user = self.current_user
        linkType = self.request.get('linkType')
        nodeType = self.request.get('nodeType') if \
            self.request.get('nodeType') else 'Point'

        sourcesURLs=json.loads(self.request.get('sourcesURLs'))
        sourcesNames=json.loads(self.request.get('sourcesNames'))
        if user:
            newLinkPoint, newLinkPointRoot = Point.create(
                title=self.request.get('title'),
                nodetype=nodeType,
                content=self.request.get('content'),
                summaryText=self.request.get('plainText'),
                user=user,
                backlink=oldPoint.key.parent(),
                linktype = linkType,
                imageURL=self.request.get('imageURL'),
                imageAuthor=self.request.get('imageAuthor'),
                imageDescription=self.request.get('imageDescription'),
                sourceURLs=sourcesURLs,
                sourceNames=sourcesNames)
            try:
                logging.info('Adding newLink: ' + linkType)
                newLinks = [{'pointRoot':newLinkPointRoot,
                            'pointCurrentVersion':newLinkPoint,
                            'linkType':linkType},
                            ]
                newPoint = oldPoint.update(
                    pointsToLink=newLinks,                 
                    user=user
                )
            except WhysaurusException as e:
                jsonOutput = {
                    'result': False,
                    'err': str(e)
                }
            else:
                path = os.path.join(constants.ROOT, 'templates/pointBox.html')
                newLinkPointHTML = json.dumps(template.render(path, {'point': newLinkPoint}))
                jsonOutput = {
                    'result': True,
                    'version': newPoint.version,
                    'author': newPoint.authorName,
                    'dateEdited': newPoint.dateEdited.strftime("%Y-%m-%d %H: %M: %S %p"),
                    'numLinkPoints': newPoint.linkCount(linkType),
                    'newLinkPoint':newLinkPointHTML
                }
            resultJSON = json.dumps(jsonOutput)
            self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
            self.response.out.write(resultJSON)
        else:
            self.response.out.write('Need to be logged in')
开发者ID:aaronlifshin,项目名称:howtosavedemocaracy,代码行数:58,代码来源:addsupportingpoint.py

示例3: doPostLoginAction

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import create [as 别名]
 def doPostLoginAction(self, postLoginAction, sessionData ):
     if postLoginAction == "createFromMain":
         user = self.current_user
         pointText = str(sessionData['pointtext'])
         if user:
             newPoint, newPointRoot = Point.create(
                 title=pointText,
                 content="",
                 summaryText="",
                 user=user,
                 imageURL=None,
                 imageAuthor=None,
                 imageDescription=None,
                 sourceURLs=[],
                 sourceNames=[])
             if newPoint:    
                 template_values = {
                     'user': user, 
                     'currentArea':self.session.get('currentArea'),
                     'currentAreaDisplayName':self.session.get('currentAreaDisplayName'),
                     'pointURL':newPoint.url
                 }
                 html = self.template_render('waitingPage.html', template_values)
                 self.session['postloginaction'] = None
                 self.session['pointText'] = None                    
                 self.response.out.write(html)
                 ReportEvent.queueEventRecord(user.key.urlsafe(), newPoint.key.urlsafe(), None, "Create Point")    
             else:
                logging.error("Was not able to create point with title: " + pointText)    
                self.redirect(str(sessionData['original_url']))
         else:
             logging.error("User was not available, and so could not create point with title: " + pointText)    
             self.redirect(str(sessionData['original_url']))
     else:
         logging.info("Unknown Post Login action " + postLoginAction)    
         self.redirect(str(sessionData['original_url']))
开发者ID:,项目名称:,代码行数:38,代码来源:

示例4: newPoint

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import create [as 别名]
    def newPoint(self):        
        user = self.current_user
        resultJSON = json.dumps({'result': False, 'error': 'Not authorized'})
        secretKey = self.request.get('secret')
        
        if not user:            
            if (secretKey == 'myballotsecret'):
                self.loginBySecretKey(secretKey)
                user = self.current_user
                if user:
                    self.response.headers['Access-Control-Allow-Origin'] = '*'

        if user:            
            if not self.request.get('title'):                
                resultJSON = json.dumps({'result': False, 'error': 'Your point must have a title'})
            else:
                sourcesURLs=json.loads(self.request.get('sourcesURLs')) if self.request.get('sourcesURLs') else None
                sourcesNames=json.loads(self.request.get('sourcesNames')) if self.request.get('sourcesNames') else None
                newPoint, newPointRoot = Point.create(
                    title=self.request.get('title'),
                    content=self.request.get('content'),
                    summaryText=self.request.get('plainText'),
                    user=user,
                    imageURL=self.request.get('imageURL'),
                    imageAuthor=self.request.get('imageAuthor'),
                    imageDescription=self.request.get('imageDescription'),
                    sourceURLs=sourcesURLs,
                    sourceNames=sourcesNames)
                       
                if newPoint:                    
                    recentlyViewed, sources = yield user.getRecentlyViewed_async( \
                                excludeList=[newPoint.key.parent()] + \
                                newPoint.getLinkedPointsRootKeys("supporting") + \
                                newPoint.getLinkedPointsRootKeys("counter")), \
                            newPoint.getSources_async()
                            
                    templateValues = {
                        'point': newPoint,
                        'pointRoot': newPointRoot,
                        'recentlyViewedPoints': recentlyViewed,
                        'supportingPoints': None,
                        'counterPoints': None,
                        'supportedPoints':newPointRoot.getBacklinkPoints("supporting"),
                        'counteredPoints':newPointRoot.getBacklinkPoints("counter"),
                        'sources': sources,
                        'user': user,
                        'voteValue': 0,
                        'ribbonValue': False,
                        'currentArea':self.session.get('currentArea'),
                        'currentAreaDisplayName':self.session.get('currentAreaDisplayName')
                    }
                    html = self.template_render('pointContent.html', templateValues)

                    templateValues = {
                        'user': self.current_user,                
                        'pointRoot': newPointRoot,
                        'comments': None
                    }        
                    commentHTML = self.template_render('pointComments.html', templateValues)
                    resultJSON = json.dumps({'result': True, 
                                     'pointURL': newPoint.url,
                                     'title':newPoint.title,
                                     'html': html,
                                     'commentHTML': commentHTML,
                                     'rootKey': newPointRoot.key.urlsafe()
                                 })
                    ReportEvent.queueEventRecord(user.key.urlsafe(), newPoint.key.urlsafe(), None, "Create Point") 
                else:
                    resultJSON = json.dumps({'result': False, 'error': 'Failed to create point.'})
        else:
            resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'})

        self.response.headers["Pragma"]="no-cache"
        self.response.headers["Cache-Control"]="no-cache, no-store, must-revalidate, pre-check=0, post-check=0"
        self.response.headers["Expires"]="Thu, 01 Dec 1994 16:00:00"  
        self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
        self.response.out.write(resultJSON)
开发者ID:aaronlifshin,项目名称:whysaurus,代码行数:79,代码来源:newpoint.py

示例5: __init__

# 需要导入模块: from models.point import Point [as 别名]
# 或者: from models.point.Point import create [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.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。