Correctly get short body
This commit is contained in:
parent
5bf17f5fdc
commit
c94bfe50d1
3 changed files with 16 additions and 2 deletions
1
Pipfile
1
Pipfile
|
@ -15,6 +15,7 @@ whitenoise = "*"
|
||||||
waitress = "*"
|
waitress = "*"
|
||||||
wagtail-markdown = "*"
|
wagtail-markdown = "*"
|
||||||
wagtail-metadata = "*"
|
wagtail-metadata = "*"
|
||||||
|
"bs4" = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
mypy = "*"
|
mypy = "*"
|
||||||
|
|
9
Pipfile.lock
generated
9
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "5ffa0692528697679dcd7085a5f33c448b989d70f53afa989c7a6a213377fc3e"
|
"sha256": "6398b48732255dbfe41aeaace62f3f4e09fd282f2521716bdb43d388cee0e928"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -31,6 +31,13 @@
|
||||||
],
|
],
|
||||||
"version": "==2.1.3"
|
"version": "==2.1.3"
|
||||||
},
|
},
|
||||||
|
"bs4": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:36ecea1fd7cc5c0c6e4a1ff075df26d50da647b75376626cc186e2212886dd3a"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==0.0.1"
|
||||||
|
},
|
||||||
"certifi": {
|
"certifi": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
|
"sha256:13e698f54293db9f89122b0581843a782ad0934a4fe0172d2a980ba77fc61bb7",
|
||||||
|
|
|
@ -3,6 +3,10 @@ from django.db import models
|
||||||
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
|
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel
|
||||||
from wagtail.images.edit_handlers import ImageChooserPanel
|
from wagtail.images.edit_handlers import ImageChooserPanel
|
||||||
from wagtailmetadata.models import MetadataPageMixin
|
from wagtailmetadata.models import MetadataPageMixin
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
SHORT_BODY_LENGTH = 30
|
||||||
|
|
||||||
|
|
||||||
class Entity(MetadataPageMixin, Page):
|
class Entity(MetadataPageMixin, Page):
|
||||||
|
@ -30,7 +34,9 @@ class Entity(MetadataPageMixin, Page):
|
||||||
return self.search_description
|
return self.search_description
|
||||||
|
|
||||||
def get_short_body(self):
|
def get_short_body(self):
|
||||||
return "Short body"
|
body_words = BeautifulSoup(str(self.body), 'html5lib').get_text().split(' ')
|
||||||
|
ending = '...' if len(body_words) > SHORT_BODY_LENGTH else ''
|
||||||
|
return ' '.join(body_words[:SHORT_BODY_LENGTH]) + ending # limit to 30 words (ish)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
Reference in a new issue