瀏覽代碼

feat: Word界面显示单词Box信息

SongZihuan 3 年之前
父節點
當前提交
154ea6bd1e
共有 4 個文件被更改,包括 14 次插入6 次删除
  1. 0 1
      app/user.py
  2. 5 4
      core/db.py
  3. 8 1
      core/word.py
  4. 1 0
      templates/test.html

+ 0 - 1
app/user.py

@@ -40,7 +40,6 @@ class UserWordDataBase(WordDatabase, UserMixin):
 
 
     def get_box_count(self) -> Tuple[list, list, int, int]:
     def get_box_count(self) -> Tuple[list, list, int, int]:
         res = self.search(columns=["COUNT(word)", "COUNT(DISTINCT word)", "box"], table="Word", group_by=["box"])
         res = self.search(columns=["COUNT(word)", "COUNT(DISTINCT word)", "box"], table="Word", group_by=["box"])
-        print(res)
         ret = [0, 0, 0, 0, 0]
         ret = [0, 0, 0, 0, 0]
         ret_distinct = [0, 0, 0, 0, 0]
         ret_distinct = [0, 0, 0, 0, 0]
         for i in res:
         for i in res:

+ 5 - 4
core/db.py

@@ -173,21 +173,22 @@ class WordDatabase(DataBase):
     @staticmethod
     @staticmethod
     def __make_word(q: str, res: list):
     def __make_word(q: str, res: list):
         w = word.Word(q)
         w = word.Word(q)
+        box = 6
         for i in res:
         for i in res:
             c = word.Word.Comment(i[2], i[3], i[4])
             c = word.Word.Comment(i[2], i[3], i[4])
             for e in i[5].split("@@"):
             for e in i[5].split("@@"):
                 c.add_eg(e)
                 c.add_eg(e)
             w.add_comment(c)
             w.add_comment(c)
+            box = min(i[6], box)
+        w.set_box(box)
         return w
         return w
 
 
     def find_word(self, q: str, search: bool = True, add: bool = True) -> Optional[word.Word]:
     def find_word(self, q: str, search: bool = True, add: bool = True) -> Optional[word.Word]:
         name_lower = q.lower().replace("'", "''")
         name_lower = q.lower().replace("'", "''")
-        res = self.search(columns=["id", "word", "part", "english", "chinese", "eg"],
+        res = self.search(columns=["id", "word", "part", "english", "chinese", "eg", "box"],
                           table="Word",
                           table="Word",
                           where=f"LOWER(word)='{name_lower}'")
                           where=f"LOWER(word)='{name_lower}'")
-        if res is None:
-            res = []
-        if len(res) <= 0:
+        if res is None or len(res) <= 0:
             if search:
             if search:
                 return self.__add_word(q, add)
                 return self.__add_word(q, add)
             return None
             return None

+ 8 - 1
core/word.py

@@ -143,14 +143,21 @@ class Word:
         def __str__(self):
         def __str__(self):
             return f"{self.part} {self.english} {self.chinese} \neg: {self.eg}"
             return f"{self.part} {self.english} {self.chinese} \neg: {self.eg}"
 
 
-    def __init__(self, name: str):
+    def __init__(self, name: str, box: int = 1):
         self.name = name
         self.name = name
         self.comment: Dict[str: "Word.Comment"] = {}  # 注释
         self.comment: Dict[str: "Word.Comment"] = {}  # 注释
+        if box < 1 or box > 5:
+            box = 1
+        self.box = box
 
 
     def add_comment(self, c: Comment):
     def add_comment(self, c: Comment):
         if self.comment.get(c.english) is None:
         if self.comment.get(c.english) is None:
             self.comment[c.english] = c
             self.comment[c.english] = c
 
 
+    def set_box(self, box: int):
+        if 0 < box < 6:
+            self.box = box
+
     def __str__(self):
     def __str__(self):
         ret = f"{self.name}:\n"
         ret = f"{self.name}:\n"
         for i in self.comment:
         for i in self.comment:

+ 1 - 0
templates/test.html

@@ -15,6 +15,7 @@
                 <div class="tab-pane fade" id="word">
                 <div class="tab-pane fade" id="word">
                     {% if have_word %}
                     {% if have_word %}
                         <p class="text-center h2"> <u> {{ word.name }} </u> </p>
                         <p class="text-center h2"> <u> {{ word.name }} </u> </p>
+                        <p class="h5 text-center"> Box: {{ word.box }} </p>
                         <div class="col-12 col-lg-6 offset-lg-3">
                         <div class="col-12 col-lg-6 offset-lg-3">
                             {% for w in word.comment %}
                             {% for w in word.comment %}
                                 <p class="h6 text-left">
                                 <p class="h6 text-left">