diff --git a/bornhack/settings/base.py b/bornhack/settings/base.py index ab56fd63..f14b6e6c 100644 --- a/bornhack/settings/base.py +++ b/bornhack/settings/base.py @@ -28,6 +28,7 @@ INSTALLED_APPS = [ 'camps', 'shop', 'news', + 'utils', 'allauth', 'allauth.account', diff --git a/camps/models.py b/camps/models.py index 5ada4fb4..881d225f 100644 --- a/camps/models.py +++ b/camps/models.py @@ -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 diff --git a/news/models.py b/news/models.py index df577b53..6afba3a9 100644 --- a/news/models.py +++ b/news/models.py @@ -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 diff --git a/news/templates/news_index.html b/news/templates/news_index.html index 49440d98..c44faae1 100644 --- a/news/templates/news_index.html +++ b/news/templates/news_index.html @@ -1,11 +1,12 @@ {% extends 'base.html' %} +{% load commonmark %} {% block content %} {% for item in news_items %}

{{ item.title }} {{ item.published_at|date:"Y-m-d" }}

- {{ item.content }} + {{ item.content|commonmark }} {% if not forloop.last %}
{% endif %} diff --git a/profiles/models.py b/profiles/models.py index 55fcf4a0..c072b585 100644 --- a/profiles/models.py +++ b/profiles/models.py @@ -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): diff --git a/requirements/base.txt b/requirements/base.txt index 5940d2bb..8b1226f9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -6,4 +6,5 @@ psycopg2>=2.6.1 PyPDF2>=1.25.1 django-wkhtmltopdf>=3.0.0 Pillow==3.2.0 -qrcode==5.3 \ No newline at end of file +qrcode==5.3 +CommonMark==0.6.4 \ No newline at end of file diff --git a/shop/models.py b/shop/models.py index b3d6cce1..7ecda5e6 100644 --- a/shop/models.py +++ b/shop/models.py @@ -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 diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/apps.py b/utils/apps.py new file mode 100644 index 00000000..8f2a6fd4 --- /dev/null +++ b/utils/apps.py @@ -0,0 +1,7 @@ +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class UtilsConfig(AppConfig): + name = 'utils' diff --git a/bornhack/utils.py b/utils/models.py similarity index 88% rename from bornhack/utils.py rename to utils/models.py index 0919be72..8dc5292c 100644 --- a/bornhack/utils.py +++ b/utils/models.py @@ -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) \ No newline at end of file diff --git a/utils/templatetags/__init__.py b/utils/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/utils/templatetags/commonmark.py b/utils/templatetags/commonmark.py new file mode 100644 index 00000000..6b885e61 --- /dev/null +++ b/utils/templatetags/commonmark.py @@ -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)) + ) \ No newline at end of file