mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Minor cleanup before highlight refactor.
This commit is contained in:
parent
0123fc1512
commit
95aca3588d
9 changed files with 34 additions and 12 deletions
|
@ -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'),
|
||||
|
|
21
dpaste/migrations/0003_snippet_highlighted.py
Normal file
21
dpaste/migrations/0003_snippet_highlighted.py
Normal 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,
|
||||
),
|
||||
]
|
|
@ -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'),
|
||||
|
|
1
dpaste/templates/dpaste/highlight/code.html
Normal file
1
dpaste/templates/dpaste/highlight/code.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:" " }}</li>{% endfor %}</ol></div>
|
1
dpaste/templates/dpaste/highlight/text.html
Normal file
1
dpaste/templates/dpaste/highlight/text.html
Normal file
|
@ -0,0 +1 @@
|
|||
{{ snippet.content|linebreaksbr }}
|
|
@ -71,10 +71,10 @@
|
|||
======================================================================= -->
|
||||
{% if snippet.lexer == 'text' %}
|
||||
<div class="snippet-rendered">
|
||||
{{ snippet.content|linebreaksbr }}
|
||||
{% include "dpaste/highlight/text.html" %}
|
||||
</div>
|
||||
{% else %}
|
||||
{% include "dpaste/snippet_pre.html" %}
|
||||
{% include "dpaste/highlight/code.html" %}
|
||||
{% endif %}
|
||||
|
||||
<!-- ======================================================================
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
{{ snippet.content|safe }}
|
|
@ -1 +0,0 @@
|
|||
{% load dpaste_tags %}<div class="code {{ snippet.lexer }}"><ol>{% for line in highlighted %}<li id="{{ forloop.counter }}">{{ line|safe|default:" " }}</li>{% endfor %}</ol></div>
|
|
@ -3,7 +3,7 @@ import difflib
|
|||
import json
|
||||
|
||||
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.urlresolvers import reverse
|
||||
from django.db.models import Count
|
||||
|
@ -35,7 +35,7 @@ template_globals = {
|
|||
# Snippet Handling
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
from django.views.generic import FormView
|
||||
|
||||
|
||||
class SnippetView(FormView):
|
||||
"""
|
||||
|
@ -122,8 +122,6 @@ class SnippetRawView(SnippetDetailView):
|
|||
"""
|
||||
Display the raw content of a snippet
|
||||
"""
|
||||
template_name = 'dpaste/snippet_details_raw.html'
|
||||
|
||||
def render_to_response(self, context, **response_kwargs):
|
||||
snippet = self.get_object()
|
||||
response = HttpResponse(snippet.content)
|
||||
|
|
Loading…
Reference in a new issue