本文整理汇总了Python中zope.component.createObject函数的典型用法代码示例。如果您正苦于以下问题:Python createObject函数的具体用法?Python createObject怎么用?Python createObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createObject函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_group
def init_group(container, admin_email, emailDomain):
'''Initialise the first group.'''
acl_users = container.site_root().acl_users
site = getattr(container.Content, SITE_ID, None)
if not site:
m = 'No site "{0}" found in "{1}"'.format(SITE_ID, container)
raise ValueError(m)
siteInfo = createObject('groupserver.SiteInfo', site)
starter = MoiraeForGroup(siteInfo)
groupId = 'example_group'
# We want the userInfo in the context of the site
admin = acl_users.get_userByEmail(admin_email)
adminInfo = createObject('groupserver.UserFromId', site, admin.getId())
try:
groupInfo = starter.create('Example group', groupId, 'public',
emailDomain, adminInfo)
except BadRequest:
mumble_exists_mumble('init_group', 'groups/%s' % groupId)
m = 'init_group: Skipping the rest of the group configuration.'
log.warning(m)
else:
ju = JoiningUser(adminInfo)
# Silent Join is used so if the SMTP config is borken everything
# still works.
ju.silent_join(groupInfo)
示例2: handle_get_groups
def handle_get_groups(self, action, data):
'''The form action for the *Leave group* page.
:param action: The button that was clicked.
:param dict data: The form data.'''
r = OrderedDict()
groupInfo = createObject('groupserver.GroupInfo', self.context, data['groupId'])
userInfo = createObject('groupserver.UserFromId', self.context, data['userId'])
if groupInfo.groupObj is None:
r['status'] = self.NO_GROUP
r['message'] = 'No such group "{0}"'.format(data['groupId'])
elif userInfo.anonymous:
r['status'] = self.NO_USER
r['message'] = 'No such user "{0}"'.format(data['userId'])
elif user_member_of_group(userInfo, groupInfo):
leave_group(groupInfo, userInfo, self.request)
r['status'] = self.SUCCESS
r['message'] = '{0} has left {1}'.format(userInfo.name, groupInfo.name)
else:
r['status'] = self.NOT_MEMBER
r['message'] = '{0} is not a member {1}'.format(userInfo.name, groupInfo.name)
r['groupId'] = data['groupId']
r['userId'] = data['userId']
retval = to_json(r)
return retval
示例3: setUp
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
# Create a conversation.
conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment')
comment1.text = 'Comment Text'
comment1.creator = "jim"
comment1.author_username = "Jim"
comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
self.new_id1 = conversation.addComment(comment1)
comment2 = createObject('plone.Comment')
comment2.text = 'Comment Text'
comment2.creator = "emma"
comment2.author_username = "Emma"
comment2.creation_date = datetime(2007, 12, 13, 4, 18, 12)
comment2.modification_date = datetime(2007, 12, 13, 4, 18, 12)
self.new_id2 = conversation.addComment(comment2)
comment3 = createObject('plone.Comment')
comment3.text = 'Comment Text'
comment3.creator = "lukas"
comment3.author_username = "Lukas"
comment3.creation_date = datetime(2009, 4, 12, 11, 12, 12)
comment3.modification_date = datetime(2009, 4, 12, 11, 12, 12)
self.new_id3 = conversation.addComment(comment3)
self.conversation = conversation
示例4: test_conversations_method
def test_conversations_method(self):
self.topic.invokeFactory(
'conversation',
id='conv1',
title='Conversation 1'
)
conversation = IConversation(self.topic.conv1)
comment1 = createObject('plone.Comment')
comment1.creation_date = datetime.utcnow()
comment1.author_name = u'John Doe'
conversation.addComment(comment1)
comment2 = createObject('plone.Comment')
comment2.creation_date = datetime.utcnow()
comment2.author_name = u'Jane Doe'
conversation.addComment(comment2)
from collective.ploneboard.browser.topic import TopicView
view = TopicView(self.topic, self.request)
conversations = view.conversations()
self.assertEqual(len(conversations), 1)
self.assertEqual(
conversations,
[
{
'title': u'Conversation 1',
'url': 'http://nohost/plone/board/topic1/conv1',
'total_comments': 2,
'last_commenter': u'Jane Doe',
'last_comment_date': comment2.creation_date,
}
]
)
示例5: __init__
def __init__(self, page):
"""Create an edit auditor.
DESCRIPTION
The constructor for an auditor is passed all the data
that will be the same for the events that are created
during one use of the auditor by a Zope 3 page-view.
ARGUMENTS
"page" A IGSContentFolder representing the page being
edited.
SIDE EFFECTS
The page is set to the page that is passed in, and used
as the context for the auditor.
The user (who is acting on the page) is set after
determining the logged-in user, using the page as the
context.
The site that all this is occurring on is set, after
being determined by a similar mechanism to the user.
A page-edit audit event factory is instantiated.
"""
self.page = page
self.userInfo = createObject('groupserver.LoggedInUser', page)
self.siteInfo = createObject('groupserver.SiteInfo', page)
self.queries = AuditQuery()
self.factory = EditPageAuditEventFactory()
示例6: __call__
def __call__(self):
siteInfo = createObject('groupserver.SiteInfo', self.context)
auditor = Auditor(self.context, siteInfo)
if len(self.traverse_subpath) == 1:
# The reset ID is specified
resetId = self.traverse_subpath[0]
try:
passwordResetUser = \
createObject('groupserver.PasswordResetUser', self.context,
resetId)
except ResetIdNotFoundError:
auditor.info(RESET_ID_404, instanceDatum=resetId)
u = '/password-reset-not-found.html?resetId={0}'
uri = u.format(resetId)
else:
if passwordResetUser.resetId_current(resetId):
auditor.info(RESET_LOGIN, passwordResetUser)
# Only log in when resetting the password
login(self.context, passwordResetUser.user)
uri = passwordResetUser.passwordSetUrl
else:
auditor.info(RESET_ID_410, passwordResetUser, resetId)
u = '/password-reset-used.html?resetId={0}'
uri = u.format(resetId)
else:
auditor.info(RESET_ID_400)
# the reset ID is not specified
uri = '/password-reset-no-id.html'
assert uri, 'URI not set'
return self.request.RESPONSE.redirect(uri)
示例7: setUp
def setUp(self):
self.portal = self.layer['portal']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
workflow = self.portal.portal_workflow
workflow.doActionFor(self.portal.doc1, 'publish')
# Create a conversation.
conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment')
comment1.text = 'Comment Text'
comment1.creator = 'jim'
comment1.author_username = 'Jim'
comment1.creation_date = datetime(2006, 9, 17, 14, 18, 12)
comment1.modification_date = datetime(2006, 9, 17, 14, 18, 12)
self.new_id1 = conversation.addComment(comment1)
comment2 = createObject('plone.Comment')
comment2.text = 'Comment Text'
comment2.creator = 'emma'
comment2.author_username = 'Emma'
comment2.creation_date = datetime(2007, 12, 13, 4, 18, 12)
comment2.modification_date = datetime(2007, 12, 13, 4, 18, 12)
self.new_id2 = conversation.addComment(comment2)
comment3 = createObject('plone.Comment')
comment3.text = 'Comment Text'
comment3.creator = 'lukas'
comment3.author_username = 'Lukas'
comment3.creation_date = datetime(2009, 4, 12, 11, 12, 12)
comment3.modification_date = datetime(2009, 4, 12, 11, 12, 12)
self.new_id3 = conversation.addComment(comment3)
self.conversation = conversation
示例8: test_notify_user
def test_notify_user(self):
# Add a comment with user notification enabled. Add another comment
# and make sure an email is send to the user of the first comment.
comment = createObject("plone.Comment")
comment.text = "Comment text"
comment.user_notification = True
comment.author_email = "[email protected]"
self.conversation.addComment(comment)
comment = createObject("plone.Comment")
comment.text = "Comment text"
comment_id = self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 1)
self.assertTrue(self.mailhost.messages[0])
msg = str(self.mailhost.messages[0])
self.assertTrue("To: [email protected]" in msg)
self.assertTrue("From: [email protected]" in msg)
# We expect the headers to be properly header encoded (7-bit):
self.assertTrue("Subject: =?utf-8?q?A_comment_has_been_posted=2E?=\n" in msg)
# The output should be encoded in a reasonable manner
# (in this case quoted-printable):
self.assertTrue("A comment on 'K=C3=B6lle Alaaf' has been posted here:" in msg)
self.assertTrue("http://nohost/plone/d=\noc1/view#%s" % comment_id in msg)
self.assertTrue("Comment text" in msg)
self.assertFalse("Approve comment" in msg)
self.assertFalse("Delete comment" in msg)
示例9: setUp
def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.request = self.layer["request"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
typetool = self.portal.portal_types
typetool.constructContent("Document", self.portal, "doc1")
self.wf = getToolByName(self.portal, "portal_workflow", None)
self.context = self.portal
self.portal.portal_workflow.setChainForPortalTypes(("Discussion Item",), "comment_review_workflow")
self.wf_tool = self.portal.portal_workflow
# Add a conversation with three comments
conversation = IConversation(self.portal.doc1)
comment1 = createObject("plone.Comment")
comment1.title = "Comment 1"
comment1.text = "Comment text"
comment1.Creator = "Jim"
new_id_1 = conversation.addComment(comment1)
self.comment1 = self.portal.doc1.restrictedTraverse("++conversation++default/%s" % new_id_1)
comment2 = createObject("plone.Comment")
comment2.title = "Comment 2"
comment2.text = "Comment text"
comment2.Creator = "Joe"
new_id_2 = conversation.addComment(comment2)
self.comment2 = self.portal.doc1.restrictedTraverse("++conversation++default/%s" % new_id_2)
comment3 = createObject("plone.Comment")
comment3.title = "Comment 3"
comment3.text = "Comment text"
comment3.Creator = "Emma"
new_id_3 = conversation.addComment(comment3)
self.comment3 = self.portal.doc1.restrictedTraverse("++conversation++default/%s" % new_id_3)
self.conversation = conversation
示例10: add_new_user
def add_new_user(self, toAddr, profileDict):
# Email address does not exist, but it is a legitimate address
user = create_user_from_email(self.context, toAddr)
# force verify
vid = '%s-%s-verified' % (toAddr, self.adminInfo.id)
evu = createObject('groupserver.EmailVerificationUserFromEmail',
self.context, toAddr)
evu.add_verification_id(vid)
evu.verify_email(vid)
# get the user object in the context of the group and site
userInfo = createObject('groupserver.UserFromId', self.context,
user.id)
self.add_profile_attributes(userInfo, profileDict)
auditor = self.get_auditor(userInfo)
status = ADD_NEW_USER
auditor.info(status, toAddr)
joininguser = IGSJoiningUser(userInfo)
joininguser.silent_join(self.groupInfo)
e = '<code class="email">{0}</code>'.format(toAddr)
msg = _('new-profile-member',
'<li>A profile for ${user} has been created, and given the '
'email address ${email}.</li>\n'
'<li>${user} has been joined to ${group}.</li>\n',
mapping={'email': e,
'user': userInfo_to_anchor(userInfo),
'group': groupInfo_to_anchor(self.groupInfo)})
retval = (msg, userInfo, status)
return retval
示例11: setUp
def setUp(self):
# Setup session manager
ztc.utils.setupCoreSessions(self.layer['app'])
# Setup sandbox
self.portal = self.layer['portal']
self.request = self.layer['request']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
name = self.portal.invokeFactory(
id='doc1',
title='Document 1',
type_name='Document')
self.document = self.portal[name]
conversation = IConversation(self.document)
replies = IReplies(conversation)
comment = createObject('plone.Comment')
comment.text = 'This is a comment'
new_id = replies.addComment(comment)
comment = self.document.restrictedTraverse(
'++conversation++default/%s' % new_id)
re_comment = createObject('plone.Comment')
re_comment.text = 'This is a reply'
re_comment.author_username = "julia"
re_comment.author_name = "Juliana"
re_comment.author_email = "[email protected]"
replies = IReplies(comment)
new_re_id = replies.addComment(re_comment)
示例12: __call__
def __call__(self):
siteInfo = createObject('groupserver.SiteInfo', self.context)
auditor = Auditor(self.context, siteInfo)
if len(self.traverse_subpath) == 1:
# A verification ID is present
verificationId = self.traverse_subpath[0]
try:
emailVerificationUser = \
createObject('groupserver.EmailVerificationUser',
self.context, verificationId)
except VerificationIdNotFoundError:
auditor.info(VERIFY_ID_404, instanceDatum=verificationId)
uri = '/email-verify-not-found.html?verificationId=%s' % \
verificationId
else:
if emailVerificationUser.verificationId_current(verificationId):
auditor.info(VERIFY_LOGIN, emailVerificationUser)
# Only log in when able to verify the email address
login(self.context, emailVerificationUser.user)
uri = '%s?verificationId=%s' % \
(emailVerificationUser.emailVerifyUrl, verificationId)
else:
auditor.info(VERIFY_ID_410, emailVerificationUser,
verificationId)
uri = '/email-verify-used.html?verificationId=%s' %\
verificationId
else:
auditor.info(VERIFY_ID_400)
# No verification ID is present
uri = '/email-verify-no-id.html'
assert uri, 'URI not set'
return self.request.RESPONSE.redirect(uri)
示例13: test_marks_behavior
def test_marks_behavior(self):
fti = queryUtility(IDexterityFTI,
name='upfront.assessmentitem.content.assessmentitem')
factory = fti.factory
new_assessmentitem = createObject(factory)
self.failUnless(IAssessmentItem.providedBy(new_assessmentitem))
fti = queryUtility(IDexterityFTI,
name='upfront.assessmentitem.content.answer')
factory = fti.factory
new_answer = createObject(factory)
self.failUnless(IAnswer.providedBy(new_answer))
marks_behavior = getUtility(IBehavior,
name = 'upfront.assessmentitem.behaviors.IMarks')
# We expect this behavior to be a form field provider. Let's verify that
self.failUnless(
IFormFieldProvider.providedBy(marks_behavior.interface)
)
# assert that you cannot add this behavior to a non-dexterity
# content type
doc = Document('doc')
marks_adapter = IMarks(doc, None)
self.assertEquals(False, marks_adapter is not None)
# assert that new_assessmentitem object implements the behavior
marks_adapter2 = IMarks(new_assessmentitem, None)
self.assertEquals(True, marks_adapter2 is not None)
# assert that new_answer object does not implements the behavior
marks_adapter3 = IMarks(new_answer, None)
self.assertEquals(False, marks_adapter3 is not None)
示例14: test_add_comment
def test_add_comment(self):
# Add comments to a CommentReplies adapter
# Create a conversation. In this case we doesn't assign it to an
# object, as we just want to check the Conversation object API.
conversation = IConversation(self.portal.doc1)
# Add a comment to the conversation
replies = IReplies(conversation)
comment = createObject('plone.Comment')
comment.text = 'Comment text'
new_id = replies.addComment(comment)
comment = self.portal.doc1.restrictedTraverse(
'++conversation++default/%s' % new_id)
# Add a reply to the CommentReplies adapter of the first comment
re_comment = createObject('plone.Comment')
re_comment.text = 'Comment text'
replies = IReplies(comment)
new_re_id = replies.addComment(re_comment)
# check that replies provides the IReplies interface
self.assertTrue(IReplies.providedBy(replies))
# Make sure our comment was added
self.assertTrue(new_re_id in replies)
# Make sure it is also reflected in the conversation
self.assertTrue(new_re_id in conversation)
# Make sure the conversation has the correct comment id
self.assertEqual(conversation[new_re_id].comment_id, new_re_id)
示例15: process_form
def process_form(self):
'''Process the forms in the page.
This method uses the "submitted" pattern that is used for the
XForms impementation on GroupServer.
* The method is called whenever the page is loaded by
tal:define="result view/process_form".
* The submitted form is checked for the hidden "submitted" field.
This field is only returned if the user submitted the form,
not when the page is loaded for the first time.
- If the field is present, then the form is processed.
- If the field is absent, then the method re turns.
RETURNS
A "result" dictionary, that at-least contains the form that
was submitted
'''
form = self.context.REQUEST.form
result = {}
result['form'] = form
if 'submitted' in form:
groupIds = [k.split('-respond')[0] for k in form.keys()
if '-respond' in k]
responses = [form['%s-respond' % k] for k in groupIds]
result['error'] = False
acceptedMessage = declinedMessage = u''
accepted = [k.split('-accept')[0] for k in responses
if '-accept' in k]
if accepted:
acceptedGroups = [createObject('groupserver.GroupInfo',
self.groupsInfo.groupsObj, g) for g in accepted]
self.accept_invitations(acceptedGroups)
acceptedMessage = self.accept_message(acceptedGroups)
declined = [k.split('-decline')[0] for k in responses
if '-decline' in k]
for d in declined:
assert d not in accepted
if declined:
declinedGroups = [createObject('groupserver.GroupInfo',
self.groupsInfo.groupsObj, g) for g in declined]
self.decline_invitations(declinedGroups)
declinedMessage = self.decline_message(declinedGroups)
result['message'] = u'%s\n%s' % \
(acceptedMessage, declinedMessage)
self.__currentInvitations = None
assert 'error' in result, 'No "errror" in the result'
assert type(result['error']) == bool
assert 'message' in result, 'No "message" in the result'
assert type(result['message']) == unicode
# Invalidate the current invitations property, so it is recomputed.
del self._current_invitations
assert 'form' in result
assert type(result['form']) == dict
return result