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 loadTags():
    try:
        tags = [
            Tag(57, 0, "RT_RPM", "RT velocidade do motor RPM", "R", "G01"),
            Tag(55, 0, "Hookload", "Carga no gancho", "R", "G02"),
            Tag(55, 4, "STANDPIPE", "Riser pressure", "R", "G03"),
            Tag(55, 8, "LEFTCATHEADPRE", "Left cat head pressure", "R", "G03"),
            Tag(57, 4, "RTMotorCurrent", "RT corrente do motor A", "R", "G04")
        ]

        return tags
    except Exception as e:
        print e
        logging.error(str(e))
Beispiel #3
0
  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 ),
    )
Beispiel #4
0
def setup_tags(json_settings):
    for tag_info in json_settings["tags"]:
        tag_name = tag_info["tag"]
        bg_style = tag_info["bgstyle"]
        text_style = tag_info["textstyle"]
        tag = Tag(name=tag_name, bg_style=bg_style, text_style=text_style)
        db.session.add(tag)
Beispiel #5
0
 def post_impl(self):
     parser = reqparse.RequestParser()
     parser.add_argument("subject", type=str)
     parser.add_argument("body", type=str, required=True)
     parser.add_argument("board", type=int, required=True)
     parser.add_argument("tags", type=str)
     args = parser.parse_args()
     if "media" not in request.files or not request.files["media"].filename:
         raise SubmissionError("A file is required to post a thread!",
                               args["board"])
     tags = []
     if args["tags"]:
         tag_list = args["tags"].replace(" ", "").split(",")
         for tag_name in tag_list:
             tag = db.session.query(Tag).filter(
                 Tag.name == tag_name).one_or_none()
             if tag is None:
                 tag = Tag(name=tag_name)
                 db.session.add(tag)
             tags.append(tag)
     db.session.flush()
     thread = Thread(board=args["board"], views=0, tags=tags)
     # FIXME: use one transaction for all of this, the current state defeats
     # the purpose of having transactions in the first place
     db.session.add(thread)
     db.session.commit()
     NewPost().post(thread_id=thread.id)
     return thread
Beispiel #6
0
  def setUp( self ):
    self.object_id = u"17"
    self.notebook_id = u"19"
    self.user_id = u"20"
    self.name = u"mytag"
    self.description = u"this is my tag"
    self.value = u"a value"
    self.delta = timedelta( seconds = 1 )

    self.tag = Tag.create( self.object_id, self.notebook_id, self.user_id, self.name,
                           self.description, self.value )
Beispiel #7
0
    def setUp(self):
        self.object_id = u"17"
        self.notebook_id = u"19"
        self.user_id = u"20"
        self.name = u"mytag"
        self.description = u"this is my tag"
        self.value = u"a value"
        self.delta = timedelta(seconds=1)

        self.tag = Tag.create(self.object_id, self.notebook_id, self.user_id,
                              self.name, self.description, self.value)
Beispiel #8
0
    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,
        )
Beispiel #9
0
def get_tags(args: dict) -> List[Tag]:
    "Returns a list of Tag objects from the given tag list."
    if not args["tags"]:
        return

    tags = list(map(lambda s: s.strip(), args["tags"].split(",")))
    ret = []

    # add all the tags that already exist in the database
    for row in db.session.query(Tag, Tag.name).filter(Tag.name.in_(tags)):
        tags.remove(row.name)
        ret.append(row.Tag)

    # create the remaining tabs and add them to the transaction
    # (the above loop removes all tags that already exist in the database
    # from the list, # therefore simply looping over the tags list should
    # suffice)
    for tag in tags:
        ret.append(Tag(name=tag))

    return ret
  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,
        )
Beispiel #12
0
import os


from customjsonencoder import CustomJSONEncoder
from model.Board import Board
from model.Slip import gen_slip
from model.Tag import Tag
import model.Media
import model.Poster
from shared import db

db.create_all()
# set up some boards
for board_name in ("anime", "tech", "meta", "politics", "gaming", "music"):
    board = Board(name=board_name)
    db.session.add(board)
# admin credentials generation
admin = gen_slip("admin", "admin")
admin.is_admin = True
db.session.add(admin)
# special tags
for tag_name, bg_style, text_style in (("general", "bg-secondary", "text-light"),):
    tag = Tag(name=tag_name, bg_style=bg_style, text_style=text_style)
    db.session.add(tag)
db.session.commit()
# write a secret so we can have session support
open("secret", "w").write(str(os.urandom(16)))
# create upload and thumbnail directory if necessary
if not os.path.exists("uploads/thumb"):
    os.makedirs("uploads/thumb")
Beispiel #13
0
    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), )
