def from_mongo_in_blog_object(cls, id): blog_data = Database.find_one(collection=Blog.COLLECTION_NAME, query={'id': id}) return cls(author=blog_data['author'], title=blog_data['title'], description=blog_data['description'], id=blog_data['id'])
def _user_has_account(self): blog = Database.find_one(Blog.COLLECTION_NAME, query={'author': self.user}) if blog is not None: self.user_blog = Blog.from_mongo_in_blog_object(blog['id']) return True else: return False
def from_mongo_in_post_object(cls, id): post_data = Database.find_one(collection=Post.COLLECTION_NAME, query={'id': id}) return cls(blog_id=post_data['blog_id'], title=post_data['title'], content=post_data['content'], author=post_data['author'], date=post_data['created_date'])
from blog_site.common.database import Database from blog_site.terminal_blog.model.menu import Menu __author__ = 'Prajesh Ananthan' Database.initialize() menu = Menu() menu.run_menu()
def save_to_mongo(self): Database.insert(User.COLLECTION_NAME, self.get_json())
def get_by_id(cls, _id): data = Database.find_one(User.COLLECTION_NAME, {"_id": _id}) if data is not None: return cls(**data)
def get_by_email(cls, email): data = Database.find_one(User.COLLECTION_NAME, {"email": email}) if data is not None: return cls(**data)
def _list_blogs(self): blogs = Database.find(Blog.COLLECTION_NAME, query={}) for blog in blogs: print("ID: {}\nTitle: {}\nAuthor: {}\n\n".format( blog['id'], blog['title'], blog['author']))
def find_author_by_id(cls, author_id): # will return content from Database not blog objects blogs = Database.find(Blog.COLLECTION_NAME, query={'author_id': author_id}) return [cls(**blog) for blog in blogs]
def from_mongo_in_blog_object(cls, _id): blog_data = Database.find_one(collection=Blog.COLLECTION_NAME, query={'_id': _id}) return cls(**blog_data)
def save_to_mongo(self): Database.insert(collection=Blog.COLLECTION_NAME, data=self.get_json())
def from_blog(id): return [ post for post in Database.find(collection=Post.COLLECTION_NAME, query={'blog_id': id}) ]
def from_mongo_in_post_object(cls, id): post_data = Database.find_one(collection=Post.COLLECTION_NAME, query={'id': id}) return cls(**post_data)
def init_database(): Database.initialize()