def create_thread( self, user_id ): """ Create a new forum thread with a blank post, and give the thread a default name. Then redirect to that new thread. @type user_id: unicode or NoneType @param user_id: id of current logged-in user (if any) @rtype dict @return { 'redirect': new_notebook_url } @raise Access_error: the current user doesn't have access to create a post @raise Validation_error: one of the arguments is invalid """ if user_id is None: raise Access_error() user = self.__database.load( User, user_id ) if user is None or not user.username or user.username == "anonymous": raise Access_error() anonymous = self.__database.select_one( User, User.sql_load_by_username( u"anonymous" ), use_cache = True ) if anonymous is None: raise Access_error() # for now, crappy hard-coding to prevent just anyone from creating a blog thread if self.__name == u"blog" and user.username != u"witten": raise Access_error() # create the new notebook thread thread_id = self.__database.next_id( Notebook, commit = False ) thread = Notebook.create( thread_id, self.DEFAULT_THREAD_NAME, user_id = user.object_id ) self.__database.save( thread, commit = False ) # associate the forum tag with the new notebook thread tag = self.__database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) ) self.__database.execute( anonymous.sql_save_notebook_tag( thread_id, tag.object_id, value = self.__name ), commit = False, ) # give the anonymous user access to the new notebook thread self.__database.execute( anonymous.sql_save_notebook( thread_id, read_write = True, owner = False, own_notes_only = True ), commit = False, ) # create a blank post in which the user can start off the thread note_id = self.__database.next_id( Notebook, commit = False ) note = Note.create( note_id, u"<h3>", notebook_id = thread_id, startup = True, rank = 0, user_id = user_id ) self.__database.save( note, commit = False ) self.__database.commit() if self.__name == "blog": return dict( redirect = u"/blog/%s" % thread_id, ) return dict( redirect = u"/forums/%s/%s" % ( self.__name, thread_id ), )
def make_thread( self ): title = u"Welcome to the Luminotes %s forum!" % self.forum_name # create a notebook thread to go in the forum notebook_id = self.database.next_id( Notebook, commit = False ) thread_notebook = Notebook.create( notebook_id, title, ) self.database.save( thread_notebook, commit = False ) anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) ) # add a single welcome note to the new thread note_id = self.database.next_id( Note, commit = False ) note = Note.create( note_id, u""" <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion forum, so please keep that in mind when posting. And have fun. """ % ( title, self.forum_name ), notebook_id, startup = True, rank = 0, user_id = anonymous.object_id, creation = datetime.now(), ) self.database.save( note, commit = False ) # load the forum tag, or create one if it doesn't exist tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) ) if not tag: tag_id = self.database.next_id( Tag, commit = False ) tag = Tag.create( tag_id, notebook_id = None, # this tag is not in the namespace of a single notebook user_id = anonymous.object_id, name = u"forum", description = u"discussion forum threads" ) self.database.save( tag, commit = False ) # associate the forum tag with the previously created notebook thread, and set that # association's value to forum_name self.database.execute( anonymous.sql_save_notebook_tag( notebook_id, tag.object_id, value = self.forum_name ), commit = False, ) # give the anonymous user access to the new notebook thread self.database.execute( anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ), commit = False, )
def convert_post(self, note): # create a notebook thread to go in the forum notebook_id = self.database.next_id(Notebook, commit=False) thread_notebook = Notebook.create( notebook_id, note.title, ) self.database.save(thread_notebook, commit=False) anonymous = self.database.select_one( User, User.sql_load_by_username(u"anonymous")) # move the given note into the newly created notebook thread note.notebook_id = notebook_id note.startup = True note.rank = 0 self.database.save(note, commit=False) # load the forum tag forum_tag = self.database.select_one( Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id)) # associate the forum tag with the previously created notebook thread, and set that # association's value to the forum name self.database.execute( anonymous.sql_save_notebook_tag(notebook_id, forum_tag.object_id, value=u"blog"), commit=False, ) # give the anonymous user access to the new notebook thread self.database.execute( anonymous.sql_save_notebook(notebook_id, read_write=True, owner=False, own_notes_only=True), commit=False, ) blog_user = self.database.select_one( User, User.sql_load_by_username(self.blog_username)) self.database.execute( blog_user.sql_save_notebook(notebook_id, read_write=True, owner=True), commit=False, )
def convert_post( self, note ): # create a notebook thread to go in the forum notebook_id = self.database.next_id( Notebook, commit = False ) thread_notebook = Notebook.create( notebook_id, note.title, ) self.database.save( thread_notebook, commit = False ) anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) ) # move the given note into the newly created notebook thread note.notebook_id = notebook_id note.startup = True note.rank = 0 self.database.save( note, commit = False ) # load the forum tag forum_tag = self.database.select_one( Tag, Tag.sql_load_by_name( u"forum", user_id = anonymous.object_id ) ) # associate the forum tag with the previously created notebook thread, and set that # association's value to the forum name self.database.execute( anonymous.sql_save_notebook_tag( notebook_id, forum_tag.object_id, value = u"blog" ), commit = False, ) # give the anonymous user access to the new notebook thread self.database.execute( anonymous.sql_save_notebook( notebook_id, read_write = True, owner = False, own_notes_only = True ), commit = False, ) blog_user = self.database.select_one( User, User.sql_load_by_username( self.blog_username ) ) self.database.execute( blog_user.sql_save_notebook( notebook_id, read_write = True, owner = True ), commit = False, )
def make_thread(self): title = u"Welcome to the Luminotes %s forum!" % self.forum_name # create a notebook thread to go in the forum notebook_id = self.database.next_id(Notebook, commit=False) thread_notebook = Notebook.create( notebook_id, title, ) self.database.save(thread_notebook, commit=False) anonymous = self.database.select_one( User, User.sql_load_by_username(u"anonymous")) # add a single welcome note to the new thread note_id = self.database.next_id(Note, commit=False) note = Note.create( note_id, u""" <h3>%s</h3> You can discuss any Luminotes %s topics here. This is a public discussion forum, so please keep that in mind when posting. And have fun. """ % (title, self.forum_name), notebook_id, startup=True, rank=0, user_id=anonymous.object_id, creation=datetime.now(), ) self.database.save(note, commit=False) # load the forum tag, or create one if it doesn't exist tag = self.database.select_one( Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id)) if not tag: tag_id = self.database.next_id(Tag, commit=False) tag = Tag.create( tag_id, notebook_id= None, # this tag is not in the namespace of a single notebook user_id=anonymous.object_id, name=u"forum", description=u"discussion forum threads") self.database.save(tag, commit=False) # associate the forum tag with the previously created notebook thread, and set that # association's value to forum_name self.database.execute( anonymous.sql_save_notebook_tag(notebook_id, tag.object_id, value=self.forum_name), commit=False, ) # give the anonymous user access to the new notebook thread self.database.execute( anonymous.sql_save_notebook(notebook_id, read_write=True, owner=False, own_notes_only=True), commit=False, )
def create_thread(self, user_id): """ Create a new forum thread with a blank post, and give the thread a default name. Then redirect to that new thread. @type user_id: unicode or NoneType @param user_id: id of current logged-in user (if any) @rtype dict @return { 'redirect': new_notebook_url } @raise Access_error: the current user doesn't have access to create a post @raise Validation_error: one of the arguments is invalid """ if user_id is None: raise Access_error() user = self.__database.load(User, user_id) if user is None or not user.username or user.username == "anonymous": raise Access_error() anonymous = self.__database.select_one( User, User.sql_load_by_username(u"anonymous"), use_cache=True) if anonymous is None: raise Access_error() # for now, crappy hard-coding to prevent just anyone from creating a blog thread if self.__name == u"blog" and user.username != u"witten": raise Access_error() # create the new notebook thread thread_id = self.__database.next_id(Notebook, commit=False) thread = Notebook.create(thread_id, self.DEFAULT_THREAD_NAME, user_id=user.object_id) self.__database.save(thread, commit=False) # associate the forum tag with the new notebook thread tag = self.__database.select_one( Tag, Tag.sql_load_by_name(u"forum", user_id=anonymous.object_id)) self.__database.execute( anonymous.sql_save_notebook_tag(thread_id, tag.object_id, value=self.__name), commit=False, ) # give the anonymous user access to the new notebook thread self.__database.execute( anonymous.sql_save_notebook(thread_id, read_write=True, owner=False, own_notes_only=True), commit=False, ) # create a blank post in which the user can start off the thread note_id = self.__database.next_id(Notebook, commit=False) note = Note.create(note_id, u"<h3>", notebook_id=thread_id, startup=True, rank=0, user_id=user_id) self.__database.save(note, commit=False) self.__database.commit() if self.__name == "blog": return dict(redirect=u"/blog/%s" % thread_id, ) return dict(redirect=u"/forums/%s/%s" % (self.__name, thread_id), )