Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.sqlite3
.idea
23 changes: 23 additions & 0 deletions sirtrevor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
from django.template.loader import render_to_string
from django.utils.encoding import python_2_unicode_compatible
import six


#@python_2_unicode_compatible
class SirTrevorContent(six.text_type):
@property
def html(self):
Expand All @@ -14,9 +16,30 @@ def html(self):
html.append(render_to_string(template_name, block['data']))
return u''.join(html)

def get_blocks(self, type=None):
if not len(self):
return
_blocks = json.loads(self)['data']

return [block for block in _blocks if not type or block['type'] is type or block['type'] in type]


def get_first_block(self, type=None):
try:
return self.get_blocks(type)[0]
except IndexError:
return None

#def __str__(self):
# for block in self.get_blocks():
# text = block['data'].get('text', False)
# if text:
# return text


custom_blocks_registry = {}


def register_block(block, name=None):
if name is None:
name = block.name
Expand Down
Binary file added sirtrevor/__init__.pyc
Binary file not shown.
Binary file added sirtrevor/admin.pyc
Binary file not shown.
Binary file added sirtrevor/conf.pyc
Binary file not shown.
Binary file added sirtrevor/fields.pyc
Binary file not shown.
Binary file added sirtrevor/forms.pyc
Binary file not shown.
Binary file added sirtrevor/models.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion sirtrevor/templates/sirtrevor/blocks/heading.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load sirtrevor %}
<div class="content-block heading-block">
<h1>{{ text|linebreaksbr }}</h1>
<h1>{{ text|markdown|linebreaksbr }}</h1>
</div>
Binary file added sirtrevor/templatetags/__init__.pyc
Binary file not shown.
Binary file added sirtrevor/templatetags/sirtrevor.pyc
Binary file not shown.
Binary file added sirtrevor/urls.pyc
Binary file not shown.
6 changes: 4 additions & 2 deletions sirtrevor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
from django.conf import settings
from django.core.files.storage import default_storage
from django.http import HttpResponse
from django.utils.module_loading import import_string
from django.utils.text import slugify
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.contrib.auth.decorators import user_passes_test
from PIL import Image
from .forms import AttachmentForm


AUTH_TEST = lambda u: u.is_staff

validator = getattr(settings, 'SIRTREVOR_USER_ATTACHMENT_VALIDATOR', False)
if validator:
AUTH_TEST = import_string(validator)

@csrf_exempt
@require_POST
Expand Down
Binary file added sirtrevor/views.pyc
Binary file not shown.
Binary file added sirtrevor/widgets.pyc
Binary file not shown.