本文整理汇总了Python中models.Link类的典型用法代码示例。如果您正苦于以下问题:Python Link类的具体用法?Python Link怎么用?Python Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: submit
def submit(request):
"""
View for submitting a URL
"""
if settings.SHORTENER_REQUIRES_LOGIN and not request.user.is_authenticated():
# TODO redirect to an error page
raise Http404
url = None
link_form = None
if request.GET:
link_form = LinkSubmitForm(request.GET)
elif request.POST:
link_form = LinkSubmitForm(request.POST)
if link_form and link_form.is_valid():
url = link_form.cleaned_data['u']
link = None
try:
link = Link.objects.get(url = url)
except Link.DoesNotExist:
pass
if link == None:
new_link = Link(url = url)
new_link.save()
link = new_link
values = default_values(request)
values['link'] = link
return render_to_response(
'url_shortener_submit_success.html',
values,
context_instance=RequestContext(request))
values = default_values(request, link_form=link_form)
return render_to_response(
'url_shortener_submit_failed.html',
values,
context_instance=RequestContext(request))
开发者ID:oppian,项目名称:oppian,代码行数:35,代码来源:views.py
示例2: copyLink
def copyLink(params):
logging.info('copylink(): Start')
#Get link from GUI
link = params['link_key'].get()
#Create new link
new_link = Link(parent=genLinkParentKey())
#Copy properties of this link to new link
new_link.name = link.name
new_link.description = link.description
new_link.url = link.url
new_link.website = link.website
#new_link.link_category = link.link_category
new_link.parent_folder = params['target_folder_key'] #parent should be the one provided by the user
new_link.date_c = datetime.datetime.now()
new_link.date_m = datetime.datetime.now()
#save new link
new_link.put()
#logging.info('copyLink: '+params['target_folder_key'].get().name)
#increment n_items of new parent folder
params['target_folder_key'].get().n_items += 1
params['target_folder_key'].get().put()
#logging.info('copyLink: '+ str(params['target_folder_key'].get().n_items))
status = 'Success: from copyLink'
return status
开发者ID:netlinks,项目名称:netlinks,代码行数:31,代码来源:linkservices.py
示例3: insert_end
def insert_end(node, decision):
"""Insert DecisionEnd between node and node parents"""
parent_links = node.get_parent_links().exclude(name='default')
decision_end = decision.get_child_end()
# Find parent decision node for every end's parent.
# If the decision node is the one passed,
# change the parent to link to the Decision node's DecisionEnd node.
# Skip embedded decisions and forks along the way.
decision_end_used = False
for parent_link in parent_links:
parent = parent_link.parent.get_full_node()
node_temp = parent
while node_temp and not isinstance(node_temp, Decision):
if isinstance(node_temp, Join):
node_temp = node_temp.get_parent_fork().get_parent()
elif isinstance(node_temp, DecisionEnd):
node_temp = node_temp.get_parent_decision().get_parent()
else:
node_temp = node_temp.get_parent()
if node_temp.id == decision.id and parent.node_type != Decision.node_type:
links = Link.objects.filter(parent=parent).exclude(name__in=['related', 'kill', 'error'])
if len(links) != 1:
raise RuntimeError(_('Cannot import workflows that have decision DAG leaf nodes with multiple children or no children.'))
link = links[0]
link.child = decision_end
link.save()
decision_end_used = True
# Create link between DecisionEnd and terminal node.
if decision_end_used and not Link.objects.filter(name='to', parent=decision_end, child=node).exists():
link = Link(name='to', parent=decision_end, child=node)
link.save()
开发者ID:bugcy013,项目名称:hue,代码行数:35,代码来源:import_workflow.py
示例4: post
def post(self):
url = self.request.get("url")
if url:
URL_RE = re.compile(r"(https|http)")
if not URL_RE.match(url):
url = "http://%s" % url
u = memcache.get(url)
# if url is already cached
if u:
params = {"hash": str(u.hash), "link": str(u.url)}
self.render("url_form.html", **params)
else:
try:
l = Link()
l.seed(url)
memcache.set(url, l)
memcache.set(str(l.hash), l)
params = {"hash": str(l.hash), "link": str(l.url)}
self.render("url_form.html", **params)
except ValueError:
params = {"error": True}
self.render("url_form.html", **params)
else:
params = {"error": True}
self.render("url_form.html", **params)
开发者ID:Roasbeef,项目名称:Simple-Url-Shortener,代码行数:25,代码来源:views.py
示例5: post_link
def post_link():
link = request.values.get('q')
author = request.values.get('author')
key = hashlib.md5(link).hexdigest()
exists = Link.get_by_key_name(key)
try:
if not exists:
link = Link(key_name=key,
link_url=link,
authors=[author])
link.put()
taskqueue.add(url='/_worker/fetch_title', params={ 'url': link.link_url, 'key': key })
else:
if author not in exists.authors:
exists.authors.append(author)
exists.updated_at = datetime.now()
exists.put()
taskqueue.add(url='/_worker/fetch_title', params={ 'url': link, 'key': key })
return jsonify({'result': True})
except:
logging.exception('api call failed')
return jsonify({'result': False})
开发者ID:Kroisse,项目名称:links.langdev.org,代码行数:28,代码来源:apis.py
示例6: add
def add(request): # add a new link
link = Link (
title = request.POST["title"],
desc = request.POST["desc"],
url = request.POST["url"]
)
link.save()
return HttpResponseRedirect("/links")
开发者ID:antsa,项目名称:Django-opas,代码行数:8,代码来源:views.py
示例7: post
def post(self):
url = self.request.get("url")
custom_path = self.request.get("custom_path")
#if custom_path:
# exists = Link.filter("path =", custom_path).get()
# if exists:
# return "path already exists, choose another"
link = Link(url=url, custom_path=custom_path)
link.put()
开发者ID:stephen-soltesz,项目名称:appengine-url-shortener,代码行数:9,代码来源:main.py
示例8: shorten
def shorten(url, title, size):
q = Link.all()
q.filter("url =", url)
urls = q.fetch(1)
if (len(urls) > 0):
return urls[0].short_url()
newLink = Link(url = url, title = title, size = size)
newLink.save()
return newLink.short_url()
开发者ID:,项目名称:,代码行数:9,代码来源:
示例9: test_link_model
def test_link_model(self):
link = Link(id='http://www.github.com/', title='My Github')
Link(id='http://www.bitbucket.com/',
title='My bitbucket')
link_key = link.put()
self.assertEquals(link_key.id(), 'http://www.github.com/')
# Link queries
link = Link.get_by_id('http://www.github.com/')
self.assertEquals(link.title, 'My Github')
开发者ID:geaden,项目名称:geaden_web,代码行数:9,代码来源:tests.py
示例10: decision_helper
def decision_helper(decision):
"""
Iterates through children, waits for ends.
When an end is found, finish the decision.
If the end has more parents than the decision has branches, bubble the end upwards.
"""
# Create decision end if it does not exist.
if not Link.objects.filter(parent=decision, name='related').exists():
end = DecisionEnd(workflow=workflow, node_type=DecisionEnd.node_type)
end.save()
link = Link(name='related', parent=decision, child=end)
link.save()
children = [link.child.get_full_node() for link in decision.get_children_links().exclude(name__in=['error','default'])]
ends = set()
for child in children:
end = helper(child)
if end:
ends.add(end)
# A single end means that we've found a unique end for this decision.
# Multiple ends mean that we've found a bad decision.
if len(ends) > 1:
raise RuntimeError(_('Cannot import workflows that have decisions paths with multiple terminal nodes that converge on a single terminal node.'))
elif len(ends) == 1:
end = ends.pop()
# Branch count will vary with each call if we have multiple decision nodes embedded within decision paths.
# This is because parents are replaced with DecisionEnd nodes.
fan_in_count = len(end.get_parent_links().exclude(name__in=['error','default']))
# IF it covers all branches, then it is an end that perfectly matches this decision.
# ELSE it is an end for a decision path that the current decision node is a part of as well.
# The unhandled case is multiple ends for a single decision that converge on a single end.
# This is not handled in Hue.
fan_out_count = len(decision.get_children_links().exclude(name__in=['error','default']))
if fan_in_count > fan_out_count:
insert_end(end, decision)
return end
elif fan_in_count == fan_out_count:
insert_end(end, decision)
# End node is a decision node.
# This means that there are multiple decision nodes in sequence.
# If both decision nodes are within a single decision path,
# then the end may need to be returned, if found.
if isinstance(end, Decision):
end = decision_helper(end)
if end:
return end
# Can do this because we've replace all its parents with a single DecisionEnd node.
return helper(end)
else:
raise RuntimeError(_('Cannot import workflows that have decisions paths with multiple terminal nodes that converge on a single terminal node.'))
else:
raise RuntimeError(_('Cannot import workflows that have decisions paths that never end.'))
return None
开发者ID:bugcy013,项目名称:hue,代码行数:57,代码来源:import_workflow.py
示例11: key_url
def key_url(key):
l = Link(key=key)
url = l.url
if url:
l.incr_click()
return redirect(l.url)
else:
abort(404)
开发者ID:zubchick,项目名称:toolong,代码行数:9,代码来源:shrt.py
示例12: add
def add(request):
if request.GET.has_key('url') and request.GET.has_key('user') and request.GET.has_key('channel') and request.GET.has_key('title'):
link = Link(url=request.GET['url'], user=request.GET['user'], channel=request.GET['channel'], title=request.GET['title'])
link.save()
#if request.GET['title'] == "Binary Data or File":
# p = subprocess.Popen(['wget', '-P', '/raid/archives/Incoming/sumdumbot/', request.GET['url']])
return HttpResponse('OK')
else:
return HttpResponse('Error')
开发者ID:jeefy,项目名称:sumdumbot-web,代码行数:9,代码来源:views.py
示例13: review
def review(request):
if request.method=='POST':
link=Link.get_by_id(int(request.POST['id']))
link.status=request.POST['action']
link.put()
approved_links=Link.all().filter('status =', 'approved')
submitted_links=Link.all().filter('status =', 'submitted')
return(render_to_response('links/review.html', locals(), context_instance=RequestContext(request)))
开发者ID:Hubble1,项目名称:eventgrinder,代码行数:9,代码来源:views.py
示例14: linkmgnt
def linkmgnt():
perpage = g.config["ADMIN_ITEM_COUNT"]
page = int(request.args.get("page", 1))
linklist = Link.get_page(offset=perpage*(page-1), limit=perpage)
pager = gen_pager(page, Link.count(), perpage, request.url)
return render_template('admin/linkmgnt.html',
linklist=linklist,
admin_url="linkmgnt",
pager=pager
)
开发者ID:minyoad,项目名称:Tyou,代码行数:10,代码来源:admin.py
示例15: redir
def redir(request, encoded):
#Potential shortened link. Decode and check to see if it's in the database. If so, redirect to full url page. If not, error.
toRedirect = Link()
findId = toRedirect.decode(encoded)
try:
check = Link.objects.get(id=findId)
except Link.DoesNotExist:
return HttpResponse("ERROR, YO")
return HttpResponseRedirect(check.longUrl())
开发者ID:arizonat,项目名称:LinkPriv-shortener,代码行数:10,代码来源:views.py
示例16: submit
def submit(request):
#Allow link input to create shortened link.
link_form = LinkSubmitForm(request.POST)
print(request.POST);
if link_form.is_valid():
url = link_form.cleaned_data['submitForm']
#Arg Parse
urlPart = url.partition('?')
args = urlPart[2].split('&')
combinations = []
for i in range(0,len(args)+1):
for perm in itertools.combinations(args,i):
combinations.append(perm)
print combinations
count = 0
#Image Gen
for c in combinations:
urlCombination = urlPart[0]+"?"
for arg in c:
urlCombination = urlCombination + arg +"&"
urlCombination = urlCombination[0:len(urlCombination)-1]
webkit2png.generate_image(urlCombination,
os.path.join(settings.PROJECT_ROOT,
"media/ss_%d.png"%count))
count = count + 1
#Gets the shortened link if this url has been shortened already. If not, it makes a new one.
link = None
try:
link = Link.objects.get(url = url)
except Link.DoesNotExist:
pass
if link == None:
new_link = Link(url = url)
new_link.save()
link = new_link
return render_to_response('results.html',
{"encodedLink": link.shortUrl(),
"perm": simplejson.dumps(combinations)},
context_instance=RequestContext(request))
开发者ID:arizonat,项目名称:LinkPriv-shortener,代码行数:54,代码来源:views.py
示例17: create
def create(request):
"""
Create an link.
"""
content_id = int(request.POST["contentid"])
supporter_id = int(request.POST["supporterid"])
link = Link(content_id=content_id, supporter_id=supporter_id, compromised=False)
link_id = link.put().id()
return HttpResponse("Created an link: %s %s %s" % (content_id, supporter_id, link_id))
开发者ID:andrewhao,项目名称:mailsafe,代码行数:11,代码来源:link.py
示例18: post
def post(self):
json = {}
if not self.current_user:
json = {
'error': 1,
'msg': self._('Access denied')
}
self.write(json)
return
title = self.get_argument('title', None)
url = self.get_argument('url', None)
description = self.get_argument('description', '')
# valid arguments
if not title:
json = {
'error': 1,
'msg': self._('Title field can not be empty')
}
self.write(json)
return
if not url:
json = {
'error': 1,
'msg': self._('URL field can not be empty')
}
self.write(json)
return
# create link
link = Link()
link.title = title
link.url = url
link.description = description
self.db.add(link)
self.db.commit()
# delete cache
keys = ['LinkList', 'SystemStatus']
self.cache.delete_multi(keys)
json = {
'error': 0,
'msg': self._('Successfully created'),
'link': {
'id': link.id,
'title': link.title,
'url': link.url,
'description': link.description
}
}
self.write(json)
开发者ID:messense,项目名称:YaBlog,代码行数:50,代码来源:api.py
示例19: test
def test():
import hashlib
from google.appengine.api import taskqueue
url = 'http://cusee.net/2462861'
key = hashlib.md5(url).hexdigest()
link = Link(key_name=key, authors=['kkung'], link_url=url)
link.put()
taskqueue.add(url='/_worker/fetch_title', params={ 'url': url, 'key': key })
return u'OK', 200
开发者ID:Kroisse,项目名称:links.langdev.org,代码行数:14,代码来源:views.py
示例20: main
def main():
unvisited_links = session.query(Link).\
filter(Link.visited_at == None).all()
if len(unvisited_links) == 0:
print("Nothing to visit right now.")
for link in unvisited_links:
try:
r = requests.get(link)
soup = BeautifulSoup(r.text, 'html.parser')
for site_url in set([o.get('href') for o in soup.find_all('a')]):
if site_url is None:
continue
url = site_url
if not is_url(site_url):
url = urljoin(link.get_domain(), site_url)
print('Found: {}'.format(url))
l = session.query(Link).\
filter(Link.url == url).first()
if l is not None:
continue
l = Link(url=url)
domain = l.get_domain()
domain_in_db = session.query(Domain).\
filter(Domain.url == domain).\
first()
if domain_in_db in None:
print("Found new domain: {}".format(domain))
domain_in_db = Domain(url=domain)
save(domain_in_db)
l.domain = domain_in_db
save(l)
except:
print('Something went wrong.')
finally:
link.visited_at = datetime.now()
save(link)
开发者ID:Martin95056,项目名称:BG-Crawler,代码行数:49,代码来源:crawler.py
注:本文中的models.Link类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论