Adding Commonmark and a template tag for that. We're going to use it in the shop app as well, so it's in its own app now (utils).
This commit is contained in:
parent
e8bda33ac3
commit
a4b578642d
|
@ -28,6 +28,7 @@ INSTALLED_APPS = [
|
|||
'camps',
|
||||
'shop',
|
||||
'news',
|
||||
'utils',
|
||||
|
||||
'allauth',
|
||||
'allauth.account',
|
||||
|
|
|
@ -2,7 +2,7 @@ import datetime
|
|||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from bornhack.utils import CreatedUpdatedModel, UUIDModel
|
||||
from utils.models import UUIDModel, CreatedUpdatedModel
|
||||
|
||||
from .managers import CampQuerySet
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.db import models
|
||||
|
||||
from bornhack.utils import CreatedUpdatedModel
|
||||
from utils.models import CreatedUpdatedModel
|
||||
from news.managers import NewsItemQuerySet
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load commonmark %}
|
||||
|
||||
{% block content %}
|
||||
{% for item in news_items %}
|
||||
<div>
|
||||
<h3>{{ item.title }} <small>{{ item.published_at|date:"Y-m-d" }}</small></h3>
|
||||
</div>
|
||||
{{ item.content }}
|
||||
{{ item.content|commonmark }}
|
||||
{% if not forloop.last %}
|
||||
<hr />
|
||||
{% endif %}
|
||||
|
|
|
@ -4,7 +4,7 @@ from django.db.models.signals import post_save
|
|||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from bornhack.utils import CreatedUpdatedModel, UUIDModel
|
||||
from utils.models import UUIDModel, CreatedUpdatedModel
|
||||
|
||||
|
||||
class Profile(CreatedUpdatedModel, UUIDModel):
|
||||
|
|
|
@ -7,3 +7,4 @@ PyPDF2>=1.25.1
|
|||
django-wkhtmltopdf>=3.0.0
|
||||
Pillow==3.2.0
|
||||
qrcode==5.3
|
||||
CommonMark==0.6.4
|
|
@ -6,7 +6,7 @@ from django.utils.text import slugify
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils import timezone
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from bornhack.utils import CreatedUpdatedModel, UUIDModel
|
||||
from utils.models import UUIDModel, CreatedUpdatedModel
|
||||
from .managers import ProductQuerySet
|
||||
import hashlib, io, base64, qrcode
|
||||
|
||||
|
|
0
utils/__init__.py
Normal file
0
utils/__init__.py
Normal file
7
utils/apps.py
Normal file
7
utils/apps.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UtilsConfig(AppConfig):
|
||||
name = 'utils'
|
|
@ -3,14 +3,6 @@ import uuid
|
|||
from django.db import models
|
||||
|
||||
|
||||
class CreatedUpdatedModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
class UUIDModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
@ -20,3 +12,11 @@ class UUIDModel(models.Model):
|
|||
default=uuid.uuid4,
|
||||
editable=False,
|
||||
)
|
||||
|
||||
|
||||
class CreatedUpdatedModel(models.Model):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
0
utils/templatetags/__init__.py
Normal file
0
utils/templatetags/__init__.py
Normal file
17
utils/templatetags/commonmark.py
Normal file
17
utils/templatetags/commonmark.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
import CommonMark
|
||||
|
||||
from django import template
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(is_safe=True)
|
||||
def commonmark(value):
|
||||
parser = CommonMark.Parser()
|
||||
renderer = CommonMark.HtmlRenderer()
|
||||
ast = parser.parse(force_text(value))
|
||||
return mark_safe(
|
||||
force_text(renderer.render(ast))
|
||||
)
|
Loading…
Reference in a new issue