本文整理汇总了Python中repoze.lemonade.content.create_content函数的典型用法代码示例。如果您正苦于以下问题:Python create_content函数的具体用法?Python create_content怎么用?Python create_content使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_content函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_feed
def add_feed(argv=sys.argv):
parser = create_karl_argparser(description='Add a new feed.')
parser.add_argument('-t', '--title', help='Override title of feed.')
parser.add_argument('-m', '--max', type=int, default=0,
help='Maximum number of entries to keep at a time.')
parser.add_argument('name', help='Identifier of feed in database.')
parser.add_argument('url', help='URL of feed.')
args = parser.parse_args(argv[1:])
env = args.bootstrap(args.config_uri)
root, closer = env['root'], env['closer']
feed = get_feed(root, args.name)
if feed is not None:
args.parser.error("Feed already exists with name: %s" % args.name)
name = args.name
override_title = args.title
max_entries = args.max
url = args.url
container = root.get('feeds')
if container is None:
container = create_content(IFeedsContainer)
root['feeds'] = container
assert name not in container, "Feed already exists: %s" % name
feed = create_content(IFeed, override_title)
feed.url = url
feed.max_entries = max_entries
container[name] = feed
feed.override_title = bool(override_title)
transaction.commit()
开发者ID:araymund,项目名称:karl,代码行数:29,代码来源:feeds.py
示例2: handle_submit
def handle_submit(self, converted):
context = self.context
request = self.request
parent = self.parent
creator = authenticated_userid(request)
log.debug('add_comment.html converted: %s, ctx: %s' % (str(converted),
self.context))
comment = create_content(
IComment,
parent.title,
converted['add_comment'],
extract_description(converted['add_comment']),
creator,
)
if not 'comments' in parent.keys():
parent['comments'] = create_content(ICommentsFolder)
comments = parent['comments']
next_id = comments.next_id
comments[next_id] = comment
if support_attachments(comment):
upload_attachments(converted['attachments'], comment,
creator, request)
return self.status_response('Comment added')
开发者ID:amarandon,项目名称:opencore,代码行数:27,代码来源:commenting.py
示例3: evolve
def evolve(context):
# add default category and layer to all calendars
# Prevent 'set_created' event handler from being called since it will,
# in turn, set the content_modified attribute of community which is used
# as the "Last Activity" in the user interface. We don't want this tweak
# to impact a community's last activity. This means we need to set created
# and modified on the new layers and categories ourselves.
registry = getSiteManager()
registry.adapters.unsubscribe(
(IContent, IObjectWillBeAddedEvent), None, set_created)
try:
search = ICatalogSearch(context)
default_category_name = ICalendarCategory.getTaggedValue('default_name')
default_layer_name = ICalendarLayer.getTaggedValue('default_name')
now = datetime.now()
cnt, docids, resolver = search(interfaces=[ICalendar])
for docid in docids:
calendar = resolver(docid)
default_category = create_content(ICalendarCategory, 'Default')
default_category.created = default_category.modified = now
if not default_category_name in calendar:
calendar[default_category_name] = default_category
local_layer = create_content(ICalendarLayer,
"This Calendar's Events Only", 'blue',
[resource_path(default_category)])
local_layer.created = local_layer.modified = now
if not default_layer_name in calendar:
calendar[default_layer_name] = local_layer
finally:
registry.adapters.subscribe(
(IContent, IObjectWillBeAddedEvent), None, set_created)
开发者ID:Falmarri,项目名称:karl,代码行数:32,代码来源:evolve2.py
示例4: add
def add(self, context, request):
default_category_name = ICalendarCategory.getTaggedValue('default_name')
default_layer_name = ICalendarLayer.getTaggedValue('default_name')
calendar = create_content(ICalendar)
context['calendar'] = calendar
calendar = context['calendar']
default_category = create_content(ICalendarCategory, 'Default')
calendar[default_category_name] = default_category
local_layer = create_content(ICalendarLayer,
"This Calendar's Events Only",' blue',
[resource_path(default_category)])
calendar[default_layer_name] = local_layer
开发者ID:Falmarri,项目名称:karl,代码行数:13,代码来源:calendar.py
示例5: handle_photo_upload
def handle_photo_upload(context, form, thumbnail=False, handle_exc=True):
upload = form.get("photo", None)
if upload is not None and upload.file is not None:
upload_file = upload.file
if hasattr(upload, 'type'):
upload_type = upload.type # FieldStorage
else:
upload_type = upload.mimetype # Formish File object
assert upload_type
if thumbnail:
if not hasattr(upload_file, 'seek'):
upload_file = StringIO(upload_file.read())
# save the source photo (in case we later decide to use
# a different thumbnail size)
source_photo = create_content(IImageFile, upload_file, upload_type)
upload_file.seek(0)
# make the thumbnail
try:
upload_file, upload_type = make_thumbnail(
upload_file, upload_type)
except IOError, e:
if not handle_exc:
raise
transaction.get().doom()
raise CustomInvalid({"photo": str(e)})
if 'source_photo' in context:
del context['source_photo']
context['source_photo'] = source_photo
photo = context.get_photo()
if photo is None:
photo = create_content(
IImageFile,
upload_file,
upload_type
)
name = "photo.%s" % photo.extension
context[name] = photo
else:
if photo.mimetype != upload_type:
del context[photo.__name__]
photo.mimetype = upload_type
name = "photo.%s" % photo.extension
context[name] = photo
photo.upload(upload_file)
check_upload_size(context, photo, 'photo')
开发者ID:boothead,项目名称:karl,代码行数:51,代码来源:utils.py
示例6: add_feed
def add_feed(site, name, url, override_title=None, max_entries=0):
container = site.get('feeds')
if container is None:
container = create_content(IFeedsContainer)
site['feeds'] = container
assert name not in container, "Feed already exists: %s" % name
feed = create_content(IFeed, override_title)
feed.url = url
feed.max_entries = max_entries
container[name] = feed
feed.override_title = bool(override_title)
return feed
开发者ID:davidblewett,项目名称:karlserve,代码行数:14,代码来源:feeds.py
示例7: __init__
def __init__(self):
super(Site, self).__init__()
self.catalog = CachingCatalog()
self.update_indexes()
self.catalog.document_map = DocumentMap()
profiles = create_content(IProfiles)
self['profiles'] = profiles
communities = create_content(ICommunities)
self['communities'] = communities
people = create_content(IPeopleDirectory)
self['people'] = people
self.users = KARLUsers(self)
self.tags = Tags(self)
self.sessions = SessionDataManager(3600, 5)
self.filestore = PersistentMapping()
开发者ID:boothead,项目名称:karl,代码行数:16,代码来源:site.py
示例8: handle_submit
def handle_submit(self, converted):
request = self.request
context = self.context
#create the news item and store it
creator = authenticated_userid(request)
newsitem = create_content(
INewsItem,
title=converted['title'],
text=converted['text'],
creator=creator,
publication_date=converted['publication_date'],
caption=converted['caption'],
)
name = make_unique_name(context, converted['title'])
context[name] = newsitem
relocate_temp_images(newsitem, request)
# tags, attachments, and photos
set_tags(newsitem, request, converted['tags'])
attachments_folder = newsitem['attachments']
upload_attachments(converted['attachments'], attachments_folder,
creator, request)
try:
handle_photo_upload(newsitem, converted)
except Invalid, e:
raise ValidationError(**e.error_dict)
开发者ID:mindreframer,项目名称:python-pyramid-stuff,代码行数:27,代码来源:newsitem.py
示例9: add_referencemanual_view
def add_referencemanual_view(context, request):
tags_list=request.POST.getall('tags')
form = AddReferenceManualForm(tags_list=tags_list)
if 'form.cancel' in request.POST:
return HTTPFound(location=model_url(context, request))
if 'form.submitted' in request.POST:
try:
converted = form.validate(request.POST)
# Create the reference manual and store it
creator = authenticated_userid(request)
reference_manual = create_content(IReferenceManual,
converted['title'],
converted['description'],
creator,
)
name = make_unique_name(context, converted['title'])
context[name] = reference_manual
# Save the tags on it.
set_tags(reference_manual, request, converted['tags'])
location = model_url(reference_manual, request)
return HTTPFound(location=location)
except Invalid, e:
fielderrors = e.error_dict
fill_values = form.convert(request.POST)
tags_field = dict(
records = [dict(tag=t) for t in request.POST.getall('tags')]
)
开发者ID:boothead,项目名称:karl,代码行数:32,代码来源:references.py
示例10: handle_photo_upload
def handle_photo_upload(context, form):
upload = form.get("photo", None)
if upload is not None and upload.file is not None:
request = get_current_request()
userid = authenticated_userid(request)
upload_file = upload.file
if hasattr(upload, "type"):
upload_type = upload.type # FieldStorage
else:
upload_type = upload.mimetype # Formish File object
assert upload_type
photo = create_content(
ICommunityFile,
title="Photo of " + context.title,
stream=upload_file,
mimetype=upload_type,
filename=basename_of_filepath(upload.filename),
creator=userid,
)
if not photo.is_image:
transaction.get().doom()
raise Invalid({"photo": "Uploaded file is not a valid image."})
if "photo" in context:
del context["photo"]
alsoProvides(photo, IPhoto)
context["photo"] = photo
check_upload_size(context, photo, "photo")
# Handle delete photo (ignore if photo also uploaded)
elif form.get("photo_delete", False) or (upload and upload.metadata.get("remove", False)):
if "photo" in context:
del context["photo"]
开发者ID:karlproject,项目名称:karl,代码行数:33,代码来源:utils.py
示例11: handle
def handle(self, message, info, text, attachments):
""" See IMailinHandler.
"""
target = self.context['comments']
reply = create_content(
IComment,
title=info['subject'],
creator=info['author'],
text=text,
description=extract_description(text),
)
reply.title = info['subject']
reply.creator = info['author']
reply.created = info['date']
reply.text = text
target[target.next_id] = reply
workflow = get_workflow(IComment, 'security', target)
if workflow is not None:
workflow.initialize(reply)
if attachments:
_addAttachments(reply, info, attachments)
# Mailin always sends alerts
alerts = queryUtility(IAlerts, default=Alerts())
alerts.emit(reply, offline_request)
开发者ID:Falmarri,项目名称:karl,代码行数:29,代码来源:mailin.py
示例12: handle_submit
def handle_submit(self, converted):
request = self.request
context = self.context
workflow = self.workflow
wikipage = create_content(
IWikiPage,
converted['title'],
converted['text'],
extract_description(converted['text']),
authenticated_userid(request),
)
name = make_name(context, converted['title'])
context[name] = wikipage
if workflow is not None:
workflow.initialize(wikipage)
if 'security_state' in converted:
workflow.transition_to_state(wikipage,
request,
converted['security_state'])
# Save the tags on it.
set_tags(wikipage, request, converted['tags'])
relocate_temp_images(wikipage, request)
if converted['sendalert']:
alerts = queryUtility(IAlerts, default=Alerts())
alerts.emit(wikipage, request)
msg = '?status_message=Wiki%20Page%20created'
location = model_url(wikipage, request) + msg
return HTTPFound(location=location)
开发者ID:reebalazs,项目名称:karl,代码行数:34,代码来源:wiki.py
示例13: handle_submit
def handle_submit(self, converted):
context = self.context
request = self.request
userid = converted['login']
users = self.users
if (users.get_by_id(userid) is not None or
users.get_by_login(userid) is not None or
userid in context):
msg = "User ID '%s' is already in use" % userid
raise ValidationError(login=msg)
users.add(userid, userid, converted['password'], converted['groups'])
# prepend http:// to the website URL if necessary
if converted.get('website', '').startswith('www.'):
converted['website'] = 'http://%s' % converted['website']
kw = {}
for k, v in converted.items():
if k in ('login', 'password', 'password_confirm',
'photo', 'groups'):
continue
kw[k] = v
profile = create_content(IProfile, **kw)
context[userid] = profile
workflow = get_workflow(IProfile, 'security', context)
if workflow is not None:
workflow.initialize(profile)
handle_photo_upload(profile, converted, thumbnail=True)
location = model_url(profile, request)
return HTTPFound(location=location)
开发者ID:boothead,项目名称:karl,代码行数:31,代码来源:people.py
示例14: evolve
def evolve(root):
former_id = None # Create lazily, in case we don't need it
profiles = find_profiles(root)
search = ICatalogSearch(root)
catalog = find_catalog(root)
creators = catalog['creator']._fwd_index.keys()
modifiers = catalog['modified_by']._fwd_index.keys()
userids = set(creators) | set(modifiers)
for userid in userids:
if userid not in profiles:
if former_id is None:
former_id = make_unique_name(profiles, 'formeruser')
print "Creating profile for former user content:", former_id
former_profile = create_content(
IProfile, firstname='Former', lastname='User'
)
profiles[former_id] = former_profile
count, docids, resolver = search(creator=userid)
for docid in docids:
doc = resolver(docid)
print "Updating 'creator' for", resource_path(doc)
doc.creator = former_id
count, docids, resolver = search(modified_by=userid)
for docid in docids:
doc = resolver(docid)
print "Updating 'modified_by' for", resource_path(doc)
doc.modified_by = former_id
开发者ID:Falmarri,项目名称:karl,代码行数:32,代码来源:evolve18.py
示例15: handle_submit
def handle_submit(self, converted):
request = self.request
context = self.context
workflow = self.workflow
forum = create_content(
IForum,
converted['title'],
converted['description'],
authenticated_userid(request),
)
name = make_unique_name(context, converted['title'])
context[name] = forum
# Set up workflow
if workflow is not None:
workflow.initialize(forum)
if 'security_state' in converted:
workflow.transition_to_state(forum, request,
converted['security_state'])
if 'sendalert' in converted and converted['sendalert']:
alerts = queryUtility(IAlerts, default=Alerts())
alerts.emit(forum, request)
location = resource_url(forum, request)
return HTTPFound(location=location)
开发者ID:lslaz1,项目名称:karl,代码行数:27,代码来源:forum.py
示例16: store_attachments
def store_attachments(attachments_folder, params, creator):
"""Given some request data, pick apart and store attachments"""
# Get the attachments out of the form data. We do iteritems
# becauser there might be multiple with the name prefixed by
# attachment.
new_attachments = []
for key, value in params.iteritems():
if key.startswith('attachment') and value != '':
new_attachments.append(value)
# Iterate through the new attachments and create content to store in
# the attachments folder.
for attachment in new_attachments:
filename = make_unique_name(attachments_folder,
basename_of_filepath(attachment.filename))
attachments_folder[filename] = obj = create_content(
ICommunityFile,
title = filename,
stream = attachment.file,
mimetype = attachment.type,
filename = filename,
creator = creator,
)
check_upload_size(attachments_folder, obj, 'attachment')
开发者ID:boothead,项目名称:karl,代码行数:25,代码来源:utils.py
示例17: test_measure_time_object_traversal
def test_measure_time_object_traversal(self):
#"""Measure time object traversal level 10"""
import datetime
#add container object
tx = self.graph.start_transaction()
root = self.app.root_factory(None)
from adhocracy.core.models.interfaces import IChildsDict
from adhocracy.core.models.container import IContainerMarker
from repoze.lemonade.content import create_content
container = root
for x in range(10):
name = u"child" + str(x)
child = create_content(IContainerMarker)
IChildsDict(container)[name] = child
container = IChildsDict(container)[name]
self.graph.stop_transaction(tx)
##test object traversal
start = datetime.datetime.now()
self.browser.open('http://localhost:6543/child0/child1/child2/' +
'child3/child4/child5/child6/child7/child8/child9')
end = datetime.datetime.now()
#echo measured time
output = """\n\n\n
Measure time object traversal level 10 - 1. run
===============================================
\n
browser.open('http://localhost/child0/../child8/child9'):\n
%s
\n\n\n
""" % (str(end - start))
print output
start = datetime.datetime.now()
self.browser.open('http://localhost:6543/child0/child1/child2/' +
'child3/child4/child5/child6/child7/child8/child9')
end = datetime.datetime.now()
#echo measured time
output = """\n\n\n
Measure time object traversal level 10 - 2. run
================================================
\n
browser.open('http://localhost/child0/../child8/child9'):\n
%s
\n\n\n
""" % (str(end - start))
print output
start = datetime.datetime.now()
self.browser.open('http://localhost:6543/child0/child1/child2/' +
'child3/child4/child5/child6/child7/child8/child9')
end = datetime.datetime.now()
#echo measured time
output = """\n\n\n
Measure time object traversal level 10 - 3. run
================================================
\n
browser.open('http://localhost/child0/../child8/child9'):\n
%s
\n\n\n
""" % (str(end - start))
print output
开发者ID:MicaSz,项目名称:adhocracy-3,代码行数:60,代码来源:tests_views_container.py
示例18: handle_submit
def handle_submit(self, converted):
context = self.context
request = self.request
parent = context.__parent__
creator = authenticated_userid(request)
comment = create_content(
IComment,
'Re: %s' % parent.title,
converted['add_comment'],
extract_description(converted['add_comment']),
creator,
)
next_id = parent['comments'].next_id
parent['comments'][next_id] = comment
workflow = get_workflow(IComment, 'security', context)
if workflow is not None:
workflow.initialize(comment)
if 'security_state' in converted:
workflow.transition_to_state(comment, request,
converted['security_state'])
if support_attachments(comment):
upload_attachments(converted['attachments'], comment,
creator, request)
relocate_temp_images(comment, request)
if converted.get('sendalert'):
alerts = queryUtility(IAlerts, default=Alerts())
alerts.emit(comment, request)
location = resource_url(parent, request)
msg = 'Comment added'
location = '%s?status_message=%s' % (location, urllib.quote(msg))
self.filestore.clear()
return HTTPFound(location=location)
开发者ID:lslaz1,项目名称:karl,代码行数:35,代码来源:commenting.py
示例19: handle_submit
def handle_submit(self, validated):
context = self.context
request = self.request
name = make_unique_name(context, validated['title'])
creator = authenticated_userid(request)
text = safe_html(validated['description'])
topic = create_content(IForumTopic,
validated['title'],
text,
creator,
)
if text:
topic.description = extract_description(text)
else:
topic.description = validated['title']
context[name] = topic
if request.POST.get('return_to') is not None:
location = request.POST['return_to']
return render_template_to_response('templates/javascript_redirect.pt',
url=location)
else:
location = model_url(topic, request)
return HTTPFound(location=location)
开发者ID:amarandon,项目名称:opencore,代码行数:28,代码来源:forum.py
示例20: upload_attachments
def upload_attachments(attachments, folder, creator, request):
""" This creates *and removes* attachments based on information
retrieved from a form"""
for attachment in attachments:
if attachment.filename:
mimetype = get_upload_mimetype(attachment)
filename = make_unique_name(
folder,
basename_of_filepath(attachment.filename)
)
folder[filename] = obj = create_content(
ICommunityFile,
title = filename,
stream = attachment.file,
mimetype = mimetype,
filename = filename,
creator = creator,
)
max_size = int(get_setting(folder, 'upload_limit', 0))
if max_size and obj.size > max_size:
msg = 'File size exceeds upload limit of %d.' % max_size
raise ValueError(msg)
else:
meta = attachment.metadata
if meta.get('remove') and meta.get('default'):
name = meta['default']
if name in folder:
ob = folder[name]
if has_permission('delete', ob, request):
del folder[name]
开发者ID:Falmarri,项目名称:karl,代码行数:30,代码来源:utils.py
注:本文中的repoze.lemonade.content.create_content函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论