本文整理汇总了Python中blog.models.Entry.save方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.save方法的具体用法?Python Entry.save怎么用?Python Entry.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Entry
的用法示例。
在下文中一共展示了Entry.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blogger_newPost
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def blogger_newPost(user, appkey, blogid, content, publish):
"""
Blogger doesn't support titles, so we will use the standard trick of
searching for a <title></title> tag and using that for a title. Returns
post id.
"""
authorid = blogid
if not authorid:
authorid = Author.objects.all()[0].id
title, body = blogger_split_content(content)
pub_date = datetime.datetime.now()
entry = Entry(headline = title,
slug = slugify(title),
content = body,
author_id = authorid,
pub_date = pub_date,
status = publish and PUBLISHED or DRAFT,)
entry.save()
# No tagging in this API...at least formally
# setTags(entry, struct)
entry.sites.add(Site.obects.get_current())
return entry.id
示例2: parse
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def parse(self):
url = "https://%s:%[email protected]/v1/posts/recent" % (self.username, self.password)
xmlData = xml_parser.parseString(self.fetch(url))
for node in xmlData.getElementsByTagName('post'):
description = node.getAttribute('description')
url = node.getAttribute('href')
temp = node.getAttribute('time')
temp = temp.split('T')
d = temp[0].split('-')
t = temp[1].split(':')
t[2] = t[2].strip('Z')
date = []
for i in d:
date.append(int(i))
for j in t:
date.append(int(j))
acceptable = datetime(date[0], date[1], date[2], date[3], date[4], date[5])
a = Entry.objects.filter(name=url, date=acceptable)
if(len(a) < 1):
u = User.objects.filter(username=self.user)[0]
entry = Entry(name=url, description=description, date=acceptable, entry_type='delicious', user=u)
entry.save()
示例3: test_create_unpublished
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def test_create_unpublished(self):
user = create_user()
entry = Entry(title="Title Me", body="Hello world", created_user=user)
entry.save()
self.assertEqual(Entry.objects.all().count(), 1)
entry.publish = True
entry.save()
示例4: __create_entry
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def __create_entry(self, lang, author, cat, title, post, date):
entry = Entry(lang=lang, author=author, title=title, post=post,
date=date, mod_date=date, published=True)
entry.save()
entry.cat.add(cat)
print "Created entry : {} | {} | ".format(lang, title)
return entry
示例5: create_entry
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def create_entry(**kwargs):
defaults = {
"title": "Test entry1",
"body": "Entry body",
"keywords": "test, entry",
# 'categories': self.create_category(),
}
defaults.update(kwargs)
entry = Entry(**defaults)
entry.slug = slugify(entry.title)
entry.save()
category = create_category()
entry.categories.add(category)
return entry
示例6: add
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def add(request, secret_key, title, text):
users = User.objects.filter(first_name=secret_key)
ab = {}
if users.count() == 0:
ab['result'] = "Incorrect query"
return HttpResponse("{}".format(json.dumps(ab)))
else:
user = users[0]
pub_date = timezone.now()
post = Entry(title=title, text=text, author=user, pub_date=pub_date)
post.save()
ab = {}
ab['result'] = "New node created"
return HttpResponse("{}".format(json.dumps(ab)))
示例7: init_data
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def init_data(**kwargs):
link=Link(text="dengmin's blog",href="http://www.iyouf.info")
link.save()
default_cate=Category(name=u'未分类',slug='default',desc=u'未分类')
default_cate.save()
entry=Entry(title='Hello World!',content='<b>Hello World, welcome to use youflog! thank you!</a>',tags='youflog')
entry.allow_comment=True
entry.slug='hello-world'
entry.category=default_cate
entry.author_id=1
entry.save(True)
comment=Comment(author='admin',email='[email protected]',weburl='http://iyouf.info',content=u'测试第一条评论')
comment.content_object=entry
comment.save()
示例8: metaWeblog_newPost
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def metaWeblog_newPost(blogid, username, password, struct, publish):
user = User.objects.get(username__exact=username)
if struct.has_key('title') and struct.has_key('description'):
post = Entry(title=struct['title'],content = struct['description'])
post.author=user
if struct.has_key('categories'):
catename = struct['categories'][0]
cate=Category.objects.get(name__exact=catename)
post.category=cate
else:
post.category_id=1
if struct.has_key('mt_keywords'):
post.tags=struct['mt_keywords']
if struct.has_key('wp_slug'):
post.slug=struct['wp_slug']
post.save(True)
return ""
示例9: setUp
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def setUp(self):
author = User(last_name="chocolate", email="[email protected]")
author.save()
call_command('populatedb')
entry_new = Entry(
author=User.objects.get(pk=1),
body='foo',
language=Language.objects.get(pk=5),
title='foo bar',
)
entry_new.save()
entry_old = Entry(
author=User.objects.get(pk=1),
body='test',
language=Language.objects.get(name="French"),
title='Test de langue',
)
entry_old.save()
示例10: quick_post
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def quick_post(request):
title=request.POST.get('title')
content=request.POST.get('content','')
tags=request.POST.get('tags','')
save=request.POST.get('save')
publish=request.POST.get('publish')
if not title and not content:
return HttpResponse(u"文章标题和内容不能为空!")
entry=Entry(title=title,content=content,tags=tags,slug='',allow_comment=True)
entry.author=request.user
entry.category_id=1
if save:
entry.save(False)
html=u"<p>文章已保存. <a href='/admin/editpost/%s'>编辑文章</a></p>"%(str(entry.id))
elif publish:
entry.save(True)
html=u"<p>文章已发布. <a href='%s' target='_blank'>查看文章</a></p>"%(entry.get_absolute_url())
return HttpResponse(html)
示例11: new_post
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def new_post(request):
if not request.user.is_authenticated():
return redirect('login')
if request.method == "POST":
form = PostForm(request.POST, error_class=DivErrorList)
if form.is_valid():
title = request.POST['title']
post = request.POST['post']
p = Entry(author=request.user,
title=title,
post=post,
pub_date=timezone.now())
p.save()
entry_id = p.pk
return redirect('detail', entry_id=entry_id)
else:
form = PostForm
dates = Entry.get_dates()
context = {'dates': dates, 'form': form}
return render(request, 'blog/new_post.html', context)
示例12: createpost
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def createpost(request):
args={}
args.update(csrf(request))
if request.POST:
title = request.POST.get('title', '')
text = request.POST.get('text', '')
user = auth.get_user(request)
if not user.is_authenticated():
args['createpost_error'] = "Login before creating posts!"
return render_to_response("blog/createpost.html", args)
elif title is None:
args['createpost_error'] = "Write some title!"
return render_to_response("blog/createpost.html", args)
elif not text:
args['createpost_error'] = "Write some text!"
return render_to_response("blog/createpost.html", args)
else:
pub_date = timezone.now()
post = Entry(title=title, text=text, author=user, pub_date=pub_date)
post.save()
return redirect('/');
else:
return render_to_response("blog/createpost.html", args)
示例13: load
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def load():
"""
Load a series of markdown and yaml files from content folders. YAML is for
blogpost metadata and markdown files are blogpost content.
"""
# Clearout the old db
# FIXME: this should check itself before it deletes things.
old_entries = Entry.objects.all()
old_entries.delete()
# Recreate the content of the db
years = ['02011'] # only one year of content for now, append later
# TODO: use this in a blog-wide yaml config file, can generate 1996-2010(c)
for year in years:
folder = './content/blog/' + year + '/'
files = set([os.path.splitext(f)[0] for f in os.listdir(folder)])
for file in files:
meta_file = open(folder + file + '.yaml', 'r')
metadata = yaml.load(meta_file)
meta_file.close()
post_file = open(folder + file + '.md', 'r')
post = post_file.read()
post_file.close()
e = Entry()
# TODO: implement django-tagging here
# Metadata
e.title = metadata['title']
e.slug = slugify(metadata['title'])
e.pub_date = metadata['pub_date']
e.published = metadata['published']
# Post
e.body = post
e.snip = post[:139] # 140 characters of fun
e.save()
pass
示例14: metaWeblog_newPost
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def metaWeblog_newPost(user, blogid, struct, publish):
# Check if we are getting a userid in the post,
# if we are not, default to the first author entered...
authorid = blogid
if not authorid:
authorid = Author.objects.all()[0].id
pub_date = struct.get('dateCreated', None)
if not pub_date:
pub_date = datetime.datetime.now()
else:
# ISO 8601 time parsing is one of those things that sucks, and Python
# doesn't have any decent way of handling the variety of formats
# it may come in. So, we make an effort to parse the most common
# form, and then default to today if we can't figure it out correctly.
try:
pub_date = datetime.datetime.strptime( str(pub_date), "%Y%m%dT%H:%M:%S" )
except ValueError:
pub_date = datetime.datetime.now()
content = struct['description']
# todo - parse out technorati tags
# Handle Movable Type extensions
# We ignore pings, tb_ping_urls, keywords, and convert_breaks
# If we get text_more we just append it to the content
comments = struct.get('mt_allow_comments', None)
if comments is not None:
comments = bool(comments)
else:
# User default value
comments = True
abstract = struct.get('mt_excerpt', None)
if abstract is None:
abstract = ''
footer = struct.get('mt_text_more', None)
if footer is not None:
content += footer
entry = Entry(headline = struct['title'],
slug = slugify(struct['title']),
content = content,
author_id = authorid,
pub_date = pub_date,
comments = comments,
abstract = abstract,
status = publish and PUBLISHED or DRAFT,)
# entry.prepopulate()
entry.save()
# Add any tags needed
setTags(entry, struct.get('categories', None))
# Add site by using blogid
entry.sites.add(Site.objects.get_current())
return entry.id
示例15: POST
# 需要导入模块: from blog.models import Entry [as 别名]
# 或者: from blog.models.Entry import save [as 别名]
def POST(self,slug='post'):
action=self.param("action")
title=self.param("post_title")
content=self.param('content')
tags=self.param("tags")
cats=self.request.get_all('cats')
key=self.param('key')
if self.param('publish')!='':
published=True
elif self.param('unpublish')!='':
published=False
else:
published=self.param('published')=='True'
allow_comment=self.parambool('allow_comment')
allow_trackback=self.parambool('allow_trackback')
entry_slug=self.param('slug')
entry_parent=self.paramint('entry_parent')
menu_order=self.paramint('menu_order')
entry_excerpt=self.param('excerpt').replace('\n','<br />')
password=self.param('password')
sticky=self.parambool('sticky')
is_external_page=self.parambool('is_external_page')
target=self.param('target')
external_page_address=self.param('external_page_address')
def mapit(cat):
return {'name':cat.name,'slug':cat.slug,'select':cat.slug in cats}
vals={'action':action,'postback':True,'cats':Category.all(),'entrytype':slug,
'cats':map(mapit,Category.all()),
'entry':{ 'title':title,'content':content,'strtags':tags,'key':key,'published':published,
'allow_comment':allow_comment,
'allow_trackback':allow_trackback,
'slug':entry_slug,
'entry_parent':entry_parent,
'excerpt':entry_excerpt,
'menu_order':menu_order,
'is_external_page':is_external_page,
'target':target,
'external_page_address':external_page_address,
'password':password,
'sticky':sticky}
}
if not (title and (content or (is_external_page and external_page_address))):
vals.update({'result':False, 'msg':_('Please input title and content.')})
self.render2('views/admin/entry.html',vals)
else:
if action=='add':
entry= Entry(title=title,content=content)
entry.settags(tags)
entry.entrytype=slug
entry.slug=entry_slug.replace(" ","-")
entry.entry_parent=entry_parent
entry.menu_order=menu_order
entry.excerpt=entry_excerpt
entry.is_external_page=is_external_page
entry.target=target
entry.external_page_address=external_page_address
newcates=[]
entry.allow_comment=allow_comment
entry.allow_trackback=allow_trackback
entry.author=self.author.user
entry.author_name=self.author.dispname
entry.password=password
entry.sticky=sticky
if cats:
for cate in cats:
c=Category.all().filter('slug =',cate)
if c:
newcates.append(c[0].key())
entry.categorie_keys=newcates;
entry.save(published)
if published:
smsg=_('Saved ok. <a href="/blog/%(link)s" target="_blank">View it now!</a>')
else:
smsg=_('Saved ok.')
vals.update({'action':'edit','result':True,'msg':smsg%{'link':str(entry.link)},'entry':entry})
self.render2('views/admin/entry.html',vals)
if published and entry.allow_trackback and self.blog.allow_pingback:
try:
autoPingback(str(entry.fullurl),HTML=content)
except:
pass
elif action=='edit':
#try:
if 1:
entry=Entry.get(key)
entry.title=title
entry.content=content
entry.slug=entry_slug.replace(' ','-')
entry.entry_parent=entry_parent
entry.menu_order=menu_order
entry.excerpt=entry_excerpt
entry.is_external_page=is_external_page
#.........这里部分代码省略.........