Ejemplo n.º 1
0
 def get_additions(self):
     story_addition = execute_command(
         'SELECT * FROM `story_addition` ').fetchall()
     additions = execute_command(
         'SELECT id FROM `story_addition` WHERE story_id=%d' %
         int(self.id)).fetchall()
     a = list()
     for addition in additions:
         a.append(StoryAddition(addition[0]))
     return a
Ejemplo n.º 2
0
    def new_story(user, title, content):
        execute_command('INSERT INTO `story` '
                        '(title, created_by, time_created) '
                        'VALUES ("%s", %d, "%s");' %
                        (title, user.id, datetime.datetime.now()))

        # TODO: find a better way to do this lol
        inserted_id = int(
            execute_command('SELECT id FROM `story` '
                            'ORDER BY id DESC LIMIT 1').fetchall()[0][0])

        StoryAddition.new_story_addition(user, Story(inserted_id), content)
        return inserted_id
Ejemplo n.º 3
0
 def __init__(self, id):
     data = execute_command('SELECT * FROM `story` WHERE `story`.id=%d' %
                            int(id)).fetchall()
     assert (len(data) != 0)
     added = execute_command(
         'SELECT author_id FROM `story_addition` WHERE `story_addition`.story_id=%d'
         % int(id)).fetchall()
     self.id = id
     self.time_created = data[0][1]
     self.title = data[0][2]
     self.author = User(
         data[0][3])  # user id - maybe change to user object later
     self.added = list()  # ids of all the users who added to the story
     for a in added:
         self.added.append(a[0])
Ejemplo n.º 4
0
 def __init__(self, id):
     data = execute_command('SELECT * FROM `user` WHERE `user`.id=%d' % id).fetchall()
     assert (len(data) != 0)  # no making non existing users!
     self.id = int(data[0][0])
     self.username = data[0][1]
     self.password = data[0][2]
     self.time_created = data[0][3]
Ejemplo n.º 5
0
 def get_story_edits(self):
     data = execute_command('SELECT story_id FROM `story_addition` WHERE `story_addition`.author_id=%d' % self.id).fetchall()
     if len(data) == 0:
         return None
     stories = list()
     for s in data:
         stories.append(story.Story(s[0]))
     return stories
Ejemplo n.º 6
0
 def get_stories(self):
     data = execute_command('SELECT * FROM `story` WHERE `story`.created_by=%d' % self.id).fetchall()
     if len(data) == 0:
         return None
     stories = list()
     for s in data:
         stories.append(story.Story(s[0]))
     return stories
Ejemplo n.º 7
0
    def get_all_stories():
        data = execute_command('SELECT id FROM `story` '
                               'ORDER BY id DESC').fetchall()

        stories = list()
        for s in data:
            stories.append(Story(s[0]))
        return stories
Ejemplo n.º 8
0
    def __init__(self, id):
        data = execute_command(
            'SELECT * FROM `story_addition` WHERE `story_addition`.id=%d' %
            int(id)).fetchall()
        assert (len(data) != 0)  # no making non existing users!

        self.id = data[0][0]
        self.time_created = data[0][1]
        self.content = data[0][2]
        self.story_id = data[0][3]
        self.author = User(data[0][4])
Ejemplo n.º 9
0
    def new_user(username, password):

        execute_command('INSERT INTO `user` (username, password, time_created)'
                        'VALUES (\"%s\", \"%s\", \"%s\")' % (username, password, datetime.datetime.now()))
Ejemplo n.º 10
0
 def username_avaliable(username):
     res = execute_command('SELECT id FROM `user` WHERE `user`.username = \"%s\"' % username).fetchall()
     return len(res) == 0
Ejemplo n.º 11
0
 def get_by_username(username):
     data = execute_command('SELECT id from `user` WHERE `user`.username = \"%s\"' % username).fetchall()
     if len(data) == 0:
         return None
     else:
         return User(data[0][0])
Ejemplo n.º 12
0
 def new_story_addition(user, story, content):
     content = content.replace('"', r'""')
     execute_command(
         'INSERT INTO `story_addition` (content, story_id, author_id, time_created)'
         'VALUES (\"%s\", \"%s\", \"%s\", \"%s\")' %
         (content, story.id, user.id, datetime.datetime.now()))