def user_article_info(user: User, article: Article, with_content=False, with_translations=True): from zeeguu_core.model import UserArticle prior_info = UserArticle.find(user, article) ua_info = article.article_info(with_content=with_content) if not prior_info: ua_info['starred'] = False ua_info['opened'] = False ua_info['liked'] = False ua_info['translations'] = [] return ua_info ua_info['starred'] = prior_info.starred is not None ua_info['opened'] = prior_info.opened is not None ua_info['liked'] = prior_info.liked if with_translations: translations = Bookmark.find_all_for_user_and_url(user, article.url) ua_info['translations'] = [ each.serializable_dictionary() for each in translations ] return ua_info
def test_bookmarks_in_url(self): random_bookmark = BookmarkRule(self.user).bookmark url = random_bookmark.text.url # each bookmark belongs to a random text / url so the # combo of user/url will always result in one bookmark assert 1 == len(Bookmark.find_all_for_user_and_url(self.user, url))
def user_article_info(cls, user: User, article: Article, with_content=False, with_translations=True): from zeeguu_core.model import Bookmark # Initialize returned info with the default article info returned_info = article.article_info(with_content=with_content) user_article_info = UserArticle.find(user, article) if not user_article_info: returned_info['starred'] = False returned_info['opened'] = False returned_info['liked'] = False returned_info['translations'] = [] return returned_info returned_info['starred'] = user_article_info.starred is not None returned_info['opened'] = user_article_info.opened is not None returned_info['liked'] = user_article_info.liked if with_translations: translations = Bookmark.find_all_for_user_and_url( user, article.url) returned_info['translations'] = [ each.serializable_dictionary() for each in translations ] return returned_info