Minor cleanup before highlight refactor.

This commit is contained in:
Martin Mahner 2017-01-21 21:35:38 +01:00
parent 0123fc1512
commit 95aca3588d
9 changed files with 34 additions and 12 deletions

View file

@ -29,10 +29,10 @@ PLAIN_CODE = '_code' # lexer name of code with no hihglighting
LEXER_LIST = getattr(settings, 'DPASTE_LEXER_LIST', ( LEXER_LIST = getattr(settings, 'DPASTE_LEXER_LIST', (
(_('Text'), ( (_('Text'), (
('_text_plain', 'Plain Text'), ('text', 'Plain Text'),
('_text_markdown', 'Markdown'), # ('_text_markdown', 'Markdown'),
('_text_rst', 'reStructuredText'), # ('_text_rst', 'reStructuredText'),
('_text_textile', 'Textile'), # ('_text_textile', 'Textile'),
)), )),
(_('Code'), ( (_('Code'), (
(PLAIN_CODE, 'Plain Code'), (PLAIN_CODE, 'Plain Code'),

View file

@ -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,
),
]

View file

@ -10,6 +10,7 @@ from .highlight import LEXER_DEFAULT
R = SystemRandom() R = SystemRandom()
ONETIME_LIMIT = getattr(settings, 'DPASTE_ONETIME_LIMIT', 2) ONETIME_LIMIT = getattr(settings, 'DPASTE_ONETIME_LIMIT', 2)
def generate_secret_id(length=None, alphabet=None, tries=0): def generate_secret_id(length=None, alphabet=None, tries=0):
length = length or getattr(settings, 'DPASTE_SLUG_LENGTH', 4) length = length or getattr(settings, 'DPASTE_SLUG_LENGTH', 4)
alphabet = alphabet or getattr(settings, 'DPASTE_SLUG_CHOICES', alphabet = alphabet or getattr(settings, 'DPASTE_SLUG_CHOICES',
@ -26,6 +27,7 @@ def generate_secret_id(length=None, alphabet=None, tries=0):
# regular one. # regular one.
return generate_secret_id(length=length+1, tries=tries) return generate_secret_id(length=length+1, tries=tries)
class Snippet(models.Model): class Snippet(models.Model):
EXPIRE_TIME = 1 EXPIRE_TIME = 1
EXPIRE_KEEP = 2 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, secret_id = models.CharField(_(u'Secret ID'), max_length=255, blank=True, null=True,
unique=True) unique=True)
content = models.TextField(_(u'Content')) content = models.TextField(_(u'Content'))
highlighted = models.TextField(_(u'Highlighted Content'))
lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT) lexer = models.CharField(_(u'Lexer'), max_length=30, default=LEXER_DEFAULT)
published = models.DateTimeField(_(u'Published'), auto_now_add=True) published = models.DateTimeField(_(u'Published'), auto_now_add=True)
expire_type = models.PositiveSmallIntegerField(_(u'Expire Type'), expire_type = models.PositiveSmallIntegerField(_(u'Expire Type'),

View file

@ -0,0 +1 @@
<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></div>

View file

@ -0,0 +1 @@
{{ snippet.content|linebreaksbr }}

View file

@ -71,10 +71,10 @@
======================================================================= --> ======================================================================= -->
{% if snippet.lexer == 'text' %} {% if snippet.lexer == 'text' %}
<div class="snippet-rendered"> <div class="snippet-rendered">
{{ snippet.content|linebreaksbr }} {% include "dpaste/highlight/text.html" %}
</div> </div>
{% else %} {% else %}
{% include "dpaste/snippet_pre.html" %} {% include "dpaste/highlight/code.html" %}
{% endif %} {% endif %}
<!-- ====================================================================== <!-- ======================================================================

View file

@ -1 +0,0 @@
{{ snippet.content|safe }}

View file

@ -1 +0,0 @@
{% load dpaste_tags %}<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:"&nbsp;" }}</li>{% endfor %}</ol></div>

View file

@ -3,7 +3,7 @@ import difflib
import json import json
from django.conf import settings from django.conf import settings
from django import get_version from django.views.generic import FormView
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Count from django.db.models import Count
@ -35,7 +35,7 @@ template_globals = {
# Snippet Handling # Snippet Handling
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
from django.views.generic import FormView
class SnippetView(FormView): class SnippetView(FormView):
""" """
@ -122,8 +122,6 @@ class SnippetRawView(SnippetDetailView):
""" """
Display the raw content of a snippet Display the raw content of a snippet
""" """
template_name = 'dpaste/snippet_details_raw.html'
def render_to_response(self, context, **response_kwargs): def render_to_response(self, context, **response_kwargs):
snippet = self.get_object() snippet = self.get_object()
response = HttpResponse(snippet.content) response = HttpResponse(snippet.content)