A web framework for aspiring media terrorists – PRE-ALPHA – DO NOT DEPLOY!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env python
  2. import flask
  3. import poobrains
  4. from flask import redirect
  5. app = poobrains.app
  6. @app.route('/')
  7. def front():
  8. return redirect(News.url())
  9. class TestSubForm(poobrains.form.Fieldset):
  10. oink = poobrains.form.fields.Text(label="OMGWTF")
  11. foo = poobrains.form.fields.Text(label="SUBfoo")
  12. submit = poobrains.form.Button('submit', label="SUBSUBMIT")
  13. @app.expose('/form')
  14. class TestForm(poobrains.form.Form):
  15. foo = poobrains.form.fields.Text()
  16. bar = TestSubForm()
  17. optin = poobrains.form.fields.Checkbox(label="Opt-in", default=False, required=True, choices=[(True, None)])
  18. radio = poobrains.form.fields.Radio(type=poobrains.form.types.INT, choices=[(1, 'One'), (5, 'Five'), (23, 'Twentythree'), (42, 'Fortytwo')])
  19. multicheck = poobrains.form.fields.Checkbox(label="Check 'em", type=poobrains.form.types.STRING, choices=[('dubs', 'dubs'), ('trips', 'TRIPS'), ('quads', 'QUADS!1!!!!')], multi=True)
  20. completeme = poobrains.form.fields.Text(label="Lookit me, I can autocomplete without JS!", choices=[('Mr. Foo', 'foo'), ('Mr. Florb', 'florb'), ('Ms. Bar', 'bar')])
  21. ranged = poobrains.form.fields.Range()
  22. trigger = poobrains.form.Button('submit', label='Hit me!')
  23. def process(self, submit):
  24. flask.flash('TestForm.process called!')
  25. return self
  26. @app.expose('/news', mode='full')
  27. class News(poobrains.commenting.Commentable):
  28. """ This is the news class docstring """
  29. class Meta:
  30. search_fields = ['title', 'name', 'text']
  31. title = poobrains.storage.fields.CharField()
  32. text = poobrains.md.MarkdownField()
  33. @app.expose('/paste', mode='full', title='Copypasta')
  34. class Paste(poobrains.tagging.Taggable):
  35. type = poobrains.storage.fields.CharField()
  36. text = poobrains.storage.fields.TextField()
  37. @app.site.box('menu_main')
  38. def menu_main():
  39. menu = poobrains.rendering.Menu('main')
  40. try:
  41. News.permissions['read'].check(flask.g.user)
  42. menu.append(News.url(), 'News')
  43. except poobrains.auth.AccessDenied:
  44. pass
  45. try:
  46. Paste.permissions['read'].check(flask.g.user)
  47. menu.append(Paste.url(), 'Pastes')
  48. except poobrains.auth.AccessDenied:
  49. pass
  50. return menu
  51. class NonExposed(poobrains.auth.Administerable):
  52. text = poobrains.storage.fields.TextField()
  53. class NonExposedB(NonExposed):
  54. pass
  55. class AVeryVeryLongNameToTestMenuPositioning(poobrains.auth.Administerable):
  56. florp = poobrains.storage.fields.BooleanField()
  57. #class MultiPK(poobrains.auth.Administerable):
  58. #
  59. # class Meta:
  60. # primary_key = peewee.CompositeKey('pk_a', 'pk_b')
  61. #
  62. # pk_a = poobrains.storage.fields.IntegerField()
  63. # pk_b = poobrains.storage.fields.IntegerField()
  64. #
  65. #
  66. #class NestedHandle(poobrains.auth.Administerable):
  67. #
  68. # class Meta:
  69. # primary_key = peewee.CompositeKey('foreign', 'local')
  70. #
  71. # foreign = poobrains.storage.fields.ForeignKeyField(MultiPK)
  72. # local = poobrains.storage.fields.CharField()
  73. @app.site.listing(NonExposedB, '/custom', mode='full', title='Custom Listing')
  74. def list_nonexposed(listing):
  75. return listing
  76. if __name__ == '__main__':
  77. #app.run()
  78. poobrains.app.main()