本文整理汇总了Python中model.Link类的典型用法代码示例。如果您正苦于以下问题:Python Link类的具体用法?Python Link怎么用?Python Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
t_values = {}
current_link_id = self.request.POST['current_link_id']
link_title = self.request.POST['link_title']
link_target = self.request.POST['link_target']
link_sequence = self.request.POST['link_sequence']
logging.info("LinkManager post: current_link_id = %s, link_title = %s, link_target = %s, link_sequence = %s" % (current_link_id, link_title, 'link_target', 'link_sequence'))
if current_link_id:
# edit existed link
link = Link.get_by_id(long(current_link_id))
link.title = link_title
link.target = link_target
link.sequence = long(link_sequence)
link.put()
t_values['alert_message'] = "link %s has been updated" % (link.title)
else:
# create new link
link = Link(title=link_title, target=link_target, sequence=long(link_sequence))
link.put()
t_values['alert_message'] = "link %s has been added" % (link.title)
# find all links
links = Link.all().order("-date")
t_values["links"] = links
return self.response.out.write(render_template("links.html", t_values, "", True))
示例2: post
def post(self, secret=""):
data = (self.get_argument("data", ""),)
if id and data and secret:
if secret == getAttr("MOVE_SECRET"):
Link.set_link(encode_special_txt(data[0]))
return self.write("1")
return self.write("Fail")
示例3: post
def post(self):
action = self.param('action')
name,url = (self.request.get(item) for item in ('linkName', 'linkURL'))
if(action == 'edit'):
key = self.param('id')
link = Link.get_by_id(int(key))
link.linkName = name
link.linkURL = url
else:
link = Link(linkName=name,linkURL=url)
link.put()
self.redirect('/admin/links')
return
示例4: addNewLink
def addNewLink(originalLink):
session = scoped_session(SessionFactory)
link = Link(originalLink)
session.add(link)
session.flush()
link.shortLink = makeMiniature(int(link.id))
session.commit()
session.remove()
result = {
'request_id': link.id,
'short_url': request.url_root.encode() + link.shortLink
}
return 201, result
示例5: get
def get(self):
link = Link(title="linkx1", target="http://baidu.com", sequence=9)
link.put()
link = Link(title="linkx2", target="http://baidu.com", sequence=9)
link.put()
link = Link(title="linkx3", target="http://baidu.com", sequence=9)
link.put()
return self.response.out.write(render_template("index.html", {}, "basic", False))
示例6: get
def get(self, name = ''):
objs = Category.get_cat_page_posts(name, 1)
catobj = Category.get_cat_by_name(name)
if catobj:
pass
else:
self.redirect(BASE_URL)
return
allpost = catobj.id_num
allpage = allpost/EACH_PAGE_POST_NUM
if allpost%EACH_PAGE_POST_NUM:
allpage += 1
output = self.render('index.html', {
'title': "%s - %s"%( catobj.name, getAttr('SITE_TITLE')),
'keywords':catobj.name,
'description':getAttr('SITE_DECR'),
'objs': objs,
'cats': Category.get_all_cat_name(),
'tags': Tag.get_hot_tag_name(),
'archives': Archive.get_all_archive_name(),
'page': 1,
'allpage': allpage,
'listtype': 'cat',
'name': name,
'namemd5': md5(name.encode('utf-8')).hexdigest(),
'comments': Comment.get_recent_comments(),
'links':Link.get_all_links(),
'isauthor':self.isAuthor(),
'Totalblog':get_count('Totalblog',NUM_SHARDS,0),
},layout='_layout.html')
self.write(output)
return output
示例7: update_basic_info
def update_basic_info(
update_categories=False,
update_tags=False,
update_links=False,
update_comments=False,
update_archives=False,
update_pages=False):
from model import Entry,Archive,Comment,Category,Tag,Link
basic_info = ObjCache.get(is_basicinfo=True)
if basic_info is not None:
info = ObjCache.get_cache_value(basic_info.cache_key)
if update_pages:
info['menu_pages'] = Entry.all().filter('entrytype =','page')\
.filter('published =',True)\
.filter('entry_parent =',0)\
.order('menu_order').fetch(limit=1000)
if update_archives:
info['archives'] = Archive.all().order('-year').order('-month').fetch(12)
if update_comments:
info['recent_comments'] = Comment.all().order('-date').fetch(5)
if update_links:
info['blogroll'] = Link.all().filter('linktype =','blogroll').fetch(limit=1000)
if update_tags:
info['alltags'] = Tag.all().order('-tagcount').fetch(limit=100)
if update_categories:
info['categories'] = Category.all().fetch(limit=1000)
logging.debug('basic_info updated')
basic_info.update(info)
示例8: get
def get(self, direction = 'next', page = '2', base_id = '1'):
if page == '1':
self.redirect(BASE_URL)
return
objs = Article.get_page_posts(direction, page, base_id)
if objs:
if direction == 'prev':
objs.reverse()
fromid = objs[0].id
endid = objs[-1].id
else:
fromid = endid = ''
allpost = Article.count_all_post()
allpage = allpost/EACH_PAGE_POST_NUM
if allpost%EACH_PAGE_POST_NUM:
allpage += 1
output = self.render('index.html', {
'title': "%s - %s | Part %s"%(SITE_TITLE,SITE_SUB_TITLE, page),
'keywords':KEYWORDS,
'description':SITE_DECR,
'objs': objs,
'cats': Category.get_all_cat_name(),
'tags': Tag.get_hot_tag_name(),
'page': int(page),
'allpage': allpage,
'listtype': 'index',
'fromid': fromid,
'endid': endid,
'comments': Comment.get_recent_comments(),
'links':Link.get_all_links(),
},layout='_layout.html')
self.write(output)
return output
示例9: delete_link
def delete_link(cls, id):
link = LinkModel.get_by_id(id)
if link:
link.key.delete()
linkDoc = cls.getDoc(id)
if linkDoc:
cls.removeDocById(id)
示例10: get
def get(self):
action = self.param('action')
values = {'action':action}
if(action == 'edit'):
key = self.param('id')
link = Link.get_by_id(int(key))
values.update({'link':link})
self.generateBasePage('manage/link.html', values)
return
示例11: post
def post(self):
act = self.get_argument("act", "")
id = self.get_argument("id", "")
name = self.get_argument("name", "")
sort = self.get_argument("sort", "0")
url = self.get_argument("url", "")
if name and url:
params = {"id": id, "name": name, "url": url, "displayorder": sort}
if act == "add":
Link.add_new_link(params)
if act == "edit":
Link.update_link_edit(params)
clear_cache_by_pathlist(["/"])
self.redirect("%s/admin/links" % (BASE_URL))
return
示例12: post
def post(self):
act = self.get_argument("act",'')
id = self.get_argument("id",'')
name = self.get_argument("name",'')
sort = self.get_argument("sort",'0')
url = self.get_argument("url",'')
if name and url:
params = {'id': id, 'name': name, 'url': url, 'displayorder': sort}
if act == 'add':
Link.add_new_link(params)
if act == 'edit':
Link.update_link_edit(params)
clear_cache_by_pathlist(['/'])
self.redirect('%s/admin/links'% (BASE_URL))
return
示例13: save_link
def save_link(cls, title, url, body="", tags=[], clicks=0, unread=True):
url = norm(url)
id = mmh3.hash(url)
key = ndb.Key(LinkModel, id)
domain = urlparse(url).netloc
if len(domain)>4 and domain.startswith('www.'):
domain = domain[4:]
link = LinkModel( key = key,
title = title,
url = url,
domain = domain,
body = body,
tags = tags,
clicks = clicks,
unread = unread )
link.put()
id = str(link.id)
doc = cls._buildDoc(id, title, body, domain, tags)
cls.add(doc)
return cls(doc, link)
示例14: get
def get(self):
act = self.get_argument("act",'')
id = self.get_argument("id",'')
obj = None
if act == 'del':
if id:
Link.del_link_by_id(id)
clear_cache_by_pathlist(['/'])
self.redirect('%s/admin/links'% (BASE_URL))
return
elif act == 'edit':
if id:
obj = Link.get_link_by_id(id)
clear_cache_by_pathlist(['/'])
self.echo('admin_link.html', {
'title': "管理友情链接",
'objs': Link.get_all_links(),
'obj': obj,
},layout='_layout_admin.html')
示例15: migrate
def migrate():
LinkDoc.deleteAllInIndex()
q = Link.query()
links = q.fetch(65535)
for link in links:
title = link.title
url = link.url
tags = link.tags
body = link.body
link.key.delete()
LinkDoc.save_link(title, url, body, tags)