Esempio 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.from_mongo(blog['id'])
         return True
     else:
         return False
Esempio n. 2
0
    def 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'])
Esempio n. 3
0
 def from_mongo(cls, id):
     # Post.from_mongo('123')
     post_data = Database.find_one(collection='posts', 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'],
                id=post_data['id'])  # return a instance of Post class
Esempio n. 4
0
 def from_blog(id):
     return [
         post for post in Database.find(collection='posts',
                                        query={'blog_id': id})
     ]
Esempio n. 5
0
 def save_to_mongo(self):
     Database.insert(collection='posts', data=self.json())
Esempio n. 6
0
import pymongo
from basic_template.blog import Blog
from basic_template.menu import Menu
from basic_template.post import Post
from basic_template.database import Database

Database.initialize()

menu = Menu()

menu.run_menu()
Esempio n. 7
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']))