-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use real models and register them with the admin
- Loading branch information
Showing
7 changed files
with
47 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from testapp import models | ||
|
||
|
||
admin.register(models.ProseEditorModel) | ||
admin.register(models.SanitizedProseEditorModel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.db import models | ||
|
||
from django_prose_editor.fields import ProseEditorField | ||
from django_prose_editor.sanitized import SanitizedProseEditorField | ||
|
||
|
||
class ProseEditorModel(models.Model): | ||
description = ProseEditorField() | ||
|
||
def __str__(self): | ||
return self.description | ||
|
||
|
||
class SanitizedProseEditorModel(models.Model): | ||
description = SanitizedProseEditorField() | ||
|
||
def __str__(self): | ||
return self.description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,40 @@ | ||
from django import test | ||
from django.db import models | ||
from django.test.utils import isolate_apps | ||
|
||
from django_prose_editor.fields import ProseEditorField | ||
from django_prose_editor.sanitized import SanitizedProseEditorField | ||
from testapp.models import ProseEditorModel, SanitizedProseEditorModel | ||
|
||
|
||
class Test(test.TestCase): | ||
@isolate_apps() | ||
def test_standard_field(self): | ||
class Model(models.Model): | ||
description = ProseEditorField() | ||
|
||
def __str__(self): | ||
return self.description | ||
|
||
m = Model(description="<p></p>") | ||
m = ProseEditorModel(description="<p></p>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "") | ||
|
||
m = Model(description="<h1></h1>") | ||
m = ProseEditorModel(description="<h1></h1>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "") | ||
|
||
m = Model(description="<p>hello</p>") | ||
m = ProseEditorModel(description="<p>hello</p>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "<p>hello</p>") | ||
|
||
@isolate_apps() | ||
def test_sanitized_field(self): | ||
class Model(models.Model): | ||
description = SanitizedProseEditorField() | ||
|
||
def __str__(self): | ||
return self.description | ||
|
||
m = Model(description="<style>h1{color:red}</style><h1>Hello</h1>") | ||
m = SanitizedProseEditorModel( | ||
description="<style>h1{color:red}</style><h1>Hello</h1>" | ||
) | ||
m.full_clean() | ||
self.assertEqual(m.description, "<h1>Hello</h1>") | ||
|
||
m = Model(description="<p></p>") | ||
m = SanitizedProseEditorModel(description="<p></p>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "") | ||
|
||
m = Model(description="<h1></h1>") | ||
m = SanitizedProseEditorModel(description="<h1></h1>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "") | ||
|
||
m = Model(description="<p>hello</p>") | ||
m = SanitizedProseEditorModel(description="<p>hello</p>") | ||
m.full_clean() | ||
self.assertEqual(m.description, "<p>hello</p>") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
urlpatterns = [] | ||
from django.contrib import admin | ||
from django.urls import path | ||
|
||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
] |