From 95aca3588d46dc7df4cfc21d9b27b0bb53626c42 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 21 Jan 2017 21:35:38 +0100 Subject: [PATCH] Minor cleanup before highlight refactor. --- dpaste/highlight.py | 8 +++---- dpaste/migrations/0003_snippet_highlighted.py | 21 +++++++++++++++++++ dpaste/models.py | 3 +++ dpaste/templates/dpaste/highlight/code.html | 1 + dpaste/templates/dpaste/highlight/text.html | 1 + dpaste/templates/dpaste/snippet_details.html | 4 ++-- .../templates/dpaste/snippet_details_raw.html | 1 - dpaste/templates/dpaste/snippet_pre.html | 1 - dpaste/views.py | 6 ++---- 9 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 dpaste/migrations/0003_snippet_highlighted.py create mode 100644 dpaste/templates/dpaste/highlight/code.html create mode 100644 dpaste/templates/dpaste/highlight/text.html delete mode 100644 dpaste/templates/dpaste/snippet_details_raw.html delete mode 100644 dpaste/templates/dpaste/snippet_pre.html diff --git a/dpaste/highlight.py b/dpaste/highlight.py index 3ab69bd..79981b9 100644 --- a/dpaste/highlight.py +++ b/dpaste/highlight.py @@ -29,10 +29,10 @@ PLAIN_CODE = '_code' # lexer name of code with no hihglighting LEXER_LIST = getattr(settings, 'DPASTE_LEXER_LIST', ( (_('Text'), ( - ('_text_plain', 'Plain Text'), - ('_text_markdown', 'Markdown'), - ('_text_rst', 'reStructuredText'), - ('_text_textile', 'Textile'), + ('text', 'Plain Text'), + # ('_text_markdown', 'Markdown'), + # ('_text_rst', 'reStructuredText'), + # ('_text_textile', 'Textile'), )), (_('Code'), ( (PLAIN_CODE, 'Plain Code'), diff --git a/dpaste/migrations/0003_snippet_highlighted.py b/dpaste/migrations/0003_snippet_highlighted.py new file mode 100644 index 0000000..79597ce --- /dev/null +++ b/dpaste/migrations/0003_snippet_highlighted.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11a1 on 2017-01-21 16:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dpaste', '0002_auto_20170119_1038'), + ] + + operations = [ + migrations.AddField( + model_name='snippet', + name='highlighted', + field=models.TextField(default='', verbose_name='Highlighted Content'), + preserve_default=False, + ), + ] diff --git a/dpaste/models.py b/dpaste/models.py index cb98bc2..87d04b2 100644 --- a/dpaste/models.py +++ b/dpaste/models.py @@ -10,6 +10,7 @@ from .highlight import LEXER_DEFAULT R = SystemRandom() ONETIME_LIMIT = getattr(settings, 'DPASTE_ONETIME_LIMIT', 2) + def generate_secret_id(length=None, alphabet=None, tries=0): length = length or getattr(settings, 'DPASTE_SLUG_LENGTH', 4) alphabet = alphabet or getattr(settings, 'DPASTE_SLUG_CHOICES', @@ -26,6 +27,7 @@ def generate_secret_id(length=None, alphabet=None, tries=0): # regular one. return generate_secret_id(length=length+1, tries=tries) + class Snippet(models.Model): EXPIRE_TIME = 1 EXPIRE_KEEP = 2 @@ -39,6 +41,7 @@ class Snippet(models.Model): secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True, null=True, unique=True) content = models.TextField(_(u'Content')) + highlighted = models.TextField(_(u'Highlighted Content')) lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT) published = models.DateTimeField(_(u'Published'), auto_now_add=True) expire_type = models.PositiveSmallIntegerField(_(u'Expire Type'), diff --git a/dpaste/templates/dpaste/highlight/code.html b/dpaste/templates/dpaste/highlight/code.html new file mode 100644 index 0000000..4c9ef72 --- /dev/null +++ b/dpaste/templates/dpaste/highlight/code.html @@ -0,0 +1 @@ +
    {% for line in highlighted %}
  1. {{ line|safe|default:" " }}
  2. {% endfor %}
diff --git a/dpaste/templates/dpaste/highlight/text.html b/dpaste/templates/dpaste/highlight/text.html new file mode 100644 index 0000000..3a442fa --- /dev/null +++ b/dpaste/templates/dpaste/highlight/text.html @@ -0,0 +1 @@ +{{ snippet.content|linebreaksbr }} diff --git a/dpaste/templates/dpaste/snippet_details.html b/dpaste/templates/dpaste/snippet_details.html index 83f71a2..4910875 100644 --- a/dpaste/templates/dpaste/snippet_details.html +++ b/dpaste/templates/dpaste/snippet_details.html @@ -71,10 +71,10 @@ ======================================================================= --> {% if snippet.lexer == 'text' %}
- {{ snippet.content|linebreaksbr }} + {% include "dpaste/highlight/text.html" %}
{% else %} - {% include "dpaste/snippet_pre.html" %} + {% include "dpaste/highlight/code.html" %} {% endif %}