Peter Justin 3 лет назад
Родитель
Сommit
a8dde1da92
4 измененных файлов с 13 добавлено и 18 удалено
  1. 9 14
      flaskbb/utils/database.py
  2. 1 1
      requirements.txt
  3. 1 1
      setup.py
  4. 2 2
      tests/unit/test_forum_models.py

+ 9 - 14
flaskbb/utils/database.py

@@ -83,28 +83,26 @@ class UTCDateTime(db.TypeDecorator):
 
 
 class HideableQuery(BaseQuery):
+    _with_hidden = False
 
     def __new__(cls, *args, **kwargs):
-        inst = super(HideableQuery, cls).__new__(cls)
+        obj = super(HideableQuery, cls).__new__(cls)
         include_hidden = kwargs.pop("_with_hidden", False)
         has_view_hidden = current_user and current_user.permissions.get(
             "viewhidden", False
         )
-        with_hidden = include_hidden or has_view_hidden
+        obj._with_hidden = include_hidden or has_view_hidden
         if args or kwargs:
-            super(HideableQuery, inst).__init__(*args, **kwargs)
-            entity = inst._mapper_zero().class_
-            return inst.filter(
-                entity.hidden != True
-            ) if not with_hidden else inst
-        return inst
+            super(HideableQuery, obj).__init__(*args, **kwargs)
+            return obj.filter_by(hidden=False) if not obj._with_hidden else obj
+        return obj
 
     def __init__(self, *args, **kwargs):
         pass
 
     def with_hidden(self):
         return self.__class__(
-            db.class_mapper(self._mapper_zero().class_),
+            self._only_full_mapper_zero('get'),
             session=db.session(),
             _with_hidden=True,
         )
@@ -113,11 +111,8 @@ class HideableQuery(BaseQuery):
         return super(HideableQuery, self).get(*args, **kwargs)
 
     def get(self, *args, **kwargs):
-        include_hidden = kwargs.pop("include_hidden", False)
-        obj = self.with_hidden()._get(*args, **kwargs)
-        return obj if obj is not None and (
-            include_hidden or not obj.hidden
-        ) else None
+        obj = self.with_deleted()._get(*args, **kwargs)
+        return obj if obj is None and (self._with_hidden or not obj.hidden) else None
 
 
 class HideableMixin(object):

+ 1 - 1
requirements.txt

@@ -53,7 +53,7 @@ requests==2.26.0
 simplejson==3.17.3
 six==1.16.0
 speaklater==1.3
-SQLAlchemy==1.3.24
+SQLAlchemy==1.4.20
 SQLAlchemy-Utils==0.37.8
 Unidecode==1.2.0
 urllib3==1.26.6

+ 1 - 1
setup.py

@@ -40,7 +40,7 @@ install_requires = [
     "flask-redis>=0.4.0",
     "Flask-SQLAlchemy>=2.4.4",
     "Flask-Themes2>=0.1.5",
-    "flask-whooshee>=0.7.0",
+    "flask-whooshee @ git+https://github.com/sh4nks/flask-whooshee.git@fix-sqlalchemy-1-4#egg=flask-whooshee",
     "Flask-WTF>=0.14.3",
     "flaskbb-plugin-conversations>=1.0.7",
     "flaskbb-plugin-portal>=1.1.3",

+ 2 - 2
tests/unit/test_forum_models.py

@@ -645,7 +645,7 @@ def test_retrieving_hidden_posts(topic, user):
     new_post.hide(user)
 
     assert Post.query.get(new_post.id) is None
-    assert Post.query.get(new_post.id, include_hidden=True) == new_post
+    assert Post.query.with_hidden().get(new_post.id) == new_post
     assert Post.query.filter(Post.id == new_post.id).first() is None
     hidden_post = Post.query\
         .with_hidden()\
@@ -658,7 +658,7 @@ def test_retrieving_hidden_topics(topic, user):
     topic.hide(user)
 
     assert Topic.query.get(topic.id) is None
-    assert Topic.query.get(topic.id, include_hidden=True) == topic
+    assert Topic.query.with_hidden().get(topic.id) == topic
     assert Topic.query.filter(Topic.id == topic.id).first() is None
     hidden_topic = Topic.query\
         .with_hidden()\