more on user management with loops.organize
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1214 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
60111065e7
commit
8edec76c1d
9 changed files with 122 additions and 41 deletions
|
@ -28,6 +28,8 @@ from zope.app.form.browser.interfaces import ITerms
|
|||
from zope.app.intid.interfaces import IIntIds
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.formlib.form import EditForm as BaseEditForm
|
||||
from zope.formlib.namedtemplate import NamedTemplate
|
||||
from zope.interface import implements
|
||||
from zope.app.publisher.browser import applySkin
|
||||
from zope.publisher.interfaces.browser import ISkin
|
||||
|
@ -39,6 +41,18 @@ from cybertools.typology.interfaces import IType
|
|||
from loops.interfaces import IView
|
||||
from loops import util
|
||||
|
||||
|
||||
class EditForm(BaseEditForm):
|
||||
|
||||
template = NamedTemplate('pageform')
|
||||
|
||||
def deleteObjectAction(self):
|
||||
return None # better not to show the edit button at the moment
|
||||
parent = zapi.getParent(self.context)
|
||||
parentUrl = zapi.absoluteURL(parent, self.request)
|
||||
return parentUrl + '/contents.html'
|
||||
|
||||
|
||||
class BaseView(object):
|
||||
|
||||
def __init__(self, context, request):
|
||||
|
|
|
@ -25,30 +25,29 @@ $Id$
|
|||
from zope.app import zapi
|
||||
from zope.app.catalog.interfaces import ICatalog
|
||||
from zope.app.event.objectevent import ObjectCreatedEvent, ObjectModifiedEvent
|
||||
from zope.app.container.contained import ObjectRemovedEvent
|
||||
from zope.app.form.browser.interfaces import ITerms
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.event import notify
|
||||
from zope.formlib.form import EditForm, FormFields
|
||||
from zope.formlib.namedtemplate import NamedTemplate
|
||||
from zope.interface import implements
|
||||
from zope.publisher.interfaces import BadRequest
|
||||
from zope.publisher.interfaces.browser import IBrowserRequest
|
||||
from zope import schema
|
||||
from zope.schema.interfaces import IIterableSource
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
|
||||
from cybertools.typology.interfaces import IType, ITypeManager
|
||||
from loops.interfaces import IConcept
|
||||
from loops.concept import Concept, ConceptTypeSourceList, PredicateSourceList
|
||||
from loops.browser.common import BaseView, LoopsTerms
|
||||
from loops.browser.common import EditForm, BaseView, LoopsTerms
|
||||
from loops import util
|
||||
|
||||
|
||||
class ConceptEditForm(EditForm):
|
||||
|
||||
template = NamedTemplate('pageform')
|
||||
|
||||
@Lazy
|
||||
def typeInterface(self):
|
||||
return IType(self.context).typeInterface
|
||||
|
@ -59,9 +58,6 @@ class ConceptEditForm(EditForm):
|
|||
typeInterface = self.typeInterface
|
||||
if typeInterface is not None:
|
||||
fields = FormFields(fields, typeInterface)
|
||||
#typeAdapter = zapi.queryAdapter(self.context, typeInterface)
|
||||
#if typeAdapter is not None:
|
||||
#...
|
||||
return fields
|
||||
|
||||
|
||||
|
|
|
@ -61,6 +61,13 @@
|
|||
permission="zope.View"
|
||||
/>
|
||||
|
||||
<!-- named template(s) -->
|
||||
|
||||
<zope:adapter
|
||||
factory="loops.browser.util.pageform"
|
||||
for="zope.interface.Interface"
|
||||
name="pageform" />
|
||||
|
||||
<!-- loops top-level container -->
|
||||
|
||||
<addform
|
||||
|
@ -159,20 +166,6 @@
|
|||
|
||||
</pages>
|
||||
|
||||
<!--<editform
|
||||
label="Edit Concept"
|
||||
name="edit.html"
|
||||
schema="loops.interfaces.IConcept"
|
||||
for="loops.interfaces.IConcept"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Edit"
|
||||
/>-->
|
||||
|
||||
<zope:adapter
|
||||
factory="loops.browser.util.pageform"
|
||||
for="zope.interface.Interface"
|
||||
name="pageform" />
|
||||
|
||||
<page
|
||||
name="edit.html"
|
||||
for="loops.interfaces.IConcept"
|
||||
|
@ -277,7 +270,15 @@
|
|||
for="loops.interfaces.IDocument"
|
||||
template="edit.pt"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Edit" />
|
||||
menu="zmi_views" title="Edit" />
|
||||
|
||||
<!--<page
|
||||
name="edit.html"
|
||||
for="loops.interfaces.IDocument"
|
||||
class="loops.browser.resource.DocumentEditForm"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Edit"
|
||||
/>-->
|
||||
|
||||
<page
|
||||
for="loops.interfaces.IDocument"
|
||||
|
@ -332,6 +333,14 @@
|
|||
menu="zmi_views" title="Edit Media Asset"
|
||||
/>
|
||||
|
||||
<!--<page
|
||||
name="edit.html"
|
||||
for="loops.interfaces.IMediaAsset"
|
||||
class="loops.browser.resource.MediaAssetEditForm"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Edit"
|
||||
/>-->
|
||||
|
||||
<!-- suppress the upload menu item: -->
|
||||
<menuItem
|
||||
for="loops.interfaces.IMediaAsset"
|
||||
|
@ -447,7 +456,7 @@
|
|||
menu="zmi_views" title="Edit Node">
|
||||
|
||||
<widget field="description" height="2" />
|
||||
<widget field="body" height="15" />
|
||||
<widget field="body" height="8" />
|
||||
|
||||
</editform>
|
||||
|
||||
|
@ -509,17 +518,6 @@
|
|||
menu="zmi_views" title="Edit Document"
|
||||
/>
|
||||
|
||||
<!--<editform
|
||||
label="Edit Concept"
|
||||
name="edit_target.html"
|
||||
schema="loops.interfaces.IConcept"
|
||||
fields="title conceptType"
|
||||
for="loops.interfaces.IConceptView"
|
||||
template="edit.pt"
|
||||
permission="zope.ManageContent"
|
||||
menu="zmi_views" title="Edit Concept"
|
||||
/>-->
|
||||
|
||||
<page
|
||||
name="node.html"
|
||||
for="loops.interfaces.INode"
|
||||
|
|
|
@ -78,6 +78,8 @@
|
|||
|
||||
</form>
|
||||
|
||||
<form metal:use-macro="views/resource_macros/delete_object" />
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -141,6 +141,9 @@ function toggleFormFieldHelp(ob,state) {
|
|||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
<form metal:use-macro="views/resource_macros/delete_object" />
|
||||
|
||||
<script type="text/javascript" metal:define-slot="trackChanges">
|
||||
zc_trackChanges(document.getElementById('zc.page.browser_form'));
|
||||
</script>
|
||||
|
|
|
@ -27,12 +27,13 @@ from zope.app import zapi
|
|||
from zope.app.catalog.interfaces import ICatalog
|
||||
from zope.app.dublincore.interfaces import ICMFDublinCore
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.formlib.form import FormFields
|
||||
from zope.proxy import removeAllProxies
|
||||
from zope.security import canAccess, canWrite
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
|
||||
from loops.interfaces import IDocument, IMediaAsset
|
||||
from loops.browser.common import BaseView
|
||||
from loops.browser.common import EditForm, BaseView
|
||||
from loops.browser.concept import ConceptRelationView, ConceptConfigureView
|
||||
from loops.browser.node import NodeView
|
||||
|
||||
|
@ -45,6 +46,13 @@ renderingFactories = {
|
|||
}
|
||||
|
||||
|
||||
class DocumentEditForm(EditForm):
|
||||
form_fields = FormFields(IDocument)
|
||||
|
||||
class MediaAssetEditForm(EditForm):
|
||||
form_fields = FormFields(IMediaAsset)
|
||||
|
||||
|
||||
class ResourceView(BaseView):
|
||||
|
||||
template = ViewPageTemplateFile('resource_macros.pt')
|
||||
|
|
|
@ -25,3 +25,21 @@
|
|||
</div>
|
||||
</metal:block>
|
||||
|
||||
|
||||
<form action="." method="post"
|
||||
metal:define-macro="delete_object"
|
||||
tal:define="action view/deleteObjectAction|nothing"
|
||||
tal:condition="action"
|
||||
tal:attributes="action action"
|
||||
id="form.object.delete">
|
||||
<span class="actionButtons"><br />
|
||||
<input type="hidden" name="ids:list" value="obj"
|
||||
tal:attributes="value context/zope:name" />
|
||||
<input type="submit" id="object.delete"
|
||||
name="container_delete_button"
|
||||
value="Delete object" class="button"
|
||||
onclick="return confirm('Do you really want to delete this object?')" />
|
||||
</span>
|
||||
</form>
|
||||
|
||||
|
||||
|
|
|
@ -23,12 +23,45 @@ $Id$
|
|||
"""
|
||||
|
||||
from zope.interface import Interface, Attribute
|
||||
from zope import schema
|
||||
from zope import component, schema
|
||||
from zope.app import zapi
|
||||
from zope.app.principalannotation import annotations
|
||||
from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
|
||||
from zope.i18nmessageid import MessageFactory
|
||||
from cybertools.organize.interfaces import IPerson as IBasePerson
|
||||
|
||||
_ = MessageFactory('zope')
|
||||
|
||||
ANNOTATION_KEY = 'loops.organize.person'
|
||||
|
||||
|
||||
class ValidationError(schema.interfaces.ValidationError):
|
||||
def doc(self):
|
||||
return self.info
|
||||
|
||||
def raiseValidationError(info):
|
||||
error = ValidationError()
|
||||
error.info = info
|
||||
raise error
|
||||
|
||||
|
||||
class UserId(schema.TextLine):
|
||||
|
||||
def _validate(self, userId):
|
||||
if not userId:
|
||||
return
|
||||
auth = component.getUtility(IAuthentication, context=self.context)
|
||||
try:
|
||||
principal = auth.getPrincipal(userId)
|
||||
except PrincipalLookupError:
|
||||
raiseValidationError(u'User %s does not exist' % userId)
|
||||
pa = annotations(principal)
|
||||
person = pa.get(ANNOTATION_KEY, None)
|
||||
if person is not None and person != self.context:
|
||||
raiseValidationError(
|
||||
u'There is alread a person (%s) assigned to user %s.'
|
||||
% (zapi.getName(person), userId))
|
||||
|
||||
|
||||
class IPerson(IBasePerson):
|
||||
""" Resembles a human being with a name (first and last name),
|
||||
|
@ -37,7 +70,7 @@ class IPerson(IBasePerson):
|
|||
basic cybertools.organize package.
|
||||
"""
|
||||
|
||||
userId = schema.TextLine(
|
||||
userId = UserId(
|
||||
title=_(u'User ID'),
|
||||
description=_(u'The principal id of a user that should '
|
||||
'be associated with this person.'),
|
||||
|
|
|
@ -29,18 +29,17 @@ from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
|
|||
from zope.component import adapts
|
||||
from zope.interface import implements
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.schema.interfaces import ValidationError
|
||||
from zope.app.form.interfaces import WidgetInputError
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
|
||||
from cybertools.organize.party import Person as BasePerson
|
||||
from cybertools.typology.interfaces import IType
|
||||
from loops.interfaces import IConcept
|
||||
from loops.organize.interfaces import IPerson
|
||||
from loops.organize.interfaces import IPerson, ANNOTATION_KEY
|
||||
from loops.type import TypeInterfaceSourceList
|
||||
|
||||
|
||||
ANNOTATION_KEY = 'loops.organize.person'
|
||||
|
||||
|
||||
# register IPerson as a type interface - (TODO: use a function for this)
|
||||
|
||||
TypeInterfaceSourceList.typeInterfaces += (IPerson,)
|
||||
|
@ -118,6 +117,16 @@ class Person(BasePerson):
|
|||
except PrincipalLookupError:
|
||||
return None
|
||||
|
||||
def getPrincipalForUserId(self, userId=None):
|
||||
userId = userId or self.userId
|
||||
if not userId:
|
||||
return None
|
||||
auth = self.authentication
|
||||
try:
|
||||
return auth.getPrincipal(userId)
|
||||
except PrincipalLookupError:
|
||||
return None
|
||||
|
||||
|
||||
def getAuthenticationUtility(context):
|
||||
return component.getUtility(IAuthentication, context=context)
|
||||
|
|
Loading…
Add table
Reference in a new issue