本文整理汇总了Python中models.Article.put方法的典型用法代码示例。如果您正苦于以下问题:Python Article.put方法的具体用法?Python Article.put怎么用?Python Article.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.put方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def post(self):
d = json.loads(self.request.body)
if d['secret'] == '16jutges16':
if 'key' in d and len(d['key']) > 10: #Keys are looong.
article = ndb.Key(urlsafe = d['key']).get()
logging.info('Modifying entry {}'.format(d['key']))
else:
article = Article()
article.slug = d['slug']
article.title = d['title']
article.text = d['text']
if 'when' in d:
# Matches isoformat into datetime object. Found in stackoverflow
article.when = datetime.datetime(
*map(int, re.split('[^\d]', d['when'])[:-1])
)
else:
article.when = datetime.datetime.now()
try:
article.keywords = string.split(d['keywords'])
except AttributeError:
article.keywords = d['keywords']
article.put()
示例2: parseAndStoreDoc
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def parseAndStoreDoc(self):
for e in self.doc.entries:
title = jinja2.Markup(e.title).unescape()
description = jinja2.Markup(e.description).unescape()
link = e.links[0]["href"]
imgLink = WSJ.wsjLogo
srcName = self.srcName
labelName = self.srcName.split("_")[1]
article = Article(title=title, description=description, imgLink=imgLink, link=link, srcName=srcName, labelName=labelName)
article.put()
logging.info("Storing data from %s" %srcName)
示例3: getArticles
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def getArticles():
articles = Article.query()
if articles.count() == 0:
hello = Article()
hello.title = "Hello World"
hello.content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consequuntur, voluptatum. Provident accusamus sit, commodi corrupti illo, veniam possimus minima rerum itaque. Magni, beatae, facere."
hello.put()
bye = Article()
bye.title = "Bye World"
bye.content = "Iraqi PM Nouri Maliki steps aside, ending political deadlock in Baghdad as the government struggles against insurgents in the north."
bye.put()
del hello, bye
articles = Article.query()
return serialize(list(articles.order(Article.date).fetch(10)))
示例4: create_article
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def create_article(request):
articles = Article.all()
if request.method == "POST":
form = ArticleForm(request.POST)
if form.is_valid():
article = Article(title=form.cleaned_data['title'],
body=form.cleaned_data['body'])
article.put()
messages.success(request, 'Article created successful')
return redirect('create_article')
return render_to_response('create_article.html', dict(articles=articles))
示例5: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def post(self):
article = Article(title=self.request.POST['article-title'], content=self.request.POST['article-content'])
article_key = article.put()
# Invalidate the article list in memcache, It will get rebuilt next time the front page is loaded
memcache.delete("articles_list")
return self.redirect('/article/%d' % article_key.id(), body="Thanks for your submission!")
示例6: get
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def get(self):
path = self.request.path.replace('citeulike/', '')
url = 'http://www.citeulike.org' + path
socket = urllib.urlopen(url)
# Build template
template = Template(open('views/page.html').read())
attrs = citeulike.page_metadata(socket.read(), url)
attrs['views'] = Article.all().filter("id =", self.request.path).count()
s = template.render_unicode(attributes=attrs)
# Render the page
self.response.out.write(template.render_unicode(attributes=attrs))
# Record that this article has been viewed
article = Article(id=self.request.path, last_viewed=datetime.now())
article.put()
示例7: upload_product
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def upload_product():
form = ProductUploadForm(request.form)
if request.method == 'POST':
picture_count = 0
file1 = request.files["picture1"] # request.files is a dictionary with the name matching
# the input name
# only one picture is required the others can be skipped
file2 = request.files["picture2"]
file3 = request.files["picture3"]
keywords = request.form["keywords"]
product_name = request.form["product_name"]
# email is temporary now. Later it will be replaced with open id or other method
#condition = request.form["condition"]
#return "%s" % (request.form.keys())
if file1 and allowed_file(file1.filename):
filename1 = secure_filename(file1.filename)
# switching to Google Datastore model - previous way used to store files in server
article = Article(product_name=product_name, keywords = keywords, condition="needs fixing")
image1 = file1.getvalue()
#imagerz1 = images.resize(image1, 1024, 768) # only on production
imagerz1 = image1
article.picture1 = db.Blob(imagerz1)
picture_count += 1
if file2 and allowed_file(file2.filename):
image2 = file2.getvalue()
#imagerz2 = images.resize(image2, 1024, 768) # only on production
imagerz2 = image2
article.picture2 = db.Blob(imagerz2)
picture_count += 1
if file3 and allowed_file(file3.filename):
image3 = file3.getvalue()
#imagerz3 = images.resize(image3, 1024, 768) # only on production
imagerz3 = image3
article.picture3 = db.Blob(imagerz3)
picture_count += 1
article.picture_count = picture_count
article.put()
#return "this are the values %s" % str(file_.keys())
return redirect(url_for('buy'))
#return render_template('show.html', filename=product_name)
return render_template('upload_flask.html', form = form)
示例8: submit
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def submit(request):
context = RequestContext(request)
if request.method == 'POST':
article_form = ArticleForm(request.POST)
if article_form.is_valid():
title = article_form.cleaned_data['title']
body = article_form.cleaned_data['body']
is_published = article_form.cleaned_data['is_published']
article = Article(title=title, body=body, is_published=is_published)
article.put()
return redirect('/')
else:
article_form = ArticleForm()
context['form'] = article_form
return render_to_response("submit.html", context)
示例9: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def post(self):
from markdown2 import markdown
title = self.request.get('title')
content = self.request.get('content')
slug_title = self.request.get('slug_title')
section_type = self.request.get('section_type')
content_html = markdown(content)
#user = users.get_current_user()
article = Article()
article.title = title
article.slug_title = slug_title
article.content = content
article.section_type = section_type
#article.author = user
article.content_html = content_html
article.is_draft = True
article.put()
self.response.out.write(article.to_json('title', 'section_type', 'is_draft', 'is_deleted', 'is_active', 'is_starred'))
示例10: process_links
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import put [as 别名]
def process_links(company):
links = linkz(company.ticker,company.exchange)
# logging.debug("google links: %s",links)
yahoo_links = yahoo_linkz(company.ticker)
# logging.debug("yahoo links: %s",yahoo_links)
old_titles = company.titles
# titles = []
if links != None:
# for [title,link] in links:
# titles.append(title)
# this could be done with a if title not in old_titles check, to avoid 2 loops through the same list: - see 'if title in titles' below
# titles = [title for title in titles if title not in old_titles]
new_titles = []
# if titles == []:
# # company.finished_scraping = True # denne slaar inn for tidlig, siden den kommer foer alle artiklene er tatt
# # company.put()
# DU ER HER - this is probably why nothing is stored:
# denne burde returnere article keys, siden mekanismen er at titles gradvis tømmes, og er tom når man er ferdig:
# return None
# link_ctr = 1
article_keys = []
# scrape_ctr = 0
for [title, link] in links:
# if link_ctr > 100: # sanity check. there should normally not be more articles than this per day.
# return article_keys
#break # from this links loop
#this is where you should do if titles not in old_titles instead:
if title not in old_titles:
# link_ctr += 1
if link != None and link != "":
html = fetch(link)
if html != None:
article = Article()
article.title = title
# logging.debug("title: %s", title)
# titles.remove(title) # when finished, titles = []
article.html = html
article.url = link
article.company = company
# article.clean = False
article.put()
# scrape_ctr += 1
article_keys.append(article.key())
new_titles.append(title)
new_titles = old_titles + new_titles
company.titles = new_titles #this list should be shortened every now and then - not if it's used for display!
company.put()
# logging.debug("scraped %s articles", scrape_ctr)
return article_keys
else:
return None