Ejemplo n.º 1
0
 def view_for_edit_thread(uid: int, messages: Dict[str, str] = None):
     thread = Thread.find_by_id(uid)
     tags = Tag.find_all()
     return render_template('edit_thread.html',
                            title="Edit thread",
                            thread=thread,
                            tags=tags,
                            messages=messages)
Ejemplo n.º 2
0
    def find_by_id(uid: int) -> 'Account':
        rows = db.execute_query(
            """
            SELECT id, username, display_name, admin FROM Account WHERE id = %(id)s;
            """, {'id': uid})

        try:
            row = rows.pop(0)

            # Deferred in order to prevent circular imports.
            from src.models.thread import Thread

            threads = Thread.find_by_author_id(row['id'])
            account = Account(row['id'], row['username'], row['display_name'],
                              row['admin'], threads)
            return account

        except:
            return None
Ejemplo n.º 3
0
    def find_by_id(uid: int) -> 'Tag':
        rows = db.execute_query(
            """
            SELECT *, (
                SELECT COUNT(*) FROM ThreadTag
                WHERE ThreadTag.tag_id = %(id)s
            ) AS count FROM Tag
            WHERE id = %(id)s;
            """, {'id': uid})

        try:
            row = rows.pop(0)

            # Deferred in order to prevent circular imports.
            from src.models.thread import Thread

            threads = Thread.find_by_tag_id(row['id'])
            tag = Tag(row['id'], row['title'], row['count'], threads)
            return tag

        except:
            return None
Ejemplo n.º 4
0
 def author_for_thread(uid: int):
     return Thread.author_for_thread(uid)
Ejemplo n.º 5
0
 def thread_exists(uid: int):
     return Thread.find_by_id(uid) is not None
Ejemplo n.º 6
0
 def delete(uid: int):
     Thread.delete(uid)
Ejemplo n.º 7
0
 def update(uid: int, title: str, tag_ids: List[int]):
     result = Thread.update(uid, title, tag_ids)
     return result
Ejemplo n.º 8
0
 def create(user_id: int, title: str, content: str, tag_ids: List[int]):
     result = Thread.create(user_id, title, content, tag_ids)
     return result
Ejemplo n.º 9
0
 def view_for_thread(uid: int, messages: Dict[str, str] = None):
     thread = Thread.find_by_id(uid)
     return render_template('thread.html',
                            title="Thread",
                            thread=thread,
                            messages=messages)
Ejemplo n.º 10
0
 def view_for_threads():
     threads = Thread.find_all()
     return render_template('threads.html',
                            title="Threads",
                            threads=threads)