本文整理汇总了Python中models.Node.get方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get方法的具体用法?Python Node.get怎么用?Python Node.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def post(self, urlname):
if not self.has_permission:
return
if not self.current_user.is_admin:
return self.redirect_next_url()
node = Node.get(urlname=urlname)
if not node:
return self.redirect_next_url()
user = self.current_user
args = self.request.arguments
try:
selected = args.get('parent_name')
print(selected)
except:
selected = [n.name for n in node.parent_nodes]
args = {'name': [node.name], 'urlname': [node.urlname],
'description': [node.description], 'style': [node.style]}
form = NodeEditForm.init(Node.get_node_choices(), selected, args=args,
node=node)
if form.validate():
node = form.save(user, node=node)
result = {'status': 'success', 'message': '节点修改成功',
'node_url': node.url}
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect(node.url)
if self.is_ajax:
return self.write(form.result)
return self.render("node/edit.html", form=form, node=node)
示例2: validate_node_name
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def validate_node_name(self, field):
node_name = unicode(self.node_name.data)
node = Node.get(name=node_name)
if not node:
raise ValidationError('不存在此节点')
self.node = node
return node
示例3: get
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def get(self, urlname, category='all'):
node = Node.get(urlname=urlname)
if not node:
raise tornado.web.HTTPError(404)
page = force_int(self.get_argument('page', 1), 1)
action = self.get_argument('action', None)
tag = self.get_argument('tag', None)
if tag:
if tag == 'description':
result = {'status': 'success', 'message': '简介传输成功',
'node_description': node.description,
'node_topic_count': node.topic_count,
'node_follow_count': node.follow_count}
return self.write(result)
if tag == 'relationship':
parent_nodes = node.parent_nodes
child_nodes = node.child_nodes
sibling_nodes = node.sibling_nodes
parent_json = []
children_json = []
sibling_json = []
for p in parent_nodes:
parent_json.append(dict(id=p.id, name=p.name,
url=p.url,
description=p.description,
summary=p.summary,
urlname=p.urlname,
icon=p.icon))
for c in child_nodes:
children_json.append(dict(id=c.id, name=c.name,
url=c.url,
description=c.description,
summary=c.summary,
urlname=c.urlname,
icon=c.icon))
for s in sibling_nodes:
sibling_json.append(dict(id=s.id, name=s.name,
url=s.url,
description=s.description,
summary=s.summary,
urlname=s.urlname,
icon=s.icon))
result = {'status': 'success', 'parent_nodes': parent_json, 'child_nodes':
children_json, 'sibling_nodes': sibling_json}
return self.write(result)
user = self.current_user
if action and user:
if action == 'follow':
result = user.follow(node_id=node.id)
if self.is_ajax:
return self.write(result)
self.flash_message(result)
return self.redirect_next_url()
topic_count = count(node.get_topics(page=None, category=category))
page_count = (topic_count + config.reply_paged - 1) // config.reply_paged
url = node.url + '?category=' + category
topics = node.get_topics(page=page, category=category)
return self.render("node/index.html", node=node, topics=topics,
category=category, page=page, page_count=page_count, url=url)
示例4: main
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def main(argv):
try:
opts, args = getopt.getopt(argv, "", ["install", "init",
"iwanttodropdatabase"])
except getopt.GetoptError:
print("参数错误")
sys.exit(2)
for opt, val in opts:
if opt == "--init":
try:
c.execute("create database %s" % config.db_name)
c.execute("grant all privileges on %s.* to '%s'@'localhost' identified by '%s'" % (config.db_name, config.db_user, config.db_pass))
c.execute("flush privileges")
c.close()
m.commit()
m.close()
except:
pass
db.generate_mapping(create_tables=True)
if not Node.get(id=1):
Node(name=u'根节点', urlname='root',
description=u'一切的根源').save()
print("数据库表初始化成功")
if opt == '--iwanttodropdatabase':
key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n")
if key == "yes i do":
key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n")
if key == "yes i do":
key = raw_input("你确定要删除数据库?所有数据将消失,且无法恢复!!!(若确定请输入yes i do,否则直接按回车键!):\n")
if key == "yes i do":
try:
c.execute("drop database %s" % config.db_name)
except Exception as e:
print(e)
finally:
pass
c.close()
m.commit()
m.close()
print("已清空数据库!")
else:
print("已取消操作!")
if opt == "--install":
base_path = sys.path[0]
try:
print(requirements_path)
os.system('sudo python %s/libs/pony/setup.py install' %
base_path)
os.system('sudo pip install -r %s/requirements.txt' %
base_path)
except e:
print(e)
finally:
print("依赖安装成功")
示例5: get
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def get(self):
node_id = int(self.get_argument('node_id', 0))
node = Node.get(id=node_id)
if node:
selected = [node.name]
else:
selected = []
form = NodeForm.init(Node.get_node_choices(), selected)
return self.render("node/create.html", form=form)
示例6: get
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def get(self):
node_id = force_int(self.get_argument('node_id', 0), 0)
node = Node.get(id=node_id)
if node:
selected = node.name
else:
selected = None
choices = Node.get_node_choices()
form = TopicForm.init(choices=choices, selected=selected)
return self.render("topic/create.html", form=form, node=node)
示例7: delete
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def delete(request, key):
form = ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
if form.drop.data is True:
node = Node.get(key)
db.delete(node.blocks)
Node.drop(key)
return redirect('/admin/pages/', 301)
if form.cascade.data is True:
# cascade callback
# inject a cascade callback that does
# # try to delete the key
# for i in range(2):
# if memcache.delete(node.get_absolute_url()) > 0:
# break
Node.drop(key, cascade=True)
# FIXME: remove blocks from dropped Nodes
return redirect(url_for('nut:pages/list_pages'), 301)
node = Node.get(key)
nodes = dict([(n.get_key(), n) for n in Node.all().filter("ancestors = ", key)])
node = rec(node, nodes)
return render_template('app:pages/confirm_delete.html', form=form,
node=node)
示例8: save
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def save(self, user, topic=None):
data = self.data
try:
node_name = data.pop('node_name')
if not self.node:
self.node = Node.get(name=node_name)
except KeyError:
logging.info('no node_name in form data, data: %s', data)
if not self.node:
logging.info('node is None in form instance, self: %s', self)
content = unicode(data.get('content'))
data.update({'user_id': user.id, 'node_id': self.node.id,
'content': strip_xss_tags(content)})
if topic:
category = 'edit'
pre_node_id = topic.node_id
pre_title = topic.title
pre_content = topic.content
cur_node_id = data.get('node_id')
cur_title = data.get('title')
cur_content = data.get('content')
changed = 0
if pre_node_id != cur_node_id:
topic.node.topic_count -= 1
self.node.topic_count += 1
diff_content = '主题节点从' + '<a class="node" href="' +\
topic.node.url + '">' + topic.node.name +\
'</a>移动到<a class="node" href="' + self.node.url + '">' +\
self.node.name + '</a>'
changed = 1
if pre_title != cur_title or pre_content != cur_content:
content1 = '<p><h2>' + pre_title + '</h2></p>' + pre_content
content2 = '<p><h2>' + cur_title + '</h2></p>' + cur_content
diff_content = ghdiff.diff(content1, content2, css=None)
changed = 1
if changed == 1:
topic.node_id = cur_node_id
topic.title = cur_title
topic.content = cur_content
History(user_id=user.id, content=diff_content,
topic_id=topic.id).save()
else:
return topic
else:
category = 'create'
topic = Topic(**data)
return topic.save(category=category)
示例9: edit
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def edit(request, key):
blocks = {}
node = Node.get(key)
add = BlockAddForm(request.form, prefix='_add')
if node.type == FOLDER:
form = FolderForm(request.form, obj=node)
else:
form = PageForm(request.form, obj=node)
form.layout.choices = Layout.get_key_to_path()
for block in node.blocks:
blocks[block.name] = BlockForm(request.form, obj=block, prefix='__block:%s__' % block.name)
if request.method == 'POST':
blocks = dict(blocks)
for key in request.form:
if key.startswith('__block:'):
name = key.split('__',2)[1][6:]
if name not in blocks:
blocks[name] = BlockForm(request.form, prefix='__block:%s__' % name)
if add.validate() and add.add.data is True:
blocks[add.name.data] = BlockForm(prefix='__block:%s__' % add.name.data)
add = BlockAddForm(prefix='_add')
elif form.validate() and all([blocks[block].validate() for block in blocks]):
layout_val = None
if node.type == PAGE:
layout_val = form.layout.data
keys = blocks.keys()
if form.layout.data == 'Layout:None':
form.layout.data = None
else:
form.layout.data = Layout.get(form.layout.data.split(':',1)[1])
for block in node.blocks:
blocks[block.name].auto_populate(block)
keys.remove(block.name)
block.put()
for block in keys:
block = Block(node=node, name=block, body=blocks[block].body.data)
block.put()
form.auto_populate(node)
node.update()
# invalidate cache
node.invalidate_cache()
if form.save.data is True:
return redirect(url_for('nut:pages/list_pages'), 301)
if layout_val is not None:
form.layout.data = layout_val
return render_template('app:pages/form.html', form=form, add=add, blocks=blocks.items(), mode='edit', node=node)
示例10: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def post(self, node_id):
if not self.has_permission:
return
if not self.current_user.is_admin:
return self.redirect_next_url()
category = self.get_argument('category', None)
node = Node.get(id=node_id)
if not node:
return self.redirect_next_url()
if self.request.files == {} or 'myimage' not in self.request.files:
self.write({"status": "error",
"message": "对不起,请选择图片"})
return
image_type_list = ['image/gif', 'image/jpeg', 'image/pjpeg',
'image/png', 'image/bmp', 'image/x-png']
icon_type_list = ['image/gif', 'image/jpeg', 'image/pjpeg',
'image/png', 'image/bmp', 'image/x-png', 'image/ico .ico',
'image/x-icon']
send_file = self.request.files['myimage'][0]
if category != 'icon' and send_file['content_type'] not in image_type_list:
self.write({"status": "error",
"message": "对不起,仅支持 jpg, jpeg, bmp, gif, png\
格式的图片"})
return
if category == 'icon' and send_file['content_type'] not in icon_type_list:
self.write({"status": "error",
"message": "对不起,仅支持 ico, jpg, jpeg, bmp, gif, png\
格式的图片"})
return
if len(send_file['body']) > 6 * 1024 * 1024:
self.write({"status": "error",
"message": "对不起,请上传6M以下的图片"})
return
tmp_file = tempfile.NamedTemporaryFile(delete=True)
tmp_file.write(send_file['body'])
tmp_file.seek(0)
try:
image_one = Image.open(tmp_file.name)
except IOError, error:
logging.info(error)
logging.info('+' * 30 + '\n')
logging.info(self.request.headers)
tmp_file.close()
self.write({"status": "error",
"message": "对不起,此文件不是图片"})
return
示例11: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def post(self):
node_id = force_int(self.get_argument('node_id', 0), 0)
node = Node.get(id=node_id)
user = self.current_user
form = TopicForm(self.request.arguments)
if form.validate():
topic = form.save(user=user)
topic.put_notifier()
result = {'status': 'success', 'message': '主题创建成功',
'topic_url': topic.url}
if self.is_ajax:
return self.write(result)
self.flash_message(**result)
return self.redirect(topic.url)
if self.is_ajax:
return self.write(form.result)
return self.render("topic/create.html", form=form, node=node)
示例12: save
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def save(self, user, role=None):
data = self.data
try:
parent_name = data.pop('parent_name')
except:
parent_name = None
data.update({'user_id': user.id})
node = Node(**data).save()
if not parent_name:
if not NodeNode.get(parent_id=1, child_id=node.id):
NodeNode(parent_id=1, child_id=node.id).save()
else:
for name in parent_name:
parent = Node.get(name=name)
if parent:
if not NodeNode.get(parent_id=parent.id, child_id=node.id):
NodeNode(parent_id=parent.id, child_id=node.id).save()
return node
示例13: init_node
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def init_node():
from models import Node
if not Node.get(id=1):
Node(name=u'根节点', urlname='root',
description=u'一切的根源').save()
示例14: validate_urlname
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def validate_urlname(self, field):
data = field.data.lower()
node = Node.get(urlname=data)
if node and node != self.node:
raise ValidationError('此节点地址已存在')
示例15: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import get [as 别名]
def post(self):
path = urllib.unquote(self.request.path)
m = parts.search(path)
if m is None:
self.error(404)
return
this_path = m.group(1)
this_page = m.group(3) or 'index'
this_ext = m.group(4) or 'html'
# get section and node
section = Section.all().filter('path =', this_path).get()
node = Node.all().filter('section =', section).get()
if section is None or node is None:
self.error(404)
return
self.request.charset = 'utf8'
# remove the horribleness from comment
if this_page == 'comment' and this_ext == 'html':
# firstly, check the 'faux' field and if something is in there, redirect
faux = self.request.get('faux')
if len(faux) > 0:
logging.info('COMMENT: Spam comment detected (Faux field not empty)')
self.redirect('/')
return
# comment submission for each section
node = Node.get( self.request.get('node') )
name = self.request.get('name')
email = self.request.get('email')
website = self.request.get('website')
comment_text = re.sub('\r', '', self.request.get('comment'));
# if there are more than 4 links (https?://) in the comment, we consider it spam
if spammy_links(comment_text):
logging.info('COMMENT: Spam comment detected (Too many links)')
self.redirect('/')
return
# now create the comment
comment = Comment(
node = node,
name = name,
email = email,
website = website,
comment = comment_text,
)
comment.set_derivatives()
comment.put()
# send a mail to the admin
admin_email = util.config_value('Admin Email')
if mail.is_email_valid(admin_email):
url_post = util.construct_url() + node.section.path + node.name + '.html'
url_mod = util.construct_url() + '/admin/comment/?key=' + str(comment.key()) + ';status='
url_del = util.construct_url() + '/admin/comment/del.html?key='+ str(comment.key())
body = 'From: ' + name + ' <' + email + '>\n'
body = body + 'Site: ' + website + '\n\n'
body = body + comment_text + '\n\n'
body = body + '*** Actions ***\n\n'
body = body + 'ViewPost = ' + url_post + '\n\n'
body = body + 'Approve = ' + url_mod + 'approve\n'
body = body + 'Reject = ' + url_mod + 'reject\n'
body = body + 'Delete = ' + url_del + '\n'
mail.send_mail(admin_email, admin_email, 'New comment on ' + section.path + node.name + '.html', body)
else:
# don't do anything
logging.info('No valid email set, skipping sending admin an email for new comment')
# redirect to the comment page
self.redirect('comment.html?key=' + str(comment.key()))
return
elif this_page == 'message' and this_ext == 'html':
# firstly, check the 'faux' field and if something is in there, redirect
faux = self.request.get('faux')
if len(faux) > 0:
logging.info('MESSAGE: Spam detected, not saving')
self.redirect('/')
return
# message submission for each section
type = self.request.get('type')
subject = self.request.get('subject')
message = self.request.POST.items()
redirect = self.request.get('redirect')
# create the full URL we should be redirecting to
full_redirect = util.construct_redirect( redirect )
# now create the message
msg = Message(
type = type,
subject = subject,
#.........这里部分代码省略.........