diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index ed4823c35c..67ac2b89d1 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -101,7 +101,8 @@ INSTALLED_APPS = [ 'django_cleanup', # Automatically delete orphaned MEDIA files 'qr_code', # Generate QR codes 'mptt', # Modified Preorder Tree Traversal - 'pagedown.apps.PagedownConfig' # Markdown forms + 'markdownx', # Markdown editing + 'markdownify', # Markdown template rendering ] LOGGING = { diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 033261d9f8..94e57b5be9 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -100,6 +100,8 @@ urlpatterns = [ url(r'^api/', include(apipatterns)), url(r'^api-doc/', include_docs_urls(title='InvenTree API')), + + url(r'^md/', include('markdownx.urls')), ] # Static file access diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 060723f3d8..20ad569a12 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -8,8 +8,6 @@ from import_export.resources import ModelResource from import_export.fields import Field import import_export.widgets as widgets -from .forms import PartAdminForm - from .models import PartCategory, Part from .models import PartAttachment, PartStar from .models import BomItem @@ -71,9 +69,6 @@ class PartResource(ModelResource): class PartAdmin(ImportExportModelAdmin): - - form = PartAdminForm - #fields = "__all__" resource_class = PartResource diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 5b4cb509fa..7a4eecd583 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -11,8 +11,6 @@ from mptt.fields import TreeNodeChoiceField from django import forms from django.utils.translation import ugettext as _ -from pagedown.widgets import AdminPagedownWidget - from .models import Part, PartCategory, PartAttachment from .models import BomItem from .models import PartParameterTemplate, PartParameter @@ -20,20 +18,6 @@ from .models import PartParameterTemplate, PartParameter from common.models import Currency -class PartAdminForm(forms.ModelForm): - """ Override default form behaviour for the Part admin interface. - - - Present the 'notes' field as a Markdown-editor - - """ - - notes = forms.CharField(widget=AdminPagedownWidget()) - - class Meta: - model = Part - fields = "__all__" - - class PartImageForm(HelperForm): """ Form for uploading a Part image """ @@ -120,7 +104,6 @@ class EditPartForm(HelperForm): 'default_supplier', 'units', 'minimum_stock', - 'notes', 'active', ] diff --git a/InvenTree/part/migrations/0026_auto_20200131_1022.py b/InvenTree/part/migrations/0026_auto_20200131_1022.py new file mode 100644 index 0000000000..f3a3af73a4 --- /dev/null +++ b/InvenTree/part/migrations/0026_auto_20200131_1022.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-01-31 10:22 + +from django.db import migrations +import markdownx.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0025_auto_20191118_2316'), + ] + + operations = [ + migrations.AlterField( + model_name='part', + name='notes', + field=markdownx.models.MarkdownxField(help_text='Part notes - supports Markdown formatting'), + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 386bf3e2c9..2df55ad73b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -22,6 +22,8 @@ from django.contrib.auth.models import User from django.db.models.signals import pre_delete from django.dispatch import receiver +from markdownx.models import MarkdownxField + from mptt.models import TreeForeignKey from datetime import datetime @@ -422,7 +424,7 @@ class Part(models.Model): virtual = models.BooleanField(default=False, help_text=_('Is this a virtual part, such as a software product or license?')) - notes = models.TextField(blank=True) + notes = MarkdownxField(help_text=_('Part notes - supports Markdown formatting')) bom_checksum = models.CharField(max_length=128, blank=True, help_text=_('Stored BOM checksum')) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 12db3e3e9b..a37ad5823d 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -147,13 +147,6 @@ -{% if part.notes %} -
-
{% trans "Notes" %}
-
{{ part.notes }}
-
-{% endif %} - {% endblock %} {% block js_load %} diff --git a/InvenTree/part/templates/part/notes.html b/InvenTree/part/templates/part/notes.html index ec2329fd0c..39d5e19842 100644 --- a/InvenTree/part/templates/part/notes.html +++ b/InvenTree/part/templates/part/notes.html @@ -1,6 +1,7 @@ {% extends "part/part_base.html" %} {% load static %} {% load i18n %} +{% load markdownify %} {% block details %} @@ -8,6 +9,18 @@

{% trans "Part Notes" %}

-Notes field goes here +
+
+ {{ part.notes | markdownify }} +
+
+ +
+ {% csrf_token %} + + {{ form }} +
+ +{{ form.media }} {% endblock %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 20d4923a73..d92bb5de7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,8 @@ django-cors-headers==3.2.0 # CORS headers extension for DRF django_filter==2.2.0 # Extended filtering options django-mptt==0.10.0 # Modified Preorder Tree Traversal django-dbbackup==3.2.0 # Database backup / restore functionality -django-pagedown==2.0.3 # Markdown form fields +django-markdownx==3.0.1 # Markdown form fields +django-markdownify==0.8.0 # Markdown rendering coreapi==2.3.0 # API documentation pygments==2.2.0 # Syntax highlighting tablib==0.13.0 # Import / export data files