Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prep for step08

  • Loading branch information...
commit 866e782f1fde5b31bc39f8fbfab3e7e2a7c926aa 1 parent 37b895a
@pauleveritt pauleveritt authored
View
1  docs/tutorial/tutorial/step08/__init__.py
@@ -6,5 +6,6 @@
def main(global_config, **settings):
config = Configurator(settings=settings, root_factory=Site.root_factory)
config.include('substanced')
+ config.include('.catalog')
config.scan()
return config.make_wsgi_app()
View
18 docs/tutorial/tutorial/step08/catalog.py
@@ -0,0 +1,18 @@
+from substanced.catalog.indexes import (
+ FieldIndex,
+ TextIndex,
+ KeywordIndex,
+ )
+
+from substanced.catalog.discriminators import (
+ get_textrepr,
+ get_title,
+ get_interfaces,
+ )
+
+def includeme(config):
+ config.add_catalog_index('name', FieldIndex('__name__'))
+ config.add_catalog_index('title', FieldIndex(get_title))
+ config.add_catalog_index('interfaces', KeywordIndex(get_interfaces))
+ config.add_catalog_index('texts', TextIndex(get_textrepr))
+
View
10 docs/tutorial/tutorial/step08/index.rst
@@ -2,12 +2,10 @@
Shows
=====
-- List documents in retail view
+- Support indexing
-- Split views into mgmt and retail
+- Add "body" to the Document property sheet
-- Introduce interfaces
+- catalog=True on Document
-- Main site view is registered against SiteEntry
-
-- View registered for IDocument
+- Reminder: blow away your Data.*
View
8 docs/tutorial/tutorial/step08/mgmt.py
@@ -6,9 +6,8 @@
IFolder,
)
-from .resources import (
- DocumentSchema,
- )
+from .interfaces import IDocument
+from .resources import DocumentSchema
@mgmt_view(
context=IFolder,
@@ -26,7 +25,8 @@ class AddDocumentView(FormView):
def add_success(self, appstruct):
registry = self.request.registry
name = appstruct.pop('name')
- document = registry.content.create('Document', **appstruct)
+ document = registry.content.create(IDocument,
+ **appstruct)
self.context[name] = document
return HTTPFound(self.request.mgmt_path(document, '@@properties'))
View
18 docs/tutorial/tutorial/step08/resources.py
@@ -1,4 +1,5 @@
import colander
+import deform.widget
from persistent import Persistent
@@ -15,6 +16,10 @@ class DocumentSchema(Schema):
title = colander.SchemaNode(
colander.String(),
)
+ body = colander.SchemaNode(
+ colander.String(),
+ widget=deform.widget.RichTextWidget()
+ )
class DocumentBasicPropertySheet(PropertySheet):
schema = DocumentSchema()
@@ -27,7 +32,8 @@ def get(self):
context = self.context
return dict(
name=context.__name__,
- title=context.title
+ title=context.title,
+ body=context.body
)
def set(self, struct):
@@ -38,6 +44,7 @@ def set(self, struct):
parent = context.__parent__
parent.rename(oldname, newname)
context.title = struct['title']
+ context.body = struct['body']
@content(
IDocument,
@@ -46,8 +53,13 @@ def set(self, struct):
add_view='add_document',
propertysheets = (
('Basic', DocumentBasicPropertySheet),
- )
+ ),
+ catalog=True,
)
class Document(Persistent):
- def __init__(self, title):
+ def __init__(self, title, body):
self.title = title
+ self.body = body
+
+ def texts(self): # for indexing
+ return self.title, self.body
View
23 docs/tutorial/tutorial/step08/retail.py
@@ -13,6 +13,12 @@ def __init__(self, context, request):
self.context = context
self.request = request
+ @property
+ def documents(self):
+ search_catalog = self.request.search_catalog
+ count, docids, resolver = search_catalog(interfaces=(IDocument,))
+ return [resolver(docid) for docid in docids]
+
@view_config(renderer='templates/siteroot_view.pt',
context=ISite)
def siteroot_view(self):
@@ -23,18 +29,21 @@ def siteroot_view(self):
name='documents')
def documents_list(self):
self.title = 'My Documents'
+
documents = []
- for name, item in self.context.items():
- if IDocument.providedBy(item):
- documents.append(
- {'url': resource_url(item, self.request),
- 'title': item.title,
- })
+ for document in self.documents:
+ documents.append(
+ {'url': resource_url(document,
+ self.request),
+ 'title': document.title,
+ })
+
return dict(documents=documents)
@view_config(renderer='templates/document_view.pt',
context=IDocument)
def document_view(self):
self.title = self.context.title
- return {}
+
+ return dict(body=self.context.body)
View
2  docs/tutorial/tutorial/step08/templates/document_view.pt
@@ -3,7 +3,7 @@
<h1>${view.title}</h1>
<div class="container-fluid">
- <p>This is the view of an <code>IDocument</code></p>
+ ${structure: body}
</div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.