本文整理汇总了Python中models.Entry.create方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.create方法的具体用法?Python Entry.create怎么用?Python Entry.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_view
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def new_view(parent_id=None):
user = Session.get_user()
if parent_id and Entry.select().where(Entry.id == parent_id, Entry.is_active == True).exists():
parent = Entry.get(Entry.id == parent_id, Entry.is_active == True)
else:
parent = None
title = views.form_get('title', 'no title')
body = views.form_get('body', '')
Entry.create(
user=user,
parent=parent,
title=title,
body=body,
)
return redirect(URLS['index'])
示例2: create
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def create():
if request.method == "POST":
if request.form.get("title") and request.form.get("content"):
try:
entry = Entry.create(
title=request.form["title"],
content=request.form["content"],
archived=request.form.get("archived") or False,
)
tags = request.form["tags"].split()
# present is a check to see if the tag exists
present = 0
# add or create tags
for tag in tags:
for entrytag in entry.tags:
if tag == entrytag.tag:
present = 1
if present == 0:
try:
thistag = Tag.get(Tag.tag == tag)
entry.tags.add(thistag)
except:
tag_obj, was_created = Tag.create_or_get(tag=tag)
EntryTags.create(tag=tag_obj, entry=entry)
present = 0
flash("Entry created successfully.", "success")
return redirect(url_for("detail", slug=entry.slug))
except:
flash("Note title already exists", "danger")
return render_template("create.html")
# TODO Refactor the below and above to make it more DRY or not
# to need to display seconds (e.g. add some kind of suffix if entry
# already exists)
elif request.form.get("content"):
entry = Entry.create(
title="{:%a %d %b %Y at %H:%M:%S}".format(datetime.datetime.now()), content=request.form["content"]
)
flash("Note created successfully.", "success")
return redirect(url_for("detail", slug=entry.slug))
else:
flash("Content is required.", "danger")
return render_template("create.html")
示例3: post
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def post(self):
page = self.get_int_param("page")
location = self.get_int_param("location")
book_key_name = self.request.get("book")
if page or location:
try:
entry = Entry.create(book = Book.get_by_key_name(book_key_name),
reader = users.get_current_user(),
page = page,
location = location)
Progress.create(entry)
except ValueError, error:
self.set_cookie("flash_message", error)
示例4: post
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def post(self, request, *args, **kwargs):
form = TextForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
title = cd.get('title')
text = cd.get('text')
cover = cd.get('cover', '')
entry = Entry.create(title, text, cover)
return HttpResponseRedirect(
reverse('detail', kwargs={'_id': str(entry.id)}))
return render_to_response('create.html', {
'form': form,
}, RequestContext(request))
示例5: create
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def create():
if request.method == 'POST':
if request.form.get('title') and request.form.get('content'):
entry = Entry.create(
title=request.form['title'],
content=request.form['content'],
published=request.form.get('published') or False)
flash('Entry created 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('create.html')
示例6: create_entry
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import create [as 别名]
def create_entry(blog, title, content, pub_date=None):
return Entry.create(blog=blog, title=title, content=content,
pub_date=pub_date or datetime.datetime.now())