Пример #1
0
 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'])
Пример #2
0
 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
Пример #3
0
 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'])
Пример #4
0
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()
Пример #5
0
 def save_to_mongo(self):
     Database.insert(User.COLLECTION_NAME, self.get_json())
Пример #6
0
 def get_by_id(cls, _id):
     data = Database.find_one(User.COLLECTION_NAME, {"_id": _id})
     if data is not None:
         return cls(**data)
Пример #7
0
 def get_by_email(cls, email):
     data = Database.find_one(User.COLLECTION_NAME, {"email": email})
     if data is not None:
         return cls(**data)
Пример #8
0
 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']))
Пример #9
0
 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]
Пример #10
0
 def from_mongo_in_blog_object(cls, _id):
     blog_data = Database.find_one(collection=Blog.COLLECTION_NAME, query={'_id': _id})
     return cls(**blog_data)
Пример #11
0
 def save_to_mongo(self):
     Database.insert(collection=Blog.COLLECTION_NAME, data=self.get_json())
Пример #12
0
 def from_blog(id):
     return [
         post for post in Database.find(collection=Post.COLLECTION_NAME,
                                        query={'blog_id': id})
     ]
Пример #13
0
 def from_mongo_in_post_object(cls, id):
     post_data = Database.find_one(collection=Post.COLLECTION_NAME,
                                   query={'id': id})
     return cls(**post_data)
Пример #14
0
def init_database():
    Database.initialize()