Ejemplo n.º 1
0
 def _user_has_account(self):
     blog = Database.find_one('blogs', {'author': self.user})
     if blog is not None:
         self.user_blog = Blog.get_from_mongo(blog['id'])
         return True
     else:
         return False
Ejemplo n.º 2
0
 def get_from_mongo(cls, id):
     blog_data = Database.find_one(collection='blogs',
                                   query={'id':id})
     return cls(author=blog_data['author'],
                 title=blog_data['title'],
                 description=blog_data['description'],
                 id=blog_data['id'])
Ejemplo n.º 3
0
 def from_mongo(cls, id):
    postdata = Database.find_one(collection = 'posts', query = {'id': id})
    return cls(blog_id=postdata['blog_id'],
               title=postdata['title'],
               content=postdata['content'],
               author=postdata['author'],
               created_date=postdata['created_date'],
               id=postdata['id'])
Ejemplo n.º 4
0
# from models.Blog import Blog
# from models.post import Post
from terminal_blog.database import Database
from terminal_blog.menu import Menu

Database.initialize()

# post = Post(blog_id="123",
#             title="First Post",
#             content="This is the first post made by Python for MongoDB",
#             author="Shubhraj")
# post.save_to_mongo()
# post = Post.from_mongo("_id_")
# posts = Post.from_blog("123")
#
# for post in posts:
#     print(post)

# blog = Blog(author="Shubhraj",
#             title="Sample Title",
#             description="Sample Description")
#
# blog.new_post()
# blog.save_to_mongo()
# from_database = Blog.get_from_mongo(blog.id)
# print(blog.get_posts()) #Post.from_blog(id)

menu = Menu()


def exit_status():
Ejemplo n.º 5
0
 def from_blog(blog_id):
     return [post for post in Database.find(collection = 'posts', query = {'blog_id': blog_id})]
Ejemplo n.º 6
0
 def save_to_mongo(self):
     Database.insert(collection='posts',
                     data=self.json())
Ejemplo n.º 7
0
 def from_blog(id):
     return [post for post in Database.find('posts', {'blog_id': id})]
Ejemplo n.º 8
0
 def from_mongo(cls, id):
     post_data = Database.find_one('posts', {'id': id})
     return cls(post_data['blog_id'], post_data['title'],
                post_data['content'], post_data['author'],
                post_data['created_id'], post_data['id'])
Ejemplo n.º 9
0
 def get_from_mongo(cls, id):
     blog_data = Database.find_one('blogs', {'id': id})
     return cls(blog_data['author'], blog_data['title'], blog_data['description'], blog_data['id'])
Ejemplo n.º 10
0
 def save_to_mongo(self):
     Database.insert('blogs', data=self.json())
Ejemplo n.º 11
0
 def _list_blogs(self):
     blogs = Database.find(collection='blogs', query={})
     for blog in blogs:
         print("ID: {}, Title: {}, Author: {}".format(
             blog['id'], blog['title'], blog['author']))