{"action":"created","comment":{"url":"https://api.github.com/repos/torchbox/wagtail/pulls/comments/51350655","id":51350655,"diff_hunk":"@@ -12,31 +12,55 @@\n from wagtail.wagtailcore.blocks import Block, StreamBlock, StreamValue, BlockField\n \n \n-class RichTextArea(WidgetWithScript, forms.Textarea):\n+class BaseTextAreaWidget(WidgetWithScript, forms.Textarea):\n+\n+    def __init__(self, editor_config=None, **kwargs):\n+        # set the base editor configuration if existent\n+        self.editor_config = editor_config\n+        super(BaseTextAreaWidget, self).__init__(**kwargs)\n+\n     def get_panel(self):\n-        from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel\n-        return RichTextFieldPanel\n+        raise NotImplementedError(\n+            \"Class %s doesn't implement a required Method()\" % (self.__class__.__name__))\n \n     def render(self, name, value, attrs=None):\n         if value is None:\n             translated_value = None\n         else:\n             translated_value = expand_db_html(value, for_editor=True)\n-        return super(RichTextArea, self).render(name, translated_value, attrs)\n-\n-    def render_js_init(self, id_, name, value):\n-        return \"makeRichTextEditable({0});\".format(json.dumps(id_))\n+        return super(BaseTextAreaWidget, self).render(name, translated_value, attrs)\n \n     def value_from_datadict(self, data, files, name):\n-        original_value = super(RichTextArea, self).value_from_datadict(data, files, name)\n+        original_value = super(BaseTextAreaWidget, self).value_from_datadict(data, files, name)\n         if original_value is None:\n             return None\n         return DbWhitelister.clean(original_value)\n \n+    class Meta:\n+        abstract = True\n+\n+\n+class RichTextArea(BaseTextAreaWidget):\n+\n+    def get_panel(self):\n+        from wagtail.wagtailadmin.edit_handlers import RichTextFieldPanel\n+        return RichTextFieldPanel\n+\n+    def render_js_init(self, id_, name, value):\n+        return \"makeRichTextEditable({0}, {1});\".format(json.dumps(id_), json.dumps(self.editor_config))\n+\n \n class RichTextField(models.TextField):\n+\n+    def __init__(self, widget=None, **kwargs):\n+        self.widget = widget\n+        super(RichTextField, self).__init__(**kwargs)\n+\n     def formfield(self, **kwargs):\n-        defaults = {'widget': RichTextArea}\n+        # check if a custom widget has been passed or use default\n+        if not self.widget:\n+            self.widget = RichTextArea","path":"wagtail/wagtailcore/fields.py","position":null,"original_position":60,"commit_id":"35550362f4ff5d772e701a526cd700df5f84bbae","original_commit_id":"9a106e7a72da72ddb17c0ff1549604a1add4a2e3","user":{"login":"HitDaCa","id":2290450,"avatar_url":"https://avatars.githubusercontent.com/u/2290450?v=3","gravatar_id":"","url":"https://api.github.com/users/HitDaCa","html_url":"https://github.com/HitDaCa","followers_url":"https://api.github.com/users/HitDaCa/followers","following_url":"https://api.github.com/users/HitDaCa/following{/other_user}","gists_url":"https://api.github.com/users/HitDaCa/gists{/gist_id}","starred_url":"https://api.github.com/users/HitDaCa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HitDaCa/subscriptions","organizations_url":"https://api.github.com/users/HitDaCa/orgs","repos_url":"https://api.github.com/users/HitDaCa/repos","events_url":"https://api.github.com/users/HitDaCa/events{/privacy}","received_events_url":"https://api.github.com/users/HitDaCa/received_events","type":"User","site_admin":false},"body":"I've updated this code following the same pattern described in [#2175 (comment)](https://github.com/torchbox/wagtail/pull/2175#discussion_r51350568). \r\nOpen for suggestions to solve this differently though.","created_at":"2016-01-30T20:49:40Z","updated_at":"2016-01-30T20:49:40Z","html_url":"https://github.com/torchbox/wagtail/pull/2175#discussion_r51350655","pull_request_url":"https://api.github.com/repos/torchbox/wagtail/pulls/2175","_links":{"self":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/comments/51350655"},"html":{"href":"https://github.com/torchbox/wagtail/pull/2175#discussion_r51350655"},"pull_request":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/2175"}}},"pull_request":{"url":"https://api.github.com/repos/torchbox/wagtail/pulls/2175","id":57726153,"html_url":"https://github.com/torchbox/wagtail/pull/2175","diff_url":"https://github.com/torchbox/wagtail/pull/2175.diff","patch_url":"https://github.com/torchbox/wagtail/pull/2175.patch","issue_url":"https://api.github.com/repos/torchbox/wagtail/issues/2175","number":2175,"state":"open","locked":false,"title":"Added possibility to pass custom widget with editor configuration through widget attribute on RichTextField and RichTextBlock","user":{"login":"HitDaCa","id":2290450,"avatar_url":"https://avatars.githubusercontent.com/u/2290450?v=3","gravatar_id":"","url":"https://api.github.com/users/HitDaCa","html_url":"https://github.com/HitDaCa","followers_url":"https://api.github.com/users/HitDaCa/followers","following_url":"https://api.github.com/users/HitDaCa/following{/other_user}","gists_url":"https://api.github.com/users/HitDaCa/gists{/gist_id}","starred_url":"https://api.github.com/users/HitDaCa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HitDaCa/subscriptions","organizations_url":"https://api.github.com/users/HitDaCa/orgs","repos_url":"https://api.github.com/users/HitDaCa/repos","events_url":"https://api.github.com/users/HitDaCa/events{/privacy}","received_events_url":"https://api.github.com/users/HitDaCa/received_events","type":"User","site_admin":false},"body":"This pull requests replaces the original pull request [#2139](https://github.com/torchbox/wagtail/pull/2139). I had wrongly rebased to latest master before adding later changes which made code compare unusable (trying to remove rebase closed the original request).\r\n\r\nFollowing the advice from @m1kola & @JoshBarr [#2139 (comment)](https://github.com/torchbox/wagtail/pull/2139#discussion-diff-51297640), RichtTextFields and StreamField RichTextBlocks now accept a **widget** attribute. By default, if none is passed, the standard RichTextArea widget is used.\r\n\r\nFollowing @JoshBarr comment about easily configuring various RichText widgets in future, I have also moved the immutable parts of the RichTextArea into it's own abstract base class. This allows easier creation of future RichTextWidget variations.\r\n\r\n```python\r\nfrom wagtail.wagtailcore.fields import RichTextField\r\nfrom wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel\r\n\r\nfrom wagtail.wagtailcore.blocks import RichTextBlock\r\nfrom wagtail.wagtailcore.fields import StreamField\r\n\r\nfrom wagtail.wagtailcore.fields import RichTextArea\r\n\r\nsimple_config = {\r\n    'halloheadings': {\r\n        'formatBlocks': ['p', 'h1']\r\n    },\r\n    'halloformat': {\r\n        'formattings': {\r\n            \"bold\": False,\r\n            \"italic\": False,\r\n        },\r\n    },\r\n    'hallowagtaildoclink': {},\r\n    'hallolists': {\r\n        \"lists\": {\r\n            \"ordered\": False,\r\n            \"unordered\": False\r\n        }\r\n    },\r\n    'hallowagtaillink': {},\r\n    'hallorequireparagraphs': {}\r\n}\r\n\r\ncomplex_config = {\r\n    'halloheadings': {\r\n        'formatBlocks': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']\r\n    },\r\n    'halloformat': {\r\n        'formattings': {\r\n            \"bold\": True,\r\n            \"italic\": True,\r\n        },\r\n    },\r\n    'hallowagtaildoclink': {},\r\n    'hallolists': {\r\n        \"lists\": {\r\n            \"ordered\": True,\r\n            \"unordered\": True\r\n        }\r\n    },\r\n    'hallowagtaillink': {},\r\n    'hallorequireparagraphs': {}\r\n}\r\n\r\nclass BookPage(Page):\r\n    book_text = RichTextField(widget=RichTextArea(editor_config=simple_config))\r\n    page_content= StreamField([\r\n        ('excerpt', RichTextBlock(required=False, widget=RichTextArea(editor_config=simple_config))),\r\n        ('paragraph', RichTextBlock(required=False, widget=RichTextArea(editor_config=complex_config)))\r\n    ])    \r\n    content_panels = Page.content_panels + [\r\n        FieldPanel('book_text', classname=\"full\"),\r\n        StreamFieldPanel('page_content')\r\n    ]\r\n```  \r\n\r\nI have also updated the RichTextField documentation and RichTextBlock documentation to explain this new attribute addition.\r\n\r\nI have added a test for the new attribute.","created_at":"2016-01-30T01:54:20Z","updated_at":"2016-01-30T20:49:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"12cca15209f4a3fa1de86c0454a46aa55b724e7f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/torchbox/wagtail/pulls/2175/commits","review_comments_url":"https://api.github.com/repos/torchbox/wagtail/pulls/2175/comments","review_comment_url":"https://api.github.com/repos/torchbox/wagtail/pulls/comments{/number}","comments_url":"https://api.github.com/repos/torchbox/wagtail/issues/2175/comments","statuses_url":"https://api.github.com/repos/torchbox/wagtail/statuses/35550362f4ff5d772e701a526cd700df5f84bbae","head":{"label":"HitDaCa:feature/added-widget-attrtibute-richtextarea","ref":"feature/added-widget-attrtibute-richtextarea","sha":"35550362f4ff5d772e701a526cd700df5f84bbae","user":{"login":"HitDaCa","id":2290450,"avatar_url":"https://avatars.githubusercontent.com/u/2290450?v=3","gravatar_id":"","url":"https://api.github.com/users/HitDaCa","html_url":"https://github.com/HitDaCa","followers_url":"https://api.github.com/users/HitDaCa/followers","following_url":"https://api.github.com/users/HitDaCa/following{/other_user}","gists_url":"https://api.github.com/users/HitDaCa/gists{/gist_id}","starred_url":"https://api.github.com/users/HitDaCa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HitDaCa/subscriptions","organizations_url":"https://api.github.com/users/HitDaCa/orgs","repos_url":"https://api.github.com/users/HitDaCa/repos","events_url":"https://api.github.com/users/HitDaCa/events{/privacy}","received_events_url":"https://api.github.com/users/HitDaCa/received_events","type":"User","site_admin":false},"repo":{"id":50067739,"name":"wagtail","full_name":"HitDaCa/wagtail","owner":{"login":"HitDaCa","id":2290450,"avatar_url":"https://avatars.githubusercontent.com/u/2290450?v=3","gravatar_id":"","url":"https://api.github.com/users/HitDaCa","html_url":"https://github.com/HitDaCa","followers_url":"https://api.github.com/users/HitDaCa/followers","following_url":"https://api.github.com/users/HitDaCa/following{/other_user}","gists_url":"https://api.github.com/users/HitDaCa/gists{/gist_id}","starred_url":"https://api.github.com/users/HitDaCa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HitDaCa/subscriptions","organizations_url":"https://api.github.com/users/HitDaCa/orgs","repos_url":"https://api.github.com/users/HitDaCa/repos","events_url":"https://api.github.com/users/HitDaCa/events{/privacy}","received_events_url":"https://api.github.com/users/HitDaCa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HitDaCa/wagtail","description":"A Django content management system focused on flexibility and user experience","fork":true,"url":"https://api.github.com/repos/HitDaCa/wagtail","forks_url":"https://api.github.com/repos/HitDaCa/wagtail/forks","keys_url":"https://api.github.com/repos/HitDaCa/wagtail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HitDaCa/wagtail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HitDaCa/wagtail/teams","hooks_url":"https://api.github.com/repos/HitDaCa/wagtail/hooks","issue_events_url":"https://api.github.com/repos/HitDaCa/wagtail/issues/events{/number}","events_url":"https://api.github.com/repos/HitDaCa/wagtail/events","assignees_url":"https://api.github.com/repos/HitDaCa/wagtail/assignees{/user}","branches_url":"https://api.github.com/repos/HitDaCa/wagtail/branches{/branch}","tags_url":"https://api.github.com/repos/HitDaCa/wagtail/tags","blobs_url":"https://api.github.com/repos/HitDaCa/wagtail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HitDaCa/wagtail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HitDaCa/wagtail/git/refs{/sha}","trees_url":"https://api.github.com/repos/HitDaCa/wagtail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HitDaCa/wagtail/statuses/{sha}","languages_url":"https://api.github.com/repos/HitDaCa/wagtail/languages","stargazers_url":"https://api.github.com/repos/HitDaCa/wagtail/stargazers","contributors_url":"https://api.github.com/repos/HitDaCa/wagtail/contributors","subscribers_url":"https://api.github.com/repos/HitDaCa/wagtail/subscribers","subscription_url":"https://api.github.com/repos/HitDaCa/wagtail/subscription","commits_url":"https://api.github.com/repos/HitDaCa/wagtail/commits{/sha}","git_commits_url":"https://api.github.com/repos/HitDaCa/wagtail/git/commits{/sha}","comments_url":"https://api.github.com/repos/HitDaCa/wagtail/comments{/number}","issue_comment_url":"https://api.github.com/repos/HitDaCa/wagtail/issues/comments{/number}","contents_url":"https://api.github.com/repos/HitDaCa/wagtail/contents/{+path}","compare_url":"https://api.github.com/repos/HitDaCa/wagtail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HitDaCa/wagtail/merges","archive_url":"https://api.github.com/repos/HitDaCa/wagtail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HitDaCa/wagtail/downloads","issues_url":"https://api.github.com/repos/HitDaCa/wagtail/issues{/number}","pulls_url":"https://api.github.com/repos/HitDaCa/wagtail/pulls{/number}","milestones_url":"https://api.github.com/repos/HitDaCa/wagtail/milestones{/number}","notifications_url":"https://api.github.com/repos/HitDaCa/wagtail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HitDaCa/wagtail/labels{/name}","releases_url":"https://api.github.com/repos/HitDaCa/wagtail/releases{/id}","deployments_url":"https://api.github.com/repos/HitDaCa/wagtail/deployments","created_at":"2016-01-20T23:24:21Z","updated_at":"2016-01-20T23:24:24Z","pushed_at":"2016-01-30T20:41:19Z","git_url":"git://github.com/HitDaCa/wagtail.git","ssh_url":"git@github.com:HitDaCa/wagtail.git","clone_url":"https://github.com/HitDaCa/wagtail.git","svn_url":"https://github.com/HitDaCa/wagtail","homepage":"wagtail.io","size":25159,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"torchbox:master","ref":"master","sha":"0845f1e1c1122e6ec4a9d75d488a23ed3d834554","user":{"login":"torchbox","id":84015,"avatar_url":"https://avatars.githubusercontent.com/u/84015?v=3","gravatar_id":"","url":"https://api.github.com/users/torchbox","html_url":"https://github.com/torchbox","followers_url":"https://api.github.com/users/torchbox/followers","following_url":"https://api.github.com/users/torchbox/following{/other_user}","gists_url":"https://api.github.com/users/torchbox/gists{/gist_id}","starred_url":"https://api.github.com/users/torchbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/torchbox/subscriptions","organizations_url":"https://api.github.com/users/torchbox/orgs","repos_url":"https://api.github.com/users/torchbox/repos","events_url":"https://api.github.com/users/torchbox/events{/privacy}","received_events_url":"https://api.github.com/users/torchbox/received_events","type":"Organization","site_admin":false},"repo":{"id":16479108,"name":"wagtail","full_name":"torchbox/wagtail","owner":{"login":"torchbox","id":84015,"avatar_url":"https://avatars.githubusercontent.com/u/84015?v=3","gravatar_id":"","url":"https://api.github.com/users/torchbox","html_url":"https://github.com/torchbox","followers_url":"https://api.github.com/users/torchbox/followers","following_url":"https://api.github.com/users/torchbox/following{/other_user}","gists_url":"https://api.github.com/users/torchbox/gists{/gist_id}","starred_url":"https://api.github.com/users/torchbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/torchbox/subscriptions","organizations_url":"https://api.github.com/users/torchbox/orgs","repos_url":"https://api.github.com/users/torchbox/repos","events_url":"https://api.github.com/users/torchbox/events{/privacy}","received_events_url":"https://api.github.com/users/torchbox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/torchbox/wagtail","description":"A Django content management system focused on flexibility and user experience","fork":false,"url":"https://api.github.com/repos/torchbox/wagtail","forks_url":"https://api.github.com/repos/torchbox/wagtail/forks","keys_url":"https://api.github.com/repos/torchbox/wagtail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/torchbox/wagtail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/torchbox/wagtail/teams","hooks_url":"https://api.github.com/repos/torchbox/wagtail/hooks","issue_events_url":"https://api.github.com/repos/torchbox/wagtail/issues/events{/number}","events_url":"https://api.github.com/repos/torchbox/wagtail/events","assignees_url":"https://api.github.com/repos/torchbox/wagtail/assignees{/user}","branches_url":"https://api.github.com/repos/torchbox/wagtail/branches{/branch}","tags_url":"https://api.github.com/repos/torchbox/wagtail/tags","blobs_url":"https://api.github.com/repos/torchbox/wagtail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/torchbox/wagtail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/torchbox/wagtail/git/refs{/sha}","trees_url":"https://api.github.com/repos/torchbox/wagtail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/torchbox/wagtail/statuses/{sha}","languages_url":"https://api.github.com/repos/torchbox/wagtail/languages","stargazers_url":"https://api.github.com/repos/torchbox/wagtail/stargazers","contributors_url":"https://api.github.com/repos/torchbox/wagtail/contributors","subscribers_url":"https://api.github.com/repos/torchbox/wagtail/subscribers","subscription_url":"https://api.github.com/repos/torchbox/wagtail/subscription","commits_url":"https://api.github.com/repos/torchbox/wagtail/commits{/sha}","git_commits_url":"https://api.github.com/repos/torchbox/wagtail/git/commits{/sha}","comments_url":"https://api.github.com/repos/torchbox/wagtail/comments{/number}","issue_comment_url":"https://api.github.com/repos/torchbox/wagtail/issues/comments{/number}","contents_url":"https://api.github.com/repos/torchbox/wagtail/contents/{+path}","compare_url":"https://api.github.com/repos/torchbox/wagtail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/torchbox/wagtail/merges","archive_url":"https://api.github.com/repos/torchbox/wagtail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/torchbox/wagtail/downloads","issues_url":"https://api.github.com/repos/torchbox/wagtail/issues{/number}","pulls_url":"https://api.github.com/repos/torchbox/wagtail/pulls{/number}","milestones_url":"https://api.github.com/repos/torchbox/wagtail/milestones{/number}","notifications_url":"https://api.github.com/repos/torchbox/wagtail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/torchbox/wagtail/labels{/name}","releases_url":"https://api.github.com/repos/torchbox/wagtail/releases{/id}","deployments_url":"https://api.github.com/repos/torchbox/wagtail/deployments","created_at":"2014-02-03T12:41:59Z","updated_at":"2016-01-30T14:12:00Z","pushed_at":"2016-01-30T20:41:20Z","git_url":"git://github.com/torchbox/wagtail.git","ssh_url":"git@github.com:torchbox/wagtail.git","clone_url":"https://github.com/torchbox/wagtail.git","svn_url":"https://github.com/torchbox/wagtail","homepage":"wagtail.io","size":32295,"stargazers_count":3232,"watchers_count":3232,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":541,"mirror_url":null,"open_issues_count":358,"forks":541,"open_issues":358,"watchers":3232,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/2175"},"html":{"href":"https://github.com/torchbox/wagtail/pull/2175"},"issue":{"href":"https://api.github.com/repos/torchbox/wagtail/issues/2175"},"comments":{"href":"https://api.github.com/repos/torchbox/wagtail/issues/2175/comments"},"review_comments":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/2175/comments"},"review_comment":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/torchbox/wagtail/pulls/2175/commits"},"statuses":{"href":"https://api.github.com/repos/torchbox/wagtail/statuses/35550362f4ff5d772e701a526cd700df5f84bbae"}}}}