[Checkins] SVN: grok/trunk/grokblog/src/grokblog/ Introduce an
interface for entries. We use this to generate the form
Martijn Faassen
faassen at infrae.com
Thu Dec 14 16:52:50 EST 2006
Log message for revision 71554:
Introduce an interface for entries. We use this to generate the form
now too. Also got rid of some code that wasn't in use anymore.
Changed:
U grok/trunk/grokblog/src/grokblog/blog.py
U grok/trunk/grokblog/src/grokblog/blog_templates/blogindex.pt
U grok/trunk/grokblog/src/grokblog/entry.py
U grok/trunk/grokblog/src/grokblog/entry_templates/index.pt
U grok/trunk/grokblog/src/grokblog/entry_templates/item.pt
A grok/trunk/grokblog/src/grokblog/interfaces.py
-=-
Modified: grok/trunk/grokblog/src/grokblog/blog.py
===================================================================
--- grok/trunk/grokblog/src/grokblog/blog.py 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/blog.py 2006-12-14 21:52:49 UTC (rev 71554)
@@ -25,9 +25,6 @@
def entries(self):
return lastEntries(10)
- def renderEntry(self, entry):
- return renderRest(entry.body)
-
class BlogEdit(grok.EditForm):
grok.context(Blog)
grok.name('edit')
Modified: grok/trunk/grokblog/src/grokblog/blog_templates/blogindex.pt
===================================================================
--- grok/trunk/grokblog/src/grokblog/blog_templates/blogindex.pt 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/blog_templates/blogindex.pt 2006-12-14 21:52:49 UTC (rev 71554)
@@ -6,7 +6,7 @@
<body>
<h1 tal:content="context/title"/>
<h2 tal:content="context/tagline"/>
- <a tal:attributes="href python:view.url('add')">Add Blog Entry</a>
+ <a tal:attributes="href python:view.url('addrest')">Add Blog Entry</a>
<div class="entries">
<tal:block repeat="entry view/entries">
Modified: grok/trunk/grokblog/src/grokblog/entry.py
===================================================================
--- grok/trunk/grokblog/src/grokblog/entry.py 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/entry.py 2006-12-14 21:52:49 UTC (rev 71554)
@@ -1,67 +1,58 @@
from datetime import datetime
-import random
from docutils.core import publish_parts
+from zope import schema, interface
+
import grok
-from zope import schema
-from blog import Blog
+from grokblog.blog import Blog
+from grokblog import interfaces
class Entry(grok.Model):
- class fields:
- published = schema.Datetime(title=u'Published')
- title = schema.TextLine(title=u'Title')
- body = schema.Text(title=u'Body')
+ interface.implements(interfaces.IEntry)
- def __init__(self, title, body):
+ def __init__(self, title, summary, rightsinfo):
self.title = title
+ self.updated = datetime.now()
self.published = datetime.now()
- self.body = body
+ self.summary = summary
+ self.rightsinfo = rightsinfo
+
+class RestructuredTextEntry(Entry):
+ interface.implements(interfaces.IRestructuredTextEntry)
-class Add(grok.AddForm):
+ def __init__(self, title, summary, rightsinfo, content):
+ super(RestructuredTextEntry, self).__init__(title, summary, rightsinfo)
+ self.content = content
+
+grok.context(RestructuredTextEntry)
+
+class AddRest(grok.AddForm):
grok.context(Blog)
form_fields = grok.Fields(
id=schema.TextLine(title=u"id"))
- form_fields += grok.AutoFields(Entry).omit('published')
+ form_fields += grok.AutoFields(RestructuredTextEntry).omit(
+ 'published', 'updated')
@grok.action('Add entry')
- def add(self, id, title, body):
- self.context['entries'][id] = Entry(title, body)
+ def add(self, id, **data):
+ self.context['entries'][id] = RestructuredTextEntry(**data)
self.redirect(self.url(self.context))
-class Index(grok.View):
-
- def before(self):
- self.body = renderRest(self.context.body)
-
class Edit(grok.EditForm):
+ form_fields = grok.AutoFields(RestructuredTextEntry).omit(
+ 'published', 'updated')
- form_fields = grok.AutoFields(Entry).omit('published')
-
@grok.action('Save changes')
def edit(self, **data):
self.applyChanges(**data)
self.redirect(self.url(self.context))
-class Body(grok.View):
-
+class RenderedContent(grok.View):
def render(self):
- return renderRest(self.context.body)
+ return renderRest(self.context.content)
-class RandomDate(grok.View):
- # for testing purposes
-
- def render(self):
- self.context.published = datetime(
- 2006,
- 11,
- random.randrange(1, 29),
- random.randrange(0, 24),
- random.randrange(0, 60),
- )
- return str(self.context.published)
-
rest_settings = {
# Disable inclusion of external files, which is a security risk.
'file_insertion_enabled': False,
Modified: grok/trunk/grokblog/src/grokblog/entry_templates/index.pt
===================================================================
--- grok/trunk/grokblog/src/grokblog/entry_templates/index.pt 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/entry_templates/index.pt 2006-12-14 21:52:49 UTC (rev 71554)
@@ -9,6 +9,6 @@
(<span class="published" tal:content="context/published"/>)
</h1>
<a tal:attributes="href python:view.url('edit')">edit...</a>
- <tal:block content="structure context/@@body"/>
+ <tal:block content="structure context/@@renderedcontent" />
</body>
</html>
Modified: grok/trunk/grokblog/src/grokblog/entry_templates/item.pt
===================================================================
--- grok/trunk/grokblog/src/grokblog/entry_templates/item.pt 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/entry_templates/item.pt 2006-12-14 21:52:49 UTC (rev 71554)
@@ -5,5 +5,5 @@
</a>
(<span class="published" tal:content="context/published"/>)
</h2>
- <tal:block content="structure context/@@body"/>
+ <tal:block content="structure context/@@renderedcontent"/>
</div>
\ No newline at end of file
Added: grok/trunk/grokblog/src/grokblog/interfaces.py
===================================================================
--- grok/trunk/grokblog/src/grokblog/interfaces.py 2006-12-14 21:40:14 UTC (rev 71553)
+++ grok/trunk/grokblog/src/grokblog/interfaces.py 2006-12-14 21:52:49 UTC (rev 71554)
@@ -0,0 +1,52 @@
+from zope.interface import Interface
+from zope import schema, interface
+
+class IEntry(Interface):
+ """
+ This interface is based on the Atom entry definition, from the Atom RFC.
+
+ http://tools.ietf.org/html/rfc4287
+ """
+
+ # id is generated when we generate entry text
+
+ title = schema.TextLine(title=u"Title", required=True)
+
+ updated = schema.Datetime(title=u"Updated", required=True)
+
+ published = schema.Datetime(title=u"Published", required=False)
+
+## authors = schema.List(title=u"Authors", value_type=schema.Object,
+## default=[])
+
+## contributors = schema.List(title=u"Contributors", value_type=schema.Object,
+## default=[])
+
+## categories = schema.List(title=u"Categories", value_type=schema.Object,
+## default=[])
+
+ #links = schema.List(title=u"Links", value_type=schema.TextLine,
+ # default=[])
+
+ summary = schema.SourceText(title=u"Summary", required=False)
+
+ # content = schema.SourceText(title=u"Content")
+
+ rightsinfo = schema.SourceText(title=u"Rights", required=False)
+
+ # source is too complicated to support for us right now
+
+class IRestructuredTextEntry(IEntry):
+ content = schema.SourceText(title=u"Content")
+
+class IAtomEntry(Interface):
+
+ def xml():
+ """Return Atom representation of an entry.
+ """
+
+class IAtomContent(Interface):
+ def xml():
+ """Return Atom representation of content of object.
+ """
+
More information about the Checkins
mailing list