本文整理汇总了Python中models.Entry类的典型用法代码示例。如果您正苦于以下问题:Python Entry类的具体用法?Python Entry怎么用?Python Entry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Entry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entries
def entries(request):
queryset = Entry.objects.order_by('-publication_date')[:5]
logged_in = False
if request.session.get('logged_in'):
logged_in = True
if request.method == 'POST':
form = EntryForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
author = User.objects.get(id=request.session.get('user'))
text = form.cleaned_data['text']
new_entry = Entry(text=text, title=title, author=author)
new_entry.save()
form = EntryForm()
else:
form = EntryForm()
else:
form = None
logged_in = False
e_dict = archive_dict()
return render(request, 'entry_list.html', {
'form': form,
'list_of_entries': queryset,
'logged_in': logged_in,
'e_dict': e_dict},
)
示例2: post
def post(self):
key = self.get_argument("key", None)
if key:
entry = Entry.get(key)
entry.title = self.get_argument("title")
entry.markdown = self.get_argument("markdown")
entry.html = markdown.markdown(self.get_argument("markdown"))
else:
title = self.get_argument("title")
slug = unicodedata.normalize("NFKD", title).encode(
"ascii", "ignore")
slug = re.sub(r"[^\w]+", " ", slug)
slug = "-".join(slug.lower().strip().split())
if not slug: slug = "entry"
while True:
existing = db.Query(Entry).filter("slug =", slug).get()
if not existing or str(existing.key()) == key:
break
slug += "-2"
entry = Entry(
author=self.current_user,
title=title,
slug=slug,
markdown=self.get_argument("markdown"),
html=markdown.markdown(self.get_argument("markdown")),
)
entry.put()
self.redirect("/entry/" + entry.slug)
示例3: get
def get(self):
entry_id = self.request.get('entry_id')
if entry_id:
try:
entry_id = int(entry_id)
except:
self.response.set_status(400)
return
entry = Entry.get_by_id(entry_id)
if not entry:
self.response.set_status(404)
return
self.send_json(entry.to_dict())
return
count = self.request.get('count')
page = self.request.get('page')
try:
count = int(count) if count else 20
page = int(page) if page else 0
except:
self.response.set_status(400)
return
entries = Entry.get_latest(count, page)
self.send_json([e.to_dict() for e in entries])
示例4: feed_push_update
def feed_push_update(feed_key):
feed = ndb.Key(urlsafe=feed_key).get()
if not feed:
raise ndb.Return(("No feed", 404))
data = request.stream.read()
if feed.hub_secret:
server_signature = request.headers.get('X-Hub-Signature', None)
signature = hmac.new(feed.hub_secret, data).hexdigest()
if server_signature != signature:
logger.warn('Got PuSH subscribe POST for feed key=%s w/o valid signature: sent=%s != expected=%s', feed_key,
server_signature, signature)
raise ndb.Return('')
logger.info('Got PuSH body: %s', data)
logger.info('Got PuSH headers: %s', request.headers)
parsed_feed = feedparser.parse(data)
new_guids, old_guids = yield Entry.process_parsed_feed(parsed_feed, feed, overflow=False)
yield Entry.publish_for_feed(feed, skip_queue=False)
raise ndb.Return('')
示例5: edit
def edit(slug):
if session.get('logged_in'):
entry = Entry.get_entry(slug, public=False)
else:
entry = Entry.get_entry(slug, public=True)
if entry is None:
return not_found(404)
if request.method == 'POST':
if request.form.get('delete'):
entry.delete()
flash('Post supprime', 'danger')
return redirect(url_for('news'))
if request.form.get('title') and request.form.get('content'):
entry.title = request.form['title']
entry.content = request.form['content']
entry.published = request.form.get('published') or False
entry.save()
flash('Entry saved successfully.', 'success')
if entry.published:
return redirect(url_for('detail', slug=entry.slug))
else:
return redirect(url_for('edit', slug=entry.slug))
else:
flash('Title and Content are required.', 'danger')
return render_template('edit.html', entry=entry)
示例6: detail
def detail(slug):
if session.get('logged_in'):
query = Entry.select()
else:
query = Entry.public()
entry = get_object_or_404(query, Entry.slug == slug)
return render_template('detail.html', entry=entry)
示例7: get
def get(self):
feed_id, feed_url = self.request.get('feed_id'), \
self.request.get('feed_url')
url_result = urllib2.urlopen(feed_url)
feed_result = fd.parse(url_result)
if feed_result.bozo == 1:
logging.error('fetch error, id: %s, url: %s, error: %s',
feed_id, feed_url, feed_result.bozo_exception)
return
feed_update_time = feed_result.get('updated', datetime.utcnow)
has_update = True
f = Feed.get_by_id(int(feed_id))
if f.is_allow_fetch(feed_update_time):
for entry in feed_result.entries:
if entry.published_parsed <= f.lastedPublishedTime:
logging.info('no updated, id: %s, url: %s', feed_id,
feed_url)
has_update = False
break
e = Entry(title = entry.title,
url = entry.link,
author = entry.author,
content = entry.content),
publishedTime = entry.published_parsed)
e.put()
logging.debug('fetch entry, url: %s', entry.link)
示例8: generateFeedEntry
def generateFeedEntry(urlContent,feed):
encodeType = feed['encoding']
urlContent = urlContent.decode(encodeType).encode('utf-8')
global_pattern = re.compile(feed['global_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M)
item_pattern = re.compile(feed['item_search_pattern'].replace('{%}','(.*?)').replace('{*}','.*?'),re.I|re.S|re.M)
sub_pattern = re.compile(r'{%(.*?)}',re.I|re.S|re.M)
globalMatch = global_pattern.search(urlContent)
globalContent = globalMatch.group()
globalContent = globalContent[0:len(globalContent)/4]
itemList = item_pattern.findall(globalContent)
print len(itemList)
for i in xrange(len(itemList)-1,-1,-1):
item = itemList[i]
link = feed['item_link']
title = feed['item_title']
content = feed['item_content']
link = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),link)
content = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),content)
title = sub_pattern.sub(lambda m: str(item[int(m.group(1))-1]),title)
result = Entry.objects.filter(title=title)
if len(result) == 0:
entry = Entry(title=title,link=link,content=content,feedid=feed['id'])
entry.save()
if feed['mail_address']!='':
send_mail(feed['mail_address'], title, link,
("smtp.163.com", 25, "[email protected]", "1234qwer", False))
pass
pass
pass
示例9: post
def post(self):
title = self.get_argument("title", default=None)
if title is None or len(title) == 0:
self.view("admin/article-new.html", menuIndex=1, error=u"请输入标题")
return
email = self.get_current_user()
user = User.gql("WHERE email = :1", email).get()
source = self.get_argument("cleanSource", default=" ")
html = self.get_argument("content", default=" ")
slug = " "
if source != " ":
slug = source.replace("\r\n", " ").replace("\t", " ")[0:200]
date = datetime.datetime.now() + datetime.timedelta(hours=8)
entry = Entry(author=user.key(),
slug=slug,
title=title,
html=html,
body_source=source,
published=date,
updated=date)
try:
entry.put()
self.dispatch(msg=u"创建成功", to=u"文章列表页", toUrl="/admin/article", seconds=2)
except:
self.view("admin/article-new.html", menuIndex=1, error=u"创建失败")
示例10: syncWeibo
def syncWeibo(request):
WBLogin = weiboLogin.weiboLogin()
if WBLogin.login('[email protected]','1234qwer')==1:
urlContent = urllib2.urlopen('http://game.weibo.com/club/forum-315-1').read()
soup = BeautifulSoup(urlContent)
ul = soup.find('ul',{'class':'top_topics'})
lis = ul.findAll('li',{'class':''})
for li in lis:
item = {
'user':li.find('div',{'class':'col1'}).find('img')['alt'],
'link':li.find('div',{'class':'no_rep_line'}).findAll('a')[1]['href'],
'tag':li.find('a',{'class':'navy_tag'}).string,
'title':li.find('div',{'class':'no_rep_line'}).findAll('a')[1].string,
'time':li.find('div',{'class':'col2'}).find('span').string
}
title = "[%s][%s]%s%s"%(item['time'],item['user'],item['tag'],item['title'])
link = item['link']
result = Entry.objects.filter(title=title)
if len(result) == 0:
entry = Entry(title=title,link=link,content='',feedid=0)
entry.save()
send_mail("[email protected]", title, link,
("smtp.163.com", 25, "[email protected]", "1234qwer", False))
pass
pass
return HttpResponse("Login success!")
else:
return HttpResponse("Login error!")
pass
示例11: add_entry
def add_entry(request):
title = json.loads(request.body)['title']
text = json.loads(request.body)['text']
entry = Entry(user=request.user, title=title, text=text)
entry.save()
data = json.dumps(Entry.serialize(entry))
return HttpResponse(data, content_type="application/json")
示例12: post
def post(self, entry_id):
entry = Entry.update_entry(entry_id, self.request2params(self.request))
if entry is None:
entry = Entry.get_entry(entry_id)
return self.redirect('/admin/entry/%d?status=fail' % entry.key.id())
time.sleep(0.1)
return self.redirect('/admin/entry/%d?status=done' % entry.key.id())
示例13: resave_entries
def resave_entries():
""" Fetch and re-save all entries """
entries = db.get_all_entries()
for item in entries:
print("Updating entry {} from user {}".format(item.get('id'), item.get('created_by')))
entry = Entry(id=item.get('id'), created_by=item.get('created_by'))
entry.save()
示例14: test_existing_id
def test_existing_id(self):
client = Client()
entry = Entry(title="Hello World!", body="Test Suite action!")
entry.save()
pk = entry.id
response = client.get('/entry/' + str(pk))
self.assertEqual(response.status_code, 200)
示例15: testUndoMyEntry
def testUndoMyEntry(self):
try:
s = get_object_or_404(ProgramSlot, pk=1)
u = get_object_or_404(User, pk=1)
e = Entry(pk=2, notes="", slot=s, user=u)
e.save()
except Http404, e:
self.fail("Something doesn't exist.")