Update requirements

- Use markdownify for rendering
- Use markdownx for editing
This commit is contained in:
Oliver Walters 2020-01-31 21:42:30 +11:00
parent da01177d23
commit c546ed5dcd
9 changed files with 42 additions and 33 deletions

View File

@ -101,7 +101,8 @@ INSTALLED_APPS = [
'django_cleanup', # Automatically delete orphaned MEDIA files 'django_cleanup', # Automatically delete orphaned MEDIA files
'qr_code', # Generate QR codes 'qr_code', # Generate QR codes
'mptt', # Modified Preorder Tree Traversal 'mptt', # Modified Preorder Tree Traversal
'pagedown.apps.PagedownConfig' # Markdown forms 'markdownx', # Markdown editing
'markdownify', # Markdown template rendering
] ]
LOGGING = { LOGGING = {

View File

@ -100,6 +100,8 @@ urlpatterns = [
url(r'^api/', include(apipatterns)), url(r'^api/', include(apipatterns)),
url(r'^api-doc/', include_docs_urls(title='InvenTree API')), url(r'^api-doc/', include_docs_urls(title='InvenTree API')),
url(r'^md/', include('markdownx.urls')),
] ]
# Static file access # Static file access

View File

@ -8,8 +8,6 @@ from import_export.resources import ModelResource
from import_export.fields import Field from import_export.fields import Field
import import_export.widgets as widgets import import_export.widgets as widgets
from .forms import PartAdminForm
from .models import PartCategory, Part from .models import PartCategory, Part
from .models import PartAttachment, PartStar from .models import PartAttachment, PartStar
from .models import BomItem from .models import BomItem
@ -71,9 +69,6 @@ class PartResource(ModelResource):
class PartAdmin(ImportExportModelAdmin): class PartAdmin(ImportExportModelAdmin):
form = PartAdminForm
#fields = "__all__"
resource_class = PartResource resource_class = PartResource

View File

@ -11,8 +11,6 @@ from mptt.fields import TreeNodeChoiceField
from django import forms from django import forms
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from pagedown.widgets import AdminPagedownWidget
from .models import Part, PartCategory, PartAttachment from .models import Part, PartCategory, PartAttachment
from .models import BomItem from .models import BomItem
from .models import PartParameterTemplate, PartParameter from .models import PartParameterTemplate, PartParameter
@ -20,20 +18,6 @@ from .models import PartParameterTemplate, PartParameter
from common.models import Currency 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): class PartImageForm(HelperForm):
""" Form for uploading a Part image """ """ Form for uploading a Part image """
@ -120,7 +104,6 @@ class EditPartForm(HelperForm):
'default_supplier', 'default_supplier',
'units', 'units',
'minimum_stock', 'minimum_stock',
'notes',
'active', 'active',
] ]

View File

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

View File

@ -22,6 +22,8 @@ from django.contrib.auth.models import User
from django.db.models.signals import pre_delete from django.db.models.signals import pre_delete
from django.dispatch import receiver from django.dispatch import receiver
from markdownx.models import MarkdownxField
from mptt.models import TreeForeignKey from mptt.models import TreeForeignKey
from datetime import datetime 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?')) 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')) bom_checksum = models.CharField(max_length=128, blank=True, help_text=_('Stored BOM checksum'))

View File

@ -147,13 +147,6 @@
</div> </div>
</div> </div>
{% if part.notes %}
<div class="panel panel-default">
<div class="panel-heading"><b>{% trans "Notes" %}</b></div>
<div class="panel-body">{{ part.notes }}</div>
</div>
{% endif %}
{% endblock %} {% endblock %}
{% block js_load %} {% block js_load %}

View File

@ -1,6 +1,7 @@
{% extends "part/part_base.html" %} {% extends "part/part_base.html" %}
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% load markdownify %}
{% block details %} {% block details %}
@ -8,6 +9,18 @@
<h4>{% trans "Part Notes" %}</h4> <h4>{% trans "Part Notes" %}</h4>
Notes field goes here <div class='panel panel-default'>
<div class='panel-body'>
{{ part.notes | markdownify }}
</div>
</div>
<form method="post" action="">
{% csrf_token %}
{{ form }}
</form>
{{ form.media }}
{% endblock %} {% endblock %}

View File

@ -5,7 +5,8 @@ django-cors-headers==3.2.0 # CORS headers extension for DRF
django_filter==2.2.0 # Extended filtering options django_filter==2.2.0 # Extended filtering options
django-mptt==0.10.0 # Modified Preorder Tree Traversal django-mptt==0.10.0 # Modified Preorder Tree Traversal
django-dbbackup==3.2.0 # Database backup / restore functionality 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 coreapi==2.3.0 # API documentation
pygments==2.2.0 # Syntax highlighting pygments==2.2.0 # Syntax highlighting
tablib==0.13.0 # Import / export data files tablib==0.13.0 # Import / export data files