add a simple markdown editor that works yet
This commit is contained in:
parent
8d71e460c5
commit
96eddbf8db
|
@ -43,6 +43,7 @@ INSTALLED_APPS = [
|
|||
'process',
|
||||
'mptt',
|
||||
'widget_tweaks',
|
||||
'writer',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -22,4 +22,5 @@ urlpatterns = [
|
|||
url(r'^docs/', include('dms.urls')),
|
||||
url(r'^jci/', include('jci.urls')),
|
||||
url(r'^p/', include('process.urls')),
|
||||
url(r'^w/', include('writer.urls')),
|
||||
]
|
||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
|
@ -0,0 +1,17 @@
|
|||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter
|
||||
def field_type(bound_field):
|
||||
return bound_field.field.widget.__class__.__name__
|
||||
|
||||
@register.filter
|
||||
def input_class(bound_field):
|
||||
css_class = ''
|
||||
if bound_field.form.is_bound:
|
||||
if bound_field.errors:
|
||||
css_class = 'is-invalid'
|
||||
elif field_type(bound_field) != 'PasswordInput':
|
||||
css_class = 'is-valid'
|
||||
return 'form-control {}'.format(css_class)
|
|
@ -6,6 +6,8 @@
|
|||
<link href="https://fonts.googleapis.com/css?family=Peralta" rel="stylesheet">
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/app.css' %}">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
|
||||
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
|
||||
{% block stylesheet %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
|
@ -18,5 +20,6 @@
|
|||
<script src="{% static 'js/jquery-3.2.1.min.js' %}"></script>
|
||||
<script src="{% static 'js/popper.min.js' %}"></script>
|
||||
<script src="{% static 'js/bootstrap.min.js' %}"></script>
|
||||
{% block javascript %}{% endblock %} <!-- Add this empty block here! -->
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load widget_tweaks %}
|
||||
{% load form_tags widget_tweaks %}
|
||||
|
||||
{% if form.non_field_errors %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
|
@ -9,5 +9,18 @@
|
|||
{% endif %}
|
||||
|
||||
{% for field in form %}
|
||||
<!-- code suppressed -->
|
||||
<div class="form-group">
|
||||
{{ field.label_tag }}
|
||||
{% render_field field class=field|input_class %}
|
||||
{% for error in field.errors %}
|
||||
<div class="invalid-feedback">
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if field.help_text %}
|
||||
<small class="form-text text-muted">
|
||||
{{ field.help_text|safe }}
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{% extends "../base.html" %}
|
||||
|
||||
{% block "content" %}
|
||||
<h2>Edit section {{ section }}</h2>
|
||||
<textarea>
|
||||
|
||||
</textarea>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascript %}
|
||||
<script>
|
||||
var simplemde = new SimpleMDE();
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "../base.html" %}
|
||||
|
||||
{% block "content" %}
|
||||
<h2>Sections</h2>
|
||||
<ul>
|
||||
{% for section in sections %}
|
||||
<li><a href="{% url 'edit_document_section' document_id section.order%}">{{ section }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
|
@ -0,0 +1,5 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Section
|
||||
|
||||
admin.site.register(Section)
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class WriterConfig(AppConfig):
|
||||
name = 'writer'
|
|
@ -0,0 +1,31 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.5 on 2018-02-03 20:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('dms', '0003_auto_20171117_0823'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Section',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('order', models.IntegerField()),
|
||||
('content', models.TextField()),
|
||||
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dms.Document')),
|
||||
],
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='section',
|
||||
unique_together=set([('document', 'order')]),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.5 on 2018-02-03 20:25
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('writer', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='section',
|
||||
name='title',
|
||||
field=models.CharField(default='Section', max_length=255),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
from django.db import models
|
||||
|
||||
from dms.models import Document
|
||||
|
||||
|
||||
class Section(models.Model):
|
||||
document = models.ForeignKey(Document)
|
||||
order = models.IntegerField()
|
||||
title = models.CharField(max_length=255)
|
||||
content = models.TextField()
|
||||
|
||||
class Meta:
|
||||
unique_together = ('document', 'order')
|
||||
ordering = ('document', 'order')
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,9 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from .views import list_sections, edit_section
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'document/(?P<document_id>\d+)/section/(?P<section_id>\d+)', edit_section, name='edit_document_section'),
|
||||
url(r'document/(?P<document_id>\d+)', list_sections, name='document_sections'),
|
||||
]
|
|
@ -0,0 +1,14 @@
|
|||
from django.shortcuts import render
|
||||
from .models import Section
|
||||
|
||||
|
||||
def list_sections(request, document_id):
|
||||
sections = Section.objects.filter(document=document_id)
|
||||
|
||||
return render(request, 'writer/sections_list.html', {'document_id': document_id, 'sections': sections})
|
||||
|
||||
|
||||
def edit_section(request, document_id, section_id):
|
||||
section = Section.objects.get(document=document_id, pk=section_id)
|
||||
|
||||
return render(request, 'writer/edit_section.html', {'document_id': document_id, 'section': section})
|
Loading…
Reference in New Issue