Personal wiki notebook (not under development)
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.

make_forum_thread.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/python2.4
  2. import os
  3. import os.path
  4. import sys
  5. import cherrypy
  6. from datetime import datetime
  7. from controller.Database import Database
  8. from model.Notebook import Notebook
  9. from model.Note import Note
  10. from model.User import User
  11. from model.Tag import Tag
  12. class Thread_maker( object ):
  13. """
  14. Create a thread for a new forum.
  15. """
  16. def __init__( self, database, forum_name ):
  17. self.database = database
  18. self.forum_name = forum_name
  19. self.make_thread()
  20. self.database.commit()
  21. def make_thread( self ):
  22. title = u"Welcome to the Luminotes %s forum!" % self.forum_name
  23. # create a notebook thread to go in the forum
  24. notebook_id = self.database.next_id( Notebook, commit = False )
  25. thread_notebook = Notebook.create(
  26. notebook_id,
  27. title,
  28. )
  29. self.database.save( thread_notebook, commit = False )
  30. anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )
  31. # add a single welcome note to the new thread
  32. note_id = self.database.next_id( Note, commit = False )
  33. note = Note.create(
  34. note_id,
  35. u"""
  36. <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion
  37. forum, so please keep that in mind when posting. And have fun.
  38. """ % ( title, self.forum_name ),
  39. notebook_id,
  40. startup = True,
  41. rank = 0,
  42. user_id = anonymous.object_id,
  43. creation = datetime.now(),
  44. )
  45. self.database.save( note, commit = False )
  46. # load the forum tag, or create one if it doesn't exist
  47. tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) )
  48. if not tag:
  49. tag_id = self.database.next_id( Tag, commit = False )
  50. tag = Tag.create(
  51. tag_id,
  52. notebook_id = None, # this tag is not in the namespace of a single notebook
  53. user_id = anonymous.object_id,
  54. name = u"forum",
  55. description = u"discussion forum threads"
  56. )
  57. self.database.save( tag, commit = False )
  58. # associate the forum tag with the previously created notebook thread, and set that
  59. # association's value to forum_name
  60. self.database.execute(
  61. anonymous.sql_save_notebook_tag( notebook_id, tag.object_id, value = self.forum_name ),
  62. commit = False,
  63. )
  64. # give the anonymous user access to the new notebook thread
  65. self.database.execute(
  66. anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ),
  67. commit = False,
  68. )
  69. def main( args ):
  70. import cherrypy
  71. from config import Common
  72. cherrypy.config.update( Common.settings )
  73. desktop = False
  74. if args and "-d" in args:
  75. from config import Development
  76. settings = Development.settings
  77. args.remove( "-d" )
  78. elif args and "-l" in args:
  79. from config import Desktop
  80. settings = Desktop.settings
  81. desktop = True
  82. args.remove( "-l" )
  83. else:
  84. from config import Production
  85. settings = Production.settings
  86. cherrypy.config.update( settings )
  87. database = Database(
  88. host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
  89. ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
  90. data_dir = ".",
  91. )
  92. ranker = Thread_maker( database, *args )
  93. if __name__ == "__main__":
  94. main( sys.argv[ 1: ] )