/products/nevow/demo-newsedit.rst

https://github.com/MostAwesomeDude/divmod-docs · ReStructuredText · 75 lines · 64 code · 11 blank · 0 comment · 0 complexity · 0a1e46abce4d23c979bddd81c5db8f7a MD5 · raw file

  1. ===============
  2. Demo: news edit
  3. ===============
  4. .. code-block:: python
  5. from twisted.application import service, strports
  6. from nevow import appserver, loaders, rend, static, url
  7. class NewsEditPage(rend.Page):
  8. docFactory = loaders.xmlstr('''
  9. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
  10. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  11. <html xmlns:n='http://nevow.com/ns/nevow/0.1'>
  12. <head>
  13. <title>Example 1: A News Item Editor</title>
  14. <link rel='stylesheet' href='form_css' type='text/css' />
  15. </head>
  16. <body>
  17. <h1>Example 1: A News Item Editor</h1>
  18. <fieldset>
  19. <legend>Add / Edit News Item</legend>
  20. <p>Form Goes Here</p>
  21. </fieldset>
  22. <ol n:render='sequence' n:data='newsItems'>
  23. <li n:pattern='item' n:render='mapping'>
  24. <strong><n:slot name='title' /></strong>: <n:slot name='description' />
  25. </li>
  26. </ol>
  27. </body>
  28. </html>
  29. ''')
  30. def __init__(self, *args, **kwargs):
  31. self.store = kwargs.pop('store')
  32. def saveNewsItem(self, newsItemData):
  33. self.store.append(newsItemData)
  34. return url.here.click('confirmation')
  35. def data_newsItems(self, ctx, name):
  36. return self.store
  37. class ConfirmationPage(rend.Page):
  38. docFactory = loaders.xmlstr('''
  39. <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
  40. 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  41. <html>
  42. <body>
  43. <h1>Your item has been saved</h1>
  44. <ul>
  45. <li><a href='./'>Go back</a></li>
  46. </ul>
  47. </body>
  48. </html>
  49. ''')
  50. # A place to store news items. A list of dicts in this simple case.
  51. store = [dict(title='Lorum Ipsum', description='''
  52. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed sed enim mollis
  53. nulla faucibus aliquet. Praesent nec nibh. Nam eget pede. Nam tincidunt purus id
  54. lorem. Vestibulum lectus nisl, molestie vitae, feugiat egestas, sodales et,
  55. tellus. Vivamus eu libero. Nulla facilisi. Nullam nec dolor. Proin ac diam at
  56. neque auctor pulvinar. Maecenas eros nibh, fermentum at, eleifend at, malesuada
  57. eu, nunc. Sed posuere felis eu ipsum. In volutpat. Phasellus viverra. Quisque
  58. dignissim mattis turpis. Maecenas accumsan ipsum vel orci. Cras ac lectus. Sed
  59. nec nisl. Integer iaculis elit scelerisque sapien. Curabitur ac diam.
  60. ''')]
  61. rootResource = NewsEditPage(store=store)
  62. rootResource.putChild('confirmation', ConfirmationPage())
  63. application = service.Application('News item editor')
  64. strports.service('8080', appserver.NevowSite(rootResource)).setServiceParent(application)