ソースを参照

feat: 显示最后出现的单词

SongZihuan 3 年 前
コミット
5bb6673ea7
3 ファイル変更23 行追加6 行削除
  1. 8 1
      app/test.py
  2. 12 3
      app/user.py
  3. 3 2
      templates/test.html

+ 8 - 1
app/test.py

@@ -40,7 +40,7 @@ class UploadFileForm(FlaskForm):
 def __load_word(word, search_from: SearchForm, reset_delete_form: ResetDeleteForm, upload_form: UploadFileForm):
 def __load_word(word, search_from: SearchForm, reset_delete_form: ResetDeleteForm, upload_form: UploadFileForm):
     user: UserWordDataBase = current_user
     user: UserWordDataBase = current_user
     box, box_distinct, box_sum, box_sum_distinct = user.get_box_count()
     box, box_distinct, box_sum, box_sum_distinct = user.get_box_count()
-    right_count, wrong_count, history = user.get_history_info()
+    right_count, wrong_count, history_list = user.get_history_info()
     job: Upload = Upload.upload.get(user.user)
     job: Upload = Upload.upload.get(user.user)
     if Upload.upload.get(user.user) is not None:
     if Upload.upload.get(user.user) is not None:
         if job.is_alive():
         if job.is_alive():
@@ -52,6 +52,13 @@ def __load_word(word, search_from: SearchForm, reset_delete_form: ResetDeleteFor
     else:
     else:
         have_job = False
         have_job = False
 
 
+    history_len = len(history_list)
+    if history_len == 0:
+        history = ""
+    else:
+        if history_len > 3:
+            history_list = history_list[:3]
+        history = f"Last word is: {', '.join(history_list)}"
     template_var = dict(word=word, len=len, right_count=right_count, wrong_count=wrong_count, history=history,
     template_var = dict(word=word, len=len, right_count=right_count, wrong_count=wrong_count, history=history,
                         box=box, box_distinct=box_distinct, box_sum=box_sum, box_sum_distinct=box_sum_distinct,
                         box=box, box_distinct=box_distinct, box_sum=box_sum, box_sum_distinct=box_sum_distinct,
                         have_job=have_job, search=search_from, reset_delete=reset_delete_form, upload=upload_form)
                         have_job=have_job, search=search_from, reset_delete=reset_delete_form, upload=upload_form)

+ 12 - 3
app/user.py

@@ -65,16 +65,21 @@ class UserWordDataBase(WordDatabase, UserMixin):
             self.set_value(4, 0)
             self.set_value(4, 0)
             self.set_value(5, "")
             self.set_value(5, "")
 
 
+    def rand_word(self):
+        w = super(UserWordDataBase, self).rand_word()
+        if w is None:
+            return None
+        self.__add_history_word(w.name)
+        return w
+
     def right_word(self, w: str):
     def right_word(self, w: str):
         self.check_time()
         self.check_time()
         self.set_value(3, int(self.get_value(3, 0)) + 1)
         self.set_value(3, int(self.get_value(3, 0)) + 1)
-        self.__add_history_word(w)
         return super(UserWordDataBase, self).right_word(w)
         return super(UserWordDataBase, self).right_word(w)
 
 
     def wrong_word(self, w: str):
     def wrong_word(self, w: str):
         self.check_time()
         self.check_time()
         self.set_value(4, int(self.get_value(4, 0)) + 1)
         self.set_value(4, int(self.get_value(4, 0)) + 1)
-        self.__add_history_word(w)
         return super(UserWordDataBase, self).wrong_word(w)
         return super(UserWordDataBase, self).wrong_word(w)
 
 
     def __add_history_word(self, w):
     def __add_history_word(self, w):
@@ -100,7 +105,11 @@ class UserWordDataBase(WordDatabase, UserMixin):
         self.check_time()
         self.check_time()
         right = int(self.get_value(3))
         right = int(self.get_value(3))
         wrong = int(self.get_value(4))
         wrong = int(self.get_value(4))
-        history = self.get_value(5, "").split(",")
+        history = self.get_value(5, "")
+        if len(history) == 0:
+            history = []
+        else:
+            history = self.get_value(5, "").split(",")[::-1]
         return right, wrong, history
         return right, wrong, history
 
 
     def reset(self):
     def reset(self):

+ 3 - 2
templates/test.html

@@ -139,8 +139,9 @@
                         <p class="col-12"> You have {{ box_sum_distinct }}({{ box_sum }}) word(s) in database. </p>
                         <p class="col-12"> You have {{ box_sum_distinct }}({{ box_sum }}) word(s) in database. </p>
                         <p class="col-12">
                         <p class="col-12">
                             Today, you have feedback {{ right_count + wrong_count }} word. <br>
                             Today, you have feedback {{ right_count + wrong_count }} word. <br>
-                            Right: {{ right_count }}, Wrong: {{ wrong_count }}. <br>
-                            Last word is '{{ history[-1] }}'.
+                            Right: {{ right_count }} <br>
+                            Wrong: {{ wrong_count }} <br>
+                            {{ history }}
                         </p>
                         </p>
 
 
                         <div class="col-12 text-center mb-2">
                         <div class="col-12 text-center mb-2">