本文整理匯總了Python中models.point.Point.getCurrentByUrl方法的典型用法代碼示例。如果您正苦於以下問題:Python Point.getCurrentByUrl方法的具體用法?Python Point.getCurrentByUrl怎麽用?Python Point.getCurrentByUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.point.Point
的用法示例。
在下文中一共展示了Point.getCurrentByUrl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
resultJSON = json.dumps({'result': False})
supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get('supportingPointURL'))
oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get('parentPointURL'))
user = self.current_user
linkType = self.request.get('linkType')
if user:
try:
newLink = [{'pointRoot':supportingPointRoot,
'pointCurrentVersion':supportingPoint,
'linkType':self.request.get('linkType')}
]
oldPoint.update(
pointsToLink=newLink,
user=user
)
except WhysaurusException as e:
resultJSON = json.dumps({'result': False, 'error': str(e)})
else:
path = os.path.join(constants.ROOT, 'templates/pointBox.html')
newLinkPointHTML = json.dumps(template.render(path, {'point': supportingPoint}))
resultJSON = json.dumps({'result': True,
'numLinkPoints': supportingPoint.linkCount(linkType),
'newLinkPoint':newLinkPointHTML})
else:
resultJSON = json.dumps({'result': 'ACCESS DENIED!'})
self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
self.response.out.write(resultJSON)
示例2: get
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def get(self):
user = self.current_user
linkType = 'supporting'
p1, pRoot1 = Point.getCurrentByUrl('CCC')
p2, pRoot2 = Point.getCurrentByUrl('bbb')
#result, newRelevance, newVoteCount = \
# user.addRelevanceVote(pRoot1.key.urlsafe(), pRoot2.key.urlsafe(), linkType, 50)
"""newRelVote = RelevanceVote(
parent=user.key,
parentPointRootKey = pRoot1.key,
childPointRootKey = pRoot2.key,
value = 50,
linkType=linkType)
newRelVote.put()"""
# GET THE VOTE BACK
q = RelevanceVote.query(RelevanceVote.parentPointRootKey == pRoot1.key,
RelevanceVote.childPointRootKey == pRoot2.key,
RelevanceVote.linkType == linkType)
votes = q.fetch(20)
message = ""
message = 'Got %d votes on retrieval.' % len(votes)
template_values = {
'user': user,
'message': message,
'currentArea':self.session.get('currentArea'),
'currentAreaDisplayName':self.session.get('currentAreaDisplayName')
}
self.response.out.write(self.template_render('message.html', template_values))
示例3: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
jsonOutput = {'result': False}
user = self.current_user
linkType = self.request.get('linkType')
sourcesURLs=json.loads(self.request.get('sourcesURLs'))
sourcesNames=json.loads(self.request.get('sourcesNames'))
parentNewScore = None
if user:
try:
parentPointURL = self.request.get('pointUrl')
oldPoint, oldPointRoot = Point.getCurrentByUrl(parentPointURL)
if oldPointRoot:
newPoint, newLinkPoint = Point.addSupportingPoint(
oldPointRoot=oldPointRoot,
title=self.request.get('title'),
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'),
sourcesURLs=sourcesURLs,
sourcesNames=sourcesNames
)
# TODO: Gene: Probably have a more efficient retrieval here no?
oldPoint, oldPointRoot = Point.getCurrentByUrl(parentPointURL)
if oldPoint:
parentNewScore = oldPoint.pointValue()
else:
raise WhysaurusException('Point with URL %s not found' % parentPointURL)
except WhysaurusException as e:
jsonOutput = {
'result': False,
'errMessage': str(e)
}
else:
ReportEvent.queueEventRecord(user.key.urlsafe(), newLinkPoint.key.urlsafe(), newPoint.key.urlsafe(), "Create Point")
newLinkPointHTML = self.template_render('linkPoint.html', {
'point': newLinkPoint,
'linkType': linkType
})
jsonOutput = {
'result': True,
'version': newPoint.version,
'author': newPoint.authorName,
'dateEdited': newPoint.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
'numLinkPoints': newPoint.linkCount(linkType),
'newLinkPoint': newLinkPointHTML,
'authorURL': self.current_user.url,
'parentNewScore': parentNewScore
}
self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
self.response.out.write(json.dumps(jsonOutput))
else:
self.response.out.write('Need to be logged in')
示例4: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
self.response.headers["Content-Type"] = "application/json; charset=utf-8"
resultJSON = json.dumps({"result": False})
supportingPoint, supportingPointRoot = Point.getCurrentByUrl(self.request.get("supportingPointURL"))
oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("parentPointURL"))
user = self.current_user
linkType = self.request.get("linkType")
if user:
try:
# This code is if the vote existed before and the point was unlinked, and now
# it is being re-linked
voteCount, rating, myVote = RelevanceVote.getExistingVoteNumbers(
oldPointRoot.key, supportingPointRoot.key, linkType, user
)
supportingPoint._relevanceVote = myVote
linkType = self.request.get("linkType")
newLink = [
{
"pointRoot": supportingPointRoot,
"pointCurrentVersion": supportingPoint,
"linkType": linkType,
"voteCount": voteCount,
"fRating": rating,
}
]
newVersion = oldPoint.update(pointsToLink=newLink, user=user)
user.addRelevanceVote(oldPointRoot.key.urlsafe(), supportingPointRoot.key.urlsafe(), linkType, 100)
# get my vote for this point, to render it in the linkPoint template
supportingPoint.addVote(user)
except WhysaurusException as e:
resultJSON = json.dumps({"result": False, "error": e.message})
else:
if newVersion:
newLinkPointHTML = self.template_render(
"linkPoint.html", {"point": supportingPoint, "linkType": linkType}
)
resultJSON = json.dumps(
{
"result": True,
"numLinkPoints": newVersion.linkCount(linkType),
"newLinkPoint": newLinkPointHTML,
"authorURL": self.current_user.url,
"author": newVersion.authorName,
"dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"),
}
)
else:
json.dumps({"result": False, "error": "There was a problem updating the point."})
else:
resultJSON = json.dumps({"result": "User not logged in. ACCESS DENIED!"})
self.response.out.write(resultJSON)
示例5: checkDBPoint
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def checkDBPoint(self, pointURL):
point, pointRoot = Point.getCurrentByUrl(pointURL)
if point:
isError1, messages1 = self.checkPointNew(point)
if pointRoot:
isError2, messages2 = self.checkRoot(pointRoot)
if not isError1 and not isError2:
message = 'No errors were found.'
else:
messages = []
if messages1:
messages += messages1
if messages2:
messages += messages2
if messages == []:
messages = ['Errors generated, but no messages generated.']
template_values = {
'messages': messages,
'user': self.current_user,
'currentArea':self.session.get('currentArea')
}
self.response.out.write(self.template_render('message.html', template_values))
示例6: getPointCreator
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def getPointCreator(self):
result = {'result': False}
point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
versionsOfThisPoint = Point.query(ancestor=pointRoot.key).order(Point.version)
firstVersion = versionsOfThisPoint.get()
authors = []
"""code for listing number of contributors"""
"""
for point in versionsOfThisPoint:
thisAuthor = {"authorName": point.authorName, "authorURL": point.authorURL }
if thisAuthor not in authors:
authors.append(thisAuthor)
"""
resultJSON = json.dumps({
'result': True,
'creatorName' : firstVersion.authorName,
'creatorURL' : firstVersion.authorURL,
'numAuthors' : len(authors)
})
self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
self.response.out.write(resultJSON)
示例7: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
resultJSON = json.dumps({'result': False})
if self.current_user:
if self.current_user.isLimited:
resultJSON = json.dumps({'result': False, 'error': 'This account cannot unlink points.'})
elif self.request.get('mainPointURL'):
mainPoint, pointRoot = Point.getCurrentByUrl(self.request.get('mainPointURL'))
if self.request.get('supportingPointURL'):
supportingPointURL = self.request.get('supportingPointURL')
newVersion = mainPoint.unlink(self.request.get('supportingPointURL'),
self.request.get('linkType'),
self.current_user)
if newVersion:
resultJSON = json.dumps({
'result': True,
'pointURL': supportingPointURL,
'authorURL': self.current_user.url,
'author': newVersion.authorName,
'dateEdited': newVersion.PSTdateEdited.strftime('%b. %d, %Y, %I:%M %p'),
})
else:
resultJSON = json.dumps({'result': False, 'error': 'URL of main point was not supplied.'})
else:
resultJSON = json.dumps({'result': False, 'error': 'You appear not to be logged in.'})
self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
self.response.out.write(resultJSON)
示例8: checkDBPointRoot
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def checkDBPointRoot(pointRoot):
logging.info('Checking %s ' % pointRoot.url)
point, pr = Point.getCurrentByUrl(pointRoot.url)
isError1 = False
isError2 = False
messages1 = []
messages2 = []
dbc = DBIntegrityCheck()
if point:
isError1, messages1 = dbc.checkPoint(point)
if pointRoot:
isError2, messages2 = dbc.checkRoot(pointRoot)
if not isError1 and not isError2:
message = 'No errors were found in %s.' % pointRoot.url
logging.info(message)
else:
message = []
if messages1:
message = message + messages1
if messages2:
message = message + messages2
if message == []:
message = ['Errors generated, but no messages generated.']
if isError1:
logging.info(messages1)
if isError2:
logging.info(messages2)
for m in message:
logging.info(message)
return message
示例9: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
resultJSON = json.dumps({'result': False})
point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
user = self.current_user
if point and user:
if user.addVote(point, int(self.request.get('vote'))):
resultJSON = json.dumps({'result': True, 'newVote': self.request.get('vote')})
self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
self.response.out.write(resultJSON)
示例10: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [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')
示例11: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
resultJSON = json.dumps({'result': False})
point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
user = self.current_user
newRibbonValue = self.request.get('ribbon') == 'true'
if point and user:
if user.setRibbon(point, newRibbonValue):
resultJSON = json.dumps({'result': True, 'ribbonTotal': point.ribbonTotal})
self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
self.response.out.write(resultJSON)
示例12: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
user = self.current_user
if user:
resultJSON = json.dumps({"result": False})
oldPoint, oldPointRoot = Point.getCurrentByUrl(self.request.get("urlToEdit"))
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
sourcesToRemove = (
json.loads(self.request.get("sourcesToRemove")) if self.request.get("sourcesToRemove") else None
)
if oldPoint == None:
resultJSON = json.dumps(
{"result": False, "error": "Unable to edit point. Please refresh the page and try again."}
)
elif user.isLimited:
resultJSON = json.dumps({"result": False, "error": "This account cannot edit points."})
else:
sources = Source.constructFromArrays(sourcesURLs, sourcesNames, oldPoint.key)
newVersion = oldPoint.update(
newTitle=self.request.get("title"),
newContent=self.request.get("content"),
newSummaryText=self.request.get("plainText"),
user=self.current_user,
imageURL=self.request.get("imageURL"),
imageAuthor=self.request.get("imageAuthor"),
imageDescription=self.request.get("imageDescription"),
sourcesToAdd=sources,
sourceKeysToRemove=sourcesToRemove,
)
if newVersion:
sources = newVersion.getSources()
sourcesHTML = self.template_render("sources.html", {"sources": sources})
resultJSON = json.dumps(
{
"result": True,
"version": newVersion.version,
"author": newVersion.authorName,
"authorURL": self.current_user.url,
"dateEdited": newVersion.PSTdateEdited.strftime("%b. %d, %Y, %I:%M %p"),
"pointURL": newVersion.url,
"imageURL": newVersion.imageURL,
"imageAuthor": newVersion.imageAuthor,
"imageDescription": newVersion.imageDescription,
"sourcesHTML": sourcesHTML,
}
)
ReportEvent.queueEventRecord(user.key.urlsafe(), newVersion.key.urlsafe(), None, "Edit Point")
else:
# This is the only way newVersion will fail
resultJSON = json.dumps({"result": False, "error": "You appear not to be logged in."})
self.response.headers["Content-Type"] = "application/json; charset=utf-8"
self.response.out.write(resultJSON)
示例13: post
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def post(self):
resultJSON = json.dumps({'result': False})
point, pointRoot = Point.getCurrentByUrl(self.request.get('pointURL'))
parentPointURL = self.request.get('parentPointURL')
parentPoint = None
if parentPointURL:
parentPoint, parentPointRoot = Point.getCurrentByUrl(parentPointURL)
user = self.current_user
if point and user:
if user.addVote(point, int(self.request.get('vote'))):
point.updateBacklinkedSorts(pointRoot)
parentNewScore = None
if parentPoint:
parentNewScore = parentPoint.pointValue()
resultJSON = json.dumps({'result': True,
'newVote': self.request.get('vote'),
'newScore': point.pointValue(),
'parentNewScore': parentNewScore})
self.response.headers["Content-Type"] = 'application/json; charset=utf-8'
self.response.out.write(resultJSON)
示例14: cleanDeadBacklinks
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def cleanDeadBacklinks(self, pointURL):
point, pointRoot = Point.getCurrentByUrl(pointURL)
if pointRoot:
rootsRemoved = pointRoot.removeDeadBacklinks()
message = 'Removed %d dead roots from %s' % (rootsRemoved, point.title)
else:
message = 'Could not find point'
template_values = {
'message': message,
'user': self.current_user,
'currentArea':self.session.get('currentArea')
}
self.response.out.write(self.template_render('message.html', template_values))
示例15: addMissingBacklinks
# 需要導入模塊: from models.point import Point [as 別名]
# 或者: from models.point.Point import getCurrentByUrl [as 別名]
def addMissingBacklinks(self, pointURL):
point, pointRoot = Point.getCurrentByUrl(pointURL)
if point:
rootsAdded = point.addMissingBacklinks()
message = 'Added %d missing roots to links of %s' % (rootsAdded, point.title)
else:
message = 'Could not find point'
template_values = {
'message': message,
'user': self.current_user,
'currentArea':self.session.get('currentArea')
}
self.response.out.write(self.template_render('message.html', template_values))