{"action":"created","comment":{"url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/comments/38084730","id":38084730,"diff_hunk":"@@ -0,0 +1,112 @@\n+import datetime\n+\n+from peewee import CharField, ForeignKeyField, DateTimeField, IntegerField\n+from flask_login import current_user\n+\n+from .base import BaseModel\n+from .user import User\n+\n+\n+class Magazine(BaseModel):\n+    create_time = DateTimeField(default=datetime.datetime.now)\n+    update_time = DateTimeField(default=datetime.datetime.now)\n+\n+    title = CharField(max_length=120)\n+    visits = IntegerField(default=0)\n+\n+    class Meta:\n+        pass\n+\n+    @classmethod\n+    def create_new(self, title):\n+        return Magazine.create(title=title)\n+\n+    @classmethod\n+    def all(self):\n+        return Magazine.select()\n+\n+    @classmethod\n+    def dump_all(self):\n+        magazines = Magazine.all()\n+        magazines_data = []\n+        for magazine in magazines:\n+            magazines_data.append(magazine.dump())\n+        return magazines_data\n+\n+    def update_posts(self, new_data):\n+        # remove old post\n+        query = MagazinePost.delete().where(MagazinePost.magazine == self.id)\n+        query.execute()\n+        # and new post\n+        for post_data in new_data:\n+            MagazinePost.create_new(\n+                user=current_user.id,\n+                magazine=self.id,\n+                title=post_data.get('title'),\n+                desc=post_data.get('desc'),\n+                url=post_data.get('url'),\n+                cover=post_data.get('cover'),\n+                category=post_data.get('category'),\n+                category_icon=post_data.get('categoryIcon'))\n+\n+    def update_visits(self):\n+        self.visits += 1\n+        self.save()\n+\n+    def dump(self):\n+        magazine_data = {}\n+        magazine_data['id'] = self.id\n+        magazine_data['title'] = self.title\n+        magazine_data['visits'] = self.visits\n+        magazine_data['posts'] = []\n+        magazine_data['create_time'] = self.create_time\n+        magazine_data['update_time'] = self.update_time\n+\n+        magazine_posts = self.posts\n+        for magazine_post in magazine_posts:\n+            magazine_data['posts'].append(magazine_post.dump())\n+        return magazine_data\n+\n+\n+class MagazinePost(BaseModel):\n+    create_time = DateTimeField(default=datetime.datetime.now)\n+    update_time = DateTimeField(default=datetime.datetime.now)\n+\n+    user = ForeignKeyField(User)\n+    magazine = ForeignKeyField(Magazine, related_name='posts')\n+    title = CharField(max_length=120)\n+    desc = CharField(max_length=400)\n+    url = CharField(max_length=200)\n+    cover = CharField(max_length=200)\n+    category = CharField(max_length=200)\n+    category_icon = CharField(max_length=200)\n+\n+    class Meta:","path":"simplecms/models/magazine.py","position":84,"original_position":84,"commit_id":"ed614a395733bf141959359fc0eb4593af84d740","original_commit_id":"ed614a395733bf141959359fc0eb4593af84d740","user":{"login":"gfreezy","id":510012,"avatar_url":"https://avatars.githubusercontent.com/u/510012?v=3","gravatar_id":"","url":"https://api.github.com/users/gfreezy","html_url":"https://github.com/gfreezy","followers_url":"https://api.github.com/users/gfreezy/followers","following_url":"https://api.github.com/users/gfreezy/following{/other_user}","gists_url":"https://api.github.com/users/gfreezy/gists{/gist_id}","starred_url":"https://api.github.com/users/gfreezy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gfreezy/subscriptions","organizations_url":"https://api.github.com/users/gfreezy/orgs","repos_url":"https://api.github.com/users/gfreezy/repos","events_url":"https://api.github.com/users/gfreezy/events{/privacy}","received_events_url":"https://api.github.com/users/gfreezy/received_events","type":"User","site_admin":false},"body":"去掉","created_at":"2015-08-27T11:20:39Z","updated_at":"2015-08-27T11:20:39Z","html_url":"https://github.com/xiachufang/simple-cms/pull/1#discussion_r38084730","pull_request_url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/comments/38084730"},"html":{"href":"https://github.com/xiachufang/simple-cms/pull/1#discussion_r38084730"},"pull_request":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1","id":43015351,"html_url":"https://github.com/xiachufang/simple-cms/pull/1","diff_url":"https://github.com/xiachufang/simple-cms/pull/1.diff","patch_url":"https://github.com/xiachufang/simple-cms/pull/1.patch","issue_url":"https://api.github.com/repos/xiachufang/simple-cms/issues/1","number":1,"state":"open","locked":false,"title":"粗略完成 simple-cms 的 JSON 数据部分的功能","user":{"login":"binderclip","id":8187479,"avatar_url":"https://avatars.githubusercontent.com/u/8187479?v=3","gravatar_id":"","url":"https://api.github.com/users/binderclip","html_url":"https://github.com/binderclip","followers_url":"https://api.github.com/users/binderclip/followers","following_url":"https://api.github.com/users/binderclip/following{/other_user}","gists_url":"https://api.github.com/users/binderclip/gists{/gist_id}","starred_url":"https://api.github.com/users/binderclip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binderclip/subscriptions","organizations_url":"https://api.github.com/users/binderclip/orgs","repos_url":"https://api.github.com/users/binderclip/repos","events_url":"https://api.github.com/users/binderclip/events{/privacy}","received_events_url":"https://api.github.com/users/binderclip/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-21T08:37:12Z","updated_at":"2015-08-27T11:20:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eacabdb950a8d61affb490bcadbe66db445c3de8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1/commits","review_comments_url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1/comments","review_comment_url":"https://api.github.com/repos/xiachufang/simple-cms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xiachufang/simple-cms/issues/1/comments","statuses_url":"https://api.github.com/repos/xiachufang/simple-cms/statuses/ed614a395733bf141959359fc0eb4593af84d740","head":{"label":"binderclip:master","ref":"master","sha":"ed614a395733bf141959359fc0eb4593af84d740","user":{"login":"binderclip","id":8187479,"avatar_url":"https://avatars.githubusercontent.com/u/8187479?v=3","gravatar_id":"","url":"https://api.github.com/users/binderclip","html_url":"https://github.com/binderclip","followers_url":"https://api.github.com/users/binderclip/followers","following_url":"https://api.github.com/users/binderclip/following{/other_user}","gists_url":"https://api.github.com/users/binderclip/gists{/gist_id}","starred_url":"https://api.github.com/users/binderclip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binderclip/subscriptions","organizations_url":"https://api.github.com/users/binderclip/orgs","repos_url":"https://api.github.com/users/binderclip/repos","events_url":"https://api.github.com/users/binderclip/events{/privacy}","received_events_url":"https://api.github.com/users/binderclip/received_events","type":"User","site_admin":false},"repo":{"id":41075446,"name":"simple-cms","full_name":"binderclip/simple-cms","owner":{"login":"binderclip","id":8187479,"avatar_url":"https://avatars.githubusercontent.com/u/8187479?v=3","gravatar_id":"","url":"https://api.github.com/users/binderclip","html_url":"https://github.com/binderclip","followers_url":"https://api.github.com/users/binderclip/followers","following_url":"https://api.github.com/users/binderclip/following{/other_user}","gists_url":"https://api.github.com/users/binderclip/gists{/gist_id}","starred_url":"https://api.github.com/users/binderclip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binderclip/subscriptions","organizations_url":"https://api.github.com/users/binderclip/orgs","repos_url":"https://api.github.com/users/binderclip/repos","events_url":"https://api.github.com/users/binderclip/events{/privacy}","received_events_url":"https://api.github.com/users/binderclip/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/binderclip/simple-cms","description":"Simple CMS","fork":true,"url":"https://api.github.com/repos/binderclip/simple-cms","forks_url":"https://api.github.com/repos/binderclip/simple-cms/forks","keys_url":"https://api.github.com/repos/binderclip/simple-cms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/binderclip/simple-cms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/binderclip/simple-cms/teams","hooks_url":"https://api.github.com/repos/binderclip/simple-cms/hooks","issue_events_url":"https://api.github.com/repos/binderclip/simple-cms/issues/events{/number}","events_url":"https://api.github.com/repos/binderclip/simple-cms/events","assignees_url":"https://api.github.com/repos/binderclip/simple-cms/assignees{/user}","branches_url":"https://api.github.com/repos/binderclip/simple-cms/branches{/branch}","tags_url":"https://api.github.com/repos/binderclip/simple-cms/tags","blobs_url":"https://api.github.com/repos/binderclip/simple-cms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/binderclip/simple-cms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/binderclip/simple-cms/git/refs{/sha}","trees_url":"https://api.github.com/repos/binderclip/simple-cms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/binderclip/simple-cms/statuses/{sha}","languages_url":"https://api.github.com/repos/binderclip/simple-cms/languages","stargazers_url":"https://api.github.com/repos/binderclip/simple-cms/stargazers","contributors_url":"https://api.github.com/repos/binderclip/simple-cms/contributors","subscribers_url":"https://api.github.com/repos/binderclip/simple-cms/subscribers","subscription_url":"https://api.github.com/repos/binderclip/simple-cms/subscription","commits_url":"https://api.github.com/repos/binderclip/simple-cms/commits{/sha}","git_commits_url":"https://api.github.com/repos/binderclip/simple-cms/git/commits{/sha}","comments_url":"https://api.github.com/repos/binderclip/simple-cms/comments{/number}","issue_comment_url":"https://api.github.com/repos/binderclip/simple-cms/issues/comments{/number}","contents_url":"https://api.github.com/repos/binderclip/simple-cms/contents/{+path}","compare_url":"https://api.github.com/repos/binderclip/simple-cms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/binderclip/simple-cms/merges","archive_url":"https://api.github.com/repos/binderclip/simple-cms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/binderclip/simple-cms/downloads","issues_url":"https://api.github.com/repos/binderclip/simple-cms/issues{/number}","pulls_url":"https://api.github.com/repos/binderclip/simple-cms/pulls{/number}","milestones_url":"https://api.github.com/repos/binderclip/simple-cms/milestones{/number}","notifications_url":"https://api.github.com/repos/binderclip/simple-cms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/binderclip/simple-cms/labels{/name}","releases_url":"https://api.github.com/repos/binderclip/simple-cms/releases{/id}","created_at":"2015-08-20T04:29:32Z","updated_at":"2015-08-21T08:25:09Z","pushed_at":"2015-08-27T07:27:32Z","git_url":"git://github.com/binderclip/simple-cms.git","ssh_url":"git@github.com:binderclip/simple-cms.git","clone_url":"https://github.com/binderclip/simple-cms.git","svn_url":"https://github.com/binderclip/simple-cms","homepage":"","size":162,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xiachufang:master","ref":"master","sha":"47f19d7e2eb90420ab30dff5787f43061b14418f","user":{"login":"xiachufang","id":990080,"avatar_url":"https://avatars.githubusercontent.com/u/990080?v=3","gravatar_id":"","url":"https://api.github.com/users/xiachufang","html_url":"https://github.com/xiachufang","followers_url":"https://api.github.com/users/xiachufang/followers","following_url":"https://api.github.com/users/xiachufang/following{/other_user}","gists_url":"https://api.github.com/users/xiachufang/gists{/gist_id}","starred_url":"https://api.github.com/users/xiachufang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiachufang/subscriptions","organizations_url":"https://api.github.com/users/xiachufang/orgs","repos_url":"https://api.github.com/users/xiachufang/repos","events_url":"https://api.github.com/users/xiachufang/events{/privacy}","received_events_url":"https://api.github.com/users/xiachufang/received_events","type":"Organization","site_admin":false},"repo":{"id":41075083,"name":"simple-cms","full_name":"xiachufang/simple-cms","owner":{"login":"xiachufang","id":990080,"avatar_url":"https://avatars.githubusercontent.com/u/990080?v=3","gravatar_id":"","url":"https://api.github.com/users/xiachufang","html_url":"https://github.com/xiachufang","followers_url":"https://api.github.com/users/xiachufang/followers","following_url":"https://api.github.com/users/xiachufang/following{/other_user}","gists_url":"https://api.github.com/users/xiachufang/gists{/gist_id}","starred_url":"https://api.github.com/users/xiachufang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiachufang/subscriptions","organizations_url":"https://api.github.com/users/xiachufang/orgs","repos_url":"https://api.github.com/users/xiachufang/repos","events_url":"https://api.github.com/users/xiachufang/events{/privacy}","received_events_url":"https://api.github.com/users/xiachufang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xiachufang/simple-cms","description":"","fork":false,"url":"https://api.github.com/repos/xiachufang/simple-cms","forks_url":"https://api.github.com/repos/xiachufang/simple-cms/forks","keys_url":"https://api.github.com/repos/xiachufang/simple-cms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xiachufang/simple-cms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xiachufang/simple-cms/teams","hooks_url":"https://api.github.com/repos/xiachufang/simple-cms/hooks","issue_events_url":"https://api.github.com/repos/xiachufang/simple-cms/issues/events{/number}","events_url":"https://api.github.com/repos/xiachufang/simple-cms/events","assignees_url":"https://api.github.com/repos/xiachufang/simple-cms/assignees{/user}","branches_url":"https://api.github.com/repos/xiachufang/simple-cms/branches{/branch}","tags_url":"https://api.github.com/repos/xiachufang/simple-cms/tags","blobs_url":"https://api.github.com/repos/xiachufang/simple-cms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xiachufang/simple-cms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xiachufang/simple-cms/git/refs{/sha}","trees_url":"https://api.github.com/repos/xiachufang/simple-cms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xiachufang/simple-cms/statuses/{sha}","languages_url":"https://api.github.com/repos/xiachufang/simple-cms/languages","stargazers_url":"https://api.github.com/repos/xiachufang/simple-cms/stargazers","contributors_url":"https://api.github.com/repos/xiachufang/simple-cms/contributors","subscribers_url":"https://api.github.com/repos/xiachufang/simple-cms/subscribers","subscription_url":"https://api.github.com/repos/xiachufang/simple-cms/subscription","commits_url":"https://api.github.com/repos/xiachufang/simple-cms/commits{/sha}","git_commits_url":"https://api.github.com/repos/xiachufang/simple-cms/git/commits{/sha}","comments_url":"https://api.github.com/repos/xiachufang/simple-cms/comments{/number}","issue_comment_url":"https://api.github.com/repos/xiachufang/simple-cms/issues/comments{/number}","contents_url":"https://api.github.com/repos/xiachufang/simple-cms/contents/{+path}","compare_url":"https://api.github.com/repos/xiachufang/simple-cms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xiachufang/simple-cms/merges","archive_url":"https://api.github.com/repos/xiachufang/simple-cms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xiachufang/simple-cms/downloads","issues_url":"https://api.github.com/repos/xiachufang/simple-cms/issues{/number}","pulls_url":"https://api.github.com/repos/xiachufang/simple-cms/pulls{/number}","milestones_url":"https://api.github.com/repos/xiachufang/simple-cms/milestones{/number}","notifications_url":"https://api.github.com/repos/xiachufang/simple-cms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xiachufang/simple-cms/labels{/name}","releases_url":"https://api.github.com/repos/xiachufang/simple-cms/releases{/id}","created_at":"2015-08-20T04:18:02Z","updated_at":"2015-08-20T04:18:02Z","pushed_at":"2015-08-27T07:27:33Z","git_url":"git://github.com/xiachufang/simple-cms.git","ssh_url":"git@github.com:xiachufang/simple-cms.git","clone_url":"https://github.com/xiachufang/simple-cms.git","svn_url":"https://github.com/xiachufang/simple-cms","homepage":null,"size":352,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1"},"html":{"href":"https://github.com/xiachufang/simple-cms/pull/1"},"issue":{"href":"https://api.github.com/repos/xiachufang/simple-cms/issues/1"},"comments":{"href":"https://api.github.com/repos/xiachufang/simple-cms/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xiachufang/simple-cms/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/xiachufang/simple-cms/statuses/ed614a395733bf141959359fc0eb4593af84d740"}}}}