本文整理汇总了Python中core.models.Blog类的典型用法代码示例。如果您正苦于以下问题:Python Blog类的具体用法?Python Blog怎么用?Python Blog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Blog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_context_data
def get_context_data(self, **kwargs):
context = super(BlogView, self).get_context_data(**kwargs)
default_blog = Blog.query().get()
context['blog'] = default_blog
if default_blog:
context['posts'] = Blog.get_all_posts(default_blog.key.id())
return context
示例2: test_get_unique_one_blog
def test_get_unique_one_blog(self):
blog = Blog(key_name=settings.BLOG_KEY_NAME, title='blog_one')
blog.put()
result = Blog.get_unique()
self.assertEqual(result.title, 'blog_one')
self.assertEqual(result.tagline, None)
self.assertEqual(Blog.all().count(), 1)
示例3: initialise_db
def initialise_db():
# Create an ancestor for all of our Posts to ensure consistency when manipulating Posts
blog_instance = Blog.query().get()
if not blog_instance:
blog_instance = Blog()
blog_instance.put()
# Create Users
if not User.query().fetch():
User(
username='admin',
password='admin' # TODO - obfuscate this
).put()
示例4: blog_delete_preview
def blog_delete_preview(blog_id, preview_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_admin(user, blog)
f = lambda:None
f.blog = blog
if preview_id == 'all':
previews_to_delete = blog.fileinfos.where(FileInfo.preview_path.is_null(False))
message = 'All previews for blog {} deleted.'.format(blog.for_display)
f.msg = 'Delete all'
else:
previews_to_delete = blog.fileinfos.where(FileInfo.id == preview_id)
message = 'Preview for fileinfo {} deleted.'.format(preview_id)
f.msg = 'Delete preview {}'.format(preview_id)
for n in previews_to_delete:
if n.page is not None:
n.page.delete_preview()
else:
n.template_mapping.template.delete_preview()
tags = template_tags(blog_id=blog.id, user=user)
from core.utils import Status
tags.status = Status(
type='success',
message=message,
close=False,
)
return report(tags, 'blog_delete_preview', f)
示例5: tag_make_for_page
def tag_make_for_page(blog_id=None, page_id=None):
user = auth.is_logged_in(request)
if page_id is None:
# page = Page()
blog = Blog.load(blog_id)
page = None
permission = auth.is_blog_editor(user, blog)
assoc = {'blog':blog}
else:
page = Page.load(page_id)
blog = None
permission = auth.is_page_editor(user, page)
assoc = {'page':page}
tag_name = request.forms.getunicode('tag')
if len(tag_name) < 1:
return None
# Note that this is a single tag only!
tag = Tag.add_or_create(
[tag_name, ],
**assoc
)
if len(tag[0]) > 0:
tpl = template(tag[0][0].new_tag_for_display)
else:
tpl = template(tag[1][0].for_display)
return tpl
示例6: blog_publish_progress
def blog_publish_progress(blog_id, original_queue_length):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_publisher(user, blog)
queue_count = 0
control_jobs = Queue.control_jobs(blog)
if control_jobs.count() > 0:
# queue_count = queue.process_queue(blog)
# queue_count = transaction(queue.process_queue)(blog)
queue_count = q_p(blog)
time.sleep(RETRY_INTERVAL * 5)
else:
queue_count = 0
percentage_complete = int((1 - (int(queue_count) / int(original_queue_length))) * 100)
import settings
return template('queue/queue_run_include',
queue_count=queue_count,
blog=blog,
break_path='{}/blog/{}/publish/break'.format(BASE_URL, blog.id),
settings=settings,
percentage_complete=percentage_complete)
示例7: media_edit
def media_edit(blog_id, media_id, status=None):
'''
UI for editing a given media entry
'''
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
is_member = auth.is_blog_member(user, blog)
media = Media.load(media_id, blog)
permission = auth.is_media_owner(user, media)
from core.ui import kv
kv_ui_data = kv.ui(media.kv_list())
tags = template_tags(blog=blog,
media=media,
status=status,
user=user,
)
tags.sidebar = sidebar.render_sidebar(
panel_set='edit_media',
status_badge=status_badge,
kv_object='Media',
kv_objectid=media.id,
kv_ui=kv_ui_data)
return media_edit_output(tags)
示例8: blog_publish_process
def blog_publish_process(blog_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_publisher(user, blog)
control_jobs = Queue.control_jobs(blog)
if control_jobs.count() > 0:
queue_count = q_p(blog)
# queue_count = transaction(queue.process_queue)(blog)
time.sleep(RETRY_INTERVAL * 5)
else:
jobs = Queue.jobs(blog)
if jobs.count() > 0:
queue_count = jobs.count()
Queue.start(blog, queue_count)
queue_count = q_p(blog)
# queue_count = transaction(queue.process_queue)(blog)
time.sleep(RETRY_INTERVAL * 5)
else:
queue_count = 0
import settings
return template('queue/queue_counter_include',
blog=blog,
settings=settings,
queue_count=queue_count)
示例9: blog_publish
def blog_publish(blog_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_publisher(user, blog)
queue_length = Queue.job_counts(blog=blog)
if queue_length > 0:
start_message = template('queue/queue_run_include',
queue=Queue.jobs(blog),
percentage_complete=0,
blog=blog,
break_path='{}/blog/{}/publish/break'.format(BASE_URL, blog.id)
)
Queue.start(blog, queue_length)
else:
start_message = "Queue empty."
tags = template_tags(blog_id=blog.id,
user=user)
#
return template('queue/queue_run_ui',
start=queue_length,
start_message=start_message,
action_url="../../blog/{}/publish/progress/{}".format(blog.id,
queue_length),
title='Publishing queue progress',
# search_context=(search_context['blog_queue'], blog),
menu=generate_menu('blog_queue', blog),
**tags.__dict__)
示例10: test_post_create
def test_post_create(self):
""" create a post """
res = self.c.post('/post/{0}'.format(self.blog_id), {'title': 'First Post',
'synopsis': 'Post Extract',
'content': 'Post Content',
'tags': ['tag1', 'tag2', 'tag3']})
self.assertEqual(len(Blog.get_all_posts(self.blog_id)), 2)
示例11: blog_user
def blog_user(user_id, blog_id):
# Obtains user edit in blog context.
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_admin(user, blog)
user_to_edit = User.find(user_id)
return edit_user(user_to_edit, editing_user=user, context=blog_context, blog=blog)
示例12: media_edit_save
def media_edit_save(blog_id, media_id):
'''
Save changes to a media entry.
'''
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
is_member = auth.is_blog_member(user, blog)
media = Media.load(media_id)
permission = auth.is_media_owner(user, media)
friendly_name = request.forms.getunicode('media_friendly_name')
changes = False
if friendly_name != media.friendly_name:
changes = True
media.friendly_name = friendly_name
import datetime
if changes is True:
media.modified_date = datetime.datetime.utcnow()
media.save()
status = utils.Status(
type='success',
message='Changes to media <b>{}</b> saved successfully.'.format(
media.for_display)
)
else:
status = utils.Status(
type='warning',
no_sure=True,
message='No discernible changes submitted for media <b>{}</b>.'.format(
media.id, media.for_display)
)
logger.info("Media {} edited by user {}.".format(
media.for_log,
user.for_log))
from core.ui import kv
kv_ui_data = kv.ui(media.kv_list())
tags = template_tags(blog=blog,
media=media,
status=status,
user=user)
tags.sidebar = sidebar.render_sidebar(
panel_set='edit_media',
status_badge=status_badge,
kv_object='Media',
kv_objectid=media.id,
kv_ui=kv_ui_data)
return media_edit_output(tags)
示例13: blog_queue_clear
def blog_queue_clear(blog_id):
'''
Clear all pending jobs out of the queue
'''
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_publisher(user, blog)
Queue.clear(blog)
示例14: get_context_data
def get_context_data(self, *args, **kwargs):
context = super(BlogMixin, self).get_context_data(*args, **kwargs)
blog = Blog.get_unique()
context.update({
'blog': blog,
'active_user': users.get_current_user(),
'is_admin': users.is_current_user_admin()
})
return context
示例15: export_theme_for_blog
def export_theme_for_blog(blog_id, theme_name, theme_description):
from core.models import KeyValue, Blog
blog = Blog.load(blog_id)
theme_to_export = blog.templates()
theme = {}
theme["title"] = theme_to_export[0].theme.title
theme["description"] = theme_to_export[0].theme.description
theme["data"] = {}
for n in theme_to_export:
theme["data"][n.id] = {}
theme["data"][n.id]["template"] = json_dump(n)
mappings_to_export = n.mappings
theme["data"][n.id]["mapping"] = {}
for m in mappings_to_export:
theme["data"][n.id]["mapping"][m.id] = json_dump(m)
# We may not use the rest of this because of the way
# KVs are being scaled back
theme["kv"] = {}
kv_list = []
top_kvs = KeyValue.select().where(
KeyValue.object == 'Theme',
KeyValue.objectid == theme_to_export[0].theme.id,
KeyValue.is_schema == True)
for n in top_kvs:
kv_list.append(n)
while len(kv_list) > 0:
theme["kv"][kv_list[0].id] = json_dump(kv_list[0])
next_kvs = KeyValue.select().where(
KeyValue.parent == kv_list[0],
KeyValue.is_schema == True)
for f in next_kvs:
kv_list.append(f)
del kv_list[0]
import settings, os
with open(os.path.join(settings.APPLICATION_PATH , "install" ,
"templates.json"), "w", encoding='utf-8') as output_file:
output_file.write(json.dumps(theme,
indent=1,
sort_keys=True,
allow_nan=True))
return theme