Beispiel #14
0
    def setUp(self):
        Test_controller.setUp(self)

        self.notebook = Notebook.create(self.database.next_id(Notebook),
                                        u"my notebook",
                                        trash_id=u"foo")
        self.database.save(self.notebook)

        self.anon_notebook = Notebook.create(self.database.next_id(Notebook),
                                             u"Luminotes",
                                             trash_id=u"bar")
        self.database.save(self.anon_notebook)
        self.anon_note = Note.create(
            self.database.next_id(Note),
            u"<h3>my note</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.anon_note)

        self.login_note = Note.create(
            self.database.next_id(Note),
            u"<h3>login</h3>",
            notebook_id=self.anon_notebook.object_id,
        )
        self.database.save(self.login_note)

        self.username = u"mulder"
        self.password = u"trustno1"
        self.email_address = u"*****@*****.**"
        self.user = None
        self.session_id = None

        self.user = User.create(self.database.next_id(User), self.username,
                                self.password, self.email_address)
        self.database.save(self.user)
        self.database.execute(
            self.user.sql_save_notebook(self.notebook.object_id))

        self.anonymous = User.create(self.database.next_id(User), u"anonymous")
        self.database.save(self.anonymous)
        self.database.execute(
            self.anonymous.sql_save_notebook(self.anon_notebook.object_id))

        self.blog_user = User.create(self.database.next_id(User), u"witten",
                                     self.password, self.email_address)
        self.database.save(self.blog_user)

        tag_id = self.database.next_id(Tag)
        self.forum_tag = Tag.create(
            tag_id,
            notebook_id=
            None,  # this tag is not in the namespace of a single notebook
            user_id=self.anonymous.object_id,
            name=u"forum",
            description=u"a discussion forum")
        self.database.save(self.forum_tag)

        self.general_thread = Notebook.create(
            self.database.next_id(Notebook), u"Welcome to the general forum!")
        self.database.save(self.general_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.general_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.general_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"general"), )

        self.support_thread = Notebook.create(
            self.database.next_id(Notebook), u"Welcome to the support forum!")
        self.database.save(self.support_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.support_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.support_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"support"), )

        self.blog_thread = Notebook.create(self.database.next_id(Notebook),
                                           u"Welcome to the blog!")
        self.database.save(self.blog_thread)
        self.database.execute(
            self.anonymous.sql_save_notebook(
                self.blog_thread.object_id,
                read_write=Notebook.READ_WRITE_FOR_OWN_NOTES), )
        self.database.execute(
            self.blog_user.sql_save_notebook(self.blog_thread.object_id,
                                             read_write=Notebook.READ_WRITE), )
        self.database.execute(
            self.anonymous.sql_save_notebook_tag(self.blog_thread.object_id,
                                                 self.forum_tag.object_id,
                                                 value=u"forum"), )
Beispiel #15
0
  def setUp( self ):
    Test_controller.setUp( self )

    self.notebook = Notebook.create( self.database.next_id( Notebook ), u"my notebook", trash_id = u"foo" )
    self.database.save( self.notebook )

    self.anon_notebook = Notebook.create( self.database.next_id( Notebook ), u"Luminotes", trash_id = u"bar" )
    self.database.save( self.anon_notebook )
    self.anon_note = Note.create(
      self.database.next_id( Note ), u"<h3>my note</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.anon_note )

    self.login_note = Note.create(
      self.database.next_id( Note ), u"<h3>login</h3>",
      notebook_id = self.anon_notebook.object_id,
    )
    self.database.save( self.login_note )

    self.username = u"mulder"
    self.password = u"trustno1"
    self.email_address = u"*****@*****.**"
    self.user = None
    self.session_id = None

    self.user = User.create( self.database.next_id( User ), self.username, self.password, self.email_address )
    self.database.save( self.user )
    self.database.execute( self.user.sql_save_notebook( self.notebook.object_id ) )

    self.anonymous = User.create( self.database.next_id( User ), u"anonymous" )
    self.database.save( self.anonymous )
    self.database.execute( self.anonymous.sql_save_notebook( self.anon_notebook.object_id ) )

    self.blog_user = User.create( self.database.next_id( User ), u"witten", self.password, self.email_address )
    self.database.save( self.blog_user )

    tag_id = self.database.next_id( Tag )
    self.forum_tag = Tag.create(
      tag_id,
      notebook_id = None, # this tag is not in the namespace of a single notebook
      user_id = self.anonymous.object_id,
      name = u"forum",
      description = u"a discussion forum"
    )
    self.database.save( self.forum_tag )

    self.general_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the general forum!" )
    self.database.save( self.general_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.general_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.general_thread.object_id, self.forum_tag.object_id, value = u"general" ),
    )

    self.support_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the support forum!" )
    self.database.save( self.support_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.support_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.support_thread.object_id, self.forum_tag.object_id, value = u"support" ),
    )

    self.blog_thread = Notebook.create( self.database.next_id( Notebook ), u"Welcome to the blog!" )
    self.database.save( self.blog_thread )
    self.database.execute(
      self.anonymous.sql_save_notebook( self.blog_thread.object_id, read_write = Notebook.READ_WRITE_FOR_OWN_NOTES ),
    )
    self.database.execute(
      self.blog_user.sql_save_notebook( self.blog_thread.object_id, read_write = Notebook.READ_WRITE ),
    )
    self.database.execute(
      self.anonymous.sql_save_notebook_tag( self.blog_thread.object_id, self.forum_tag.object_id, value = u"forum" ),
    )