Permalink
Browse files

Hmm, I've made a bit of a hash of it. Pause for reflection.

  • Loading branch information...
pauleveritt committed May 10, 2012
1 parent 9515e0b commit 55265a3b786f0e1a1b7138c6e0c9c97d75ea3bde
@@ -31,7 +31,7 @@ class AddDocumentView(FormView):
def add_success(self, appstruct):
registry = self.request.registry
name = appstruct.pop('name')
- topic = appstruct.pop('topic')
+ #topic = appstruct.pop('topic')
document = registry.content.create(IDocument,
**appstruct)
@@ -11,25 +11,44 @@
from .interfaces import (
IDocument,
ITopic
-)
+ )
+
+import deform_bootstrap.widget
+from substanced.util import oid_of
+@colander.deferred
+def principals_widget(node, kw):
+ request = kw['request']
+ principals = find_service(request.context, 'principals')
+ groups = [(str(oid_of(group)), name) for name, group in
+ principals['groups'].items()]
+ users = [(str(oid_of(user)), name) for name, user in
+ principals['users'].items()]
+ values = (
+ {'label':'Groups', 'values':groups},
+ {'label':'Users', 'values':users},
+ )
+ widget = deform_bootstrap.widget.ChosenOptGroupWidget(values=values)
+ return widget
class DocumentSchema(Schema):
name = colander.SchemaNode(
colander.String(),
- )
+ )
title = colander.SchemaNode(
colander.String(),
)
body = colander.SchemaNode(
colander.String(),
widget=deform.widget.RichTextWidget()
)
- topic = colander.SchemaNode(
+ principal = colander.SchemaNode(
colander.Int(),
- )
+ missing=colander.null,
+ widget = principals_widget,
+ )
+
class DocumentBasicPropertySheet(PropertySheet):
- schema = DocumentSchema()
def __init__(self, context, request):
self.context = context
@@ -56,17 +75,18 @@ def set(self, struct):
context.body = struct['body']
# Make the relationship to a topic
- objectmap = find_service(context, 'objectmap')
- objectid = struct['topic']
- topic = objectmap.object_for(objectid)
- objectmap.connect(context, topic, 'document-to-topic')
+ #objectmap = find_service(context, 'objectmap')
+ #objectid = struct['topic']
+ #topic = objectmap.object_for(objectid)
+ #objectmap.connect(context, topic, 'document-to-topic')
+
@content(
IDocument,
name='Document',
icon='icon-align-left',
add_view='add_document',
- propertysheets = (
+ propertysheets=(
('Basic', DocumentBasicPropertySheet),
),
catalog=True,
@@ -82,12 +102,14 @@ def texts(self): # for indexing
@property
def topic(self):
- objectmap = find_service(self, 'objectmap')
- topics = list(objectmap.targets(self, 'document-to-topic'))
- topic = 0
- for t in topics:
- topic = t
- return topic
+ #objectmap = find_service(self, 'objectmap')
+ #topics = list(objectmap.targets(self, 'document-to-topic'))
+ #topic = 0
+ #for t in topics:
+ # topic = t
+ #return topic
+
+ return None
# Topics
class TopicSchema(Schema):
@@ -98,6 +120,7 @@ class TopicSchema(Schema):
colander.String(),
)
+
class TopicBasicPropertySheet(PropertySheet):
schema = TopicSchema()
@@ -121,12 +144,13 @@ def set(self, struct):
parent.rename(oldname, newname)
context.title = struct['title']
+
@content(
ITopic,
name='Topic',
icon='icon-align-left',
add_view='add_topic',
- propertysheets = (
+ propertysheets=(
('Basic', TopicBasicPropertySheet),
),
catalog=True,
@@ -141,6 +165,7 @@ def texts(self): # for indexing
@property
def document(self):
- objectmap = find_service(self, 'objectmap')
- return objectmap.sources(self, 'document-to-topic')
+ #objectmap = find_service(self, 'objectmap')
+ #return objectmap.sources(self, 'document-to-topic')
+ return None
@@ -54,7 +54,18 @@ def documents_list(self):
def document_view(self):
self.title = self.context.title
- topic = self.context.topic
+ objectid = -1099536351
+ from substanced.service import find_service
+ objectmap = find_service(self.context, 'objectmap')
+ rel = 'document-to-topic'
+ topic = objectmap.object_for(objectid)
+ print list(objectmap.sources(topic, rel))
+ print list(objectmap.targets(self.context, rel))
+ #objectmap.connect(self.context, topic, 'document-to-topic')
+
+
+
+
return dict(body=self.context.body, topic=topic)

0 comments on commit 55265a3

Please sign in to comment.