本文整理汇总了Python中core.models.Blog.load方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.load方法的具体用法?Python Blog.load怎么用?Python Blog.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.models.Blog
的用法示例。
在下文中一共展示了Blog.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blog_publish_process
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例2: blog_publish
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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__)
示例3: blog_delete_preview
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例4: media_edit
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例5: tag_make_for_page
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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: blog_user
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例8: media_edit_save
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例9: blog_queue_clear
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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)
示例10: export_theme_for_blog
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
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
示例11: new_category
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
def new_category(blog_id):
from core.models import db
with db.atomic() as txn:
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_editor(user, blog)
category_list = [n for n in blog.categories]
category = Category(id=0,
title='',
blog=blog)
top_level_category = Category(
id=None,
title='[Top-level category]',
parent=None
)
category_list.insert(0, top_level_category)
tags = template_tags(
blog=blog,
user=user)
if request.method == "POST":
with db.atomic() as txn:
category_title = request.forms.getunicode('category_title')
try:
parent_category = int(request.forms.getunicode('category_parent'))
except ValueError:
parent_category = None
with db.atomic() as txn:
category = Category(blog=blog,
title=category_title,
parent_category=parent_category
)
category.save()
redirect('{}/blog/{}/category/{}'.format(
BASE_URL, blog.id, category.id))
tpl = template('edit/category',
category=category,
category_list=category_list,
menu=generate_menu('blog_new_category', category),
search_context=(search_contexts['sites'], None),
**tags.__dict__)
return tpl
示例12: blog_static
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
def blog_static(filepath):
'''
Returns static routes for the currently staged blog.
The blog ID is appended to the URL as a '_' parameter (e.g., ?_=1 for blog ID 1)
The future of this function is currently being debated.
'''
try:
blog_id = int(request.query['_'])
except KeyError:
return system_site_index()
# raise
blog = Blog.load(blog_id)
root_path = blog.path
filesystem_filepath = urllib.parse.quote(filepath)
# TODO: replace this with results from /preview path,
# or another function that finds by abs path in db.
if os.path.isfile(root_path + "/" + filesystem_filepath) is False:
filepath += ("index.html")
if os.path.isfile(root_path + "/" + filesystem_filepath) is False:
abort(404, 'File {} not found'.format(root_path + "/" + filesystem_filepath))
k = static_file(filesystem_filepath, root=root_path)
if (k.headers['Content-Type'][:5] == "text/" or
k.headers['Content-Type'] == "application/javascript"):
k.add_header(
'Cache-Control', 'max-age=7200, public, must-revalidate')
if (k._headers['Content-Type'][0][:5] == "text/" and not k.body == ""):
x = k.body.read()
k.body.close()
y = x.decode('utf8')
z = re.compile(r' href=["\']' + (blog.url) + '([^"\']*)["\']')
z2 = re.compile(r' href=["\'](/[^"\']*)["\']')
y = re.sub(z, r" href='" + BASE_URL_PROTOCOL + DEFAULT_LOCAL_ADDRESS +
DEFAULT_LOCAL_PORT + "\\1?_={}'".format(blog_id), y)
y = re.sub(z2, r" href='\1?_={}'".format(blog_id), y)
y = y.encode('utf8')
k.headers['Content-Length'] = len(y)
k.body = y
return (k)
示例13: blog_list_users
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
def blog_list_users(blog_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_admin(user, blog)
return listing(request, blog, blog.users,
'blog_users', 'blog_list_users',
user=user,
tags_data={'blog':blog}
)
示例14: blog_apply_theme
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
def blog_apply_theme(blog_id, theme_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_publisher(user, blog)
reason = auth.check_template_lock(blog)
theme = Theme.load(theme_id)
tags = template_tags(blog=blog,
user=user)
from core.utils import Status
if request.forms.getunicode('confirm') == user.logout_nonce:
from core.models import db
with db.atomic() as txn:
blog.apply_theme(theme, user)
status = Status(
type='success',
close=False,
message='''
Theme <b>{}</b> was successfully applied to blog <b>{}</b>.</p>
It is recommended that you <a href="{}">republish this blog.</a>
'''.format(theme.for_display, blog.for_display, '{}/blog/{}/republish'.format(
BASE_URL, blog.id))
)
else:
status = Status(
type='warning',
close=False,
message='''
You are about to apply theme <b>{}</b> to blog <b>{}</b>.</p>
<p>This will OVERWRITE AND REMOVE ALL EXISTING TEMPLATES on this blog!</p>
'''.format(theme.for_display, blog.for_display),
url='{}/blog/{}/themes'.format(
BASE_URL, blog.id),
yes={'id':'delete',
'name':'confirm',
'label':'Yes, I want to apply this theme',
'value':user.logout_nonce},
no={'label':'No, don\'t apply this theme',
'url':'{}/blog/{}/themes'.format(
BASE_URL, blog.id)}
)
tags.status = status if reason is None else reason
return report(tags, 'blog_apply_theme', [blog, theme])
示例15: tag_list_pages
# 需要导入模块: from core.models import Blog [as 别名]
# 或者: from core.models.Blog import load [as 别名]
def tag_list_pages(blog_id, tag_id):
user = auth.is_logged_in(request)
blog = Blog.load(blog_id)
permission = auth.is_blog_member(user, blog)
tag = Tag.load(tag_id)
return listing(request, tag, tag.pages.order_by(Page.publication_date.desc()),
'blog', 'blog_pages_for_tag',
user=user,
search_ui='blog_pages_with_tag',
search_context=tag_in_blog_search_results,
tags_data={'blog':blog}
)