aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newspipe/controllers/bookmark.py3
-rw-r--r--newspipe/models/bookmark.py15
-rw-r--r--newspipe/models/user.py7
-rw-r--r--newspipe/web/views/bookmark.py8
4 files changed, 24 insertions, 9 deletions
diff --git a/newspipe/controllers/bookmark.py b/newspipe/controllers/bookmark.py
index be67614d..08c8256f 100644
--- a/newspipe/controllers/bookmark.py
+++ b/newspipe/controllers/bookmark.py
@@ -14,6 +14,9 @@ class BookmarkController(AbstractController):
def count_by_href(self, **filters):
return self._count_by(Bookmark.href, filters)
+ def read_ordered(self, **filters):
+ return super().read(**filters).order_by(Bookmark.time.desc())
+
def update(self, filters, attrs):
BookmarkTagController(self.user_id).read(
**{"bookmark_id": filters["id"]}
diff --git a/newspipe/models/bookmark.py b/newspipe/models/bookmark.py
index ee89ffe5..a008ff07 100644
--- a/newspipe/models/bookmark.py
+++ b/newspipe/models/bookmark.py
@@ -52,12 +52,19 @@ class Bookmark(db.Model, RightMixin):
user_id = db.Column(db.Integer(), db.ForeignKey("user.id"))
# relationships
+ # tags = db.relationship(
+ # BookmarkTag,
+ # backref="of_bookmark",
+ # lazy="dynamic",
+ # cascade="all,delete-orphan",
+ # order_by=desc(BookmarkTag.text),
+ # )
tags = db.relationship(
- BookmarkTag,
- backref="of_bookmark",
- lazy="dynamic",
+ "BookmarkTag",
+ back_populates="bookmark",
cascade="all,delete-orphan",
- order_by=desc(BookmarkTag.text),
+ lazy=False,
+ foreign_keys="[BookmarkTag.bookmark_id]",
)
tags_proxy = association_proxy("tags", "text")
diff --git a/newspipe/models/user.py b/newspipe/models/user.py
index d051b9a2..b17496a2 100644
--- a/newspipe/models/user.py
+++ b/newspipe/models/user.py
@@ -36,6 +36,7 @@ from werkzeug.security import check_password_hash
from newspipe.bootstrap import db
from newspipe.models.category import Category
from newspipe.models.feed import Feed
+from newspipe.models.bookmark import Bookmark
from newspipe.models.right_mixin import RightMixin
@@ -76,6 +77,12 @@ class User(db.Model, UserMixin, RightMixin):
cascade="all, delete-orphan",
foreign_keys=[Feed.user_id],
)
+ bookmarks = db.relationship(
+ "Bookmark",
+ backref="user",
+ cascade="all, delete-orphan",
+ foreign_keys=[Bookmark.user_id],
+ )
@staticmethod
def _fields_base_write():
diff --git a/newspipe/web/views/bookmark.py b/newspipe/web/views/bookmark.py
index acfaa007..ccb2cbe0 100644
--- a/newspipe/web/views/bookmark.py
+++ b/newspipe/web/views/bookmark.py
@@ -40,7 +40,7 @@ from flask import (
from flask_babel import gettext
from flask_login import current_user, login_required
from flask_paginate import Pagination, get_page_args
-from sqlalchemy import desc
+from sqlalchemy import desc, text
from werkzeug.exceptions import BadRequest
from newspipe.bootstrap import db
@@ -93,12 +93,10 @@ def list_(per_page, status="all"):
filters["shared"] = True
bookmarks = (
- BookmarkController(user_id).read(**filters).order_by(desc("time")).limit(1000)
+ BookmarkController(user_id).read_ordered(**filters).limit(1000)
+ # BookmarkController(user_id).read(**filters).limit(1000)
)
- # tag_contr = BookmarkTagController(user_id)
- # tag_contr.read().join(bookmarks).all()
-
page, per_page, offset = get_page_args()
pagination = Pagination(
page=page,
bgstack15