Skip to content

Commit

Permalink
Remove reliance on django-markdownx (#3231)
Browse files Browse the repository at this point in the history
* Remove reliance on django-markdownx

- We are now rendering notes on the client side using easymde
- No longer any need to utilize the markdownx integration
- Adds character limit for notes fields`

* Adjust legacy migrations - remove references to markdownx

* Fix bug for company notes field
  • Loading branch information
SchrodingersGat committed Jun 20, 2022
1 parent a8b71d7 commit 63b4ff3
Show file tree
Hide file tree
Showing 32 changed files with 173 additions and 110 deletions.
16 changes: 16 additions & 0 deletions InvenTree/InvenTree/fields.py
Expand Up @@ -157,3 +157,19 @@ def formfield(self, **kwargs):
defaults.update(kwargs)

return super().formfield(**kwargs)


class InvenTreeNotesField(models.TextField):
"""Custom implementation of a 'notes' field"""

# Maximum character limit for the various 'notes' fields
NOTES_MAX_LENGTH = 50000

def __init__(self, **kwargs):
"""Configure default initial values for this field"""
kwargs['max_length'] = self.NOTES_MAX_LENGTH
kwargs['verbose_name'] = _('Notes')
kwargs['blank'] = True
kwargs['null'] = True

super().__init__(**kwargs)
6 changes: 0 additions & 6 deletions InvenTree/InvenTree/settings.py
Expand Up @@ -15,7 +15,6 @@
import socket
import string
import sys
from datetime import datetime

import django.conf.locale
from django.core.files.storage import default_storage
Expand Down Expand Up @@ -253,7 +252,6 @@ def _is_true(x):
'import_export', # Import / export tables to file
'django_cleanup.apps.CleanupConfig', # Automatically delete orphaned MEDIA files
'mptt', # Modified Preorder Tree Traversal
'markdownx', # Markdown editing
'markdownify', # Markdown template rendering
'django_admin_shell', # Python shell for the admin interface
'djmoney', # django-money integration
Expand Down Expand Up @@ -875,10 +873,6 @@ def _is_true(x):
REMOTE_LOGIN = get_setting('INVENTREE_REMOTE_LOGIN', CONFIG.get('remote_login', False))
REMOTE_LOGIN_HEADER = get_setting('INVENTREE_REMOTE_LOGIN_HEADER', CONFIG.get('remote_login_header', 'REMOTE_USER'))

# Markdownx configuration
# Ref: https://neutronx.github.io/django-markdownx/customization/
MARKDOWNX_MEDIA_PATH = datetime.now().strftime('markdownx/%Y/%m/%d')

# Markdownify configuration
# Ref: https://django-markdownify.readthedocs.io/en/latest/settings.html

Expand Down
9 changes: 0 additions & 9 deletions InvenTree/InvenTree/static/css/color-themes/dark-reader.css
Expand Up @@ -3539,15 +3539,6 @@ a.ui-button:active,
.index-action-selected {
background-color: rgb(32, 34, 36);
}
.markdownx .row {
border-color: rgb(31, 31, 92);
}
.markdownx-editor {
border-color: rgb(31, 31, 92);
}
.markdownx-preview {
border-color: rgb(31, 31, 92);
}
.progress {
background-image: initial;
background-color: rgb(32, 34, 36);
Expand Down
20 changes: 0 additions & 20 deletions InvenTree/InvenTree/static/css/inventree.css
Expand Up @@ -63,30 +63,10 @@ main {
background-color: #EEEEF5;
}

.markdownx .row {
margin: 5px;
padding: 5px;
border: 1px solid #cce;
border-radius: 4px;
}

.markdownx-editor {
width: 100%;
border: 1px solid #cce;
border-radius: 3px;
padding: 10px;
}

.panel-content {
padding: 10px;
}

.markdownx-preview {
border: 1px solid #cce;
border-radius: 3px;
padding: 10px;
}

/* Progress bars */

.progress {
Expand Down
3 changes: 0 additions & 3 deletions InvenTree/InvenTree/urls.py
Expand Up @@ -126,9 +126,6 @@

re_path(r'^api/', include(apipatterns)),
re_path(r'^api-doc/', include_docs_urls(title='InvenTree API')),

# 3rd party endpoints
re_path(r'^markdownx/', include('markdownx.urls')),
]

frontendpatterns = [
Expand Down
5 changes: 2 additions & 3 deletions InvenTree/build/migrations/0008_auto_20200201_1247.py
@@ -1,7 +1,6 @@
# Generated by Django 2.2.9 on 2020-02-01 12:47

from django.db import migrations
import markdownx.models
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -14,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='build',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Extra build notes'),
field=models.TextField(blank=True, help_text='Extra build notes'),
),
]
3 changes: 1 addition & 2 deletions InvenTree/build/migrations/0014_auto_20200425_1243.py
Expand Up @@ -4,7 +4,6 @@
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import markdownx.models
import mptt.fields


Expand All @@ -31,7 +30,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='build',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Extra build notes', verbose_name='Notes'),
field=models.TextField(blank=True, help_text='Extra build notes', verbose_name='Notes'),
),
migrations.AlterField(
model_name='build',
Expand Down
19 changes: 19 additions & 0 deletions InvenTree/build/migrations/0035_alter_build_notes.py
@@ -0,0 +1,19 @@
# Generated by Django 3.2.13 on 2022-06-20 07:28

import InvenTree.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('build', '0034_alter_build_reference_int'),
]

operations = [
migrations.AlterField(
model_name='build',
name='notes',
field=InvenTree.fields.InvenTreeNotesField(blank=True, help_text='Extra build notes', max_length=50000, null=True, verbose_name='Notes'),
),
]
7 changes: 2 additions & 5 deletions InvenTree/build/models.py
Expand Up @@ -16,8 +16,6 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from markdownx.models import MarkdownxField

from mptt.models import MPTTModel, TreeForeignKey
from mptt.exceptions import InvalidMove

Expand Down Expand Up @@ -320,9 +318,8 @@ def get_absolute_url(self):
blank=True, help_text=_('Link to external URL')
)

notes = MarkdownxField(
verbose_name=_('Notes'),
blank=True, help_text=_('Extra build notes')
notes = InvenTree.fields.InvenTreeNotesField(
help_text=_('Extra build notes')
)

def sub_builds(self, cascade=True):
Expand Down
5 changes: 2 additions & 3 deletions InvenTree/company/migrations/0010_auto_20200201_1231.py
@@ -1,7 +1,6 @@
# Generated by Django 2.2.9 on 2020-02-01 12:31

from django.db import migrations
import markdownx.models
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -14,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='company',
name='notes',
field=markdownx.models.MarkdownxField(blank=True),
field=models.TextField(blank=True),
),
]
3 changes: 1 addition & 2 deletions InvenTree/company/migrations/0032_auto_20210403_1837.py
Expand Up @@ -5,7 +5,6 @@
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import markdownx.models
import stdimage.models


Expand Down Expand Up @@ -44,7 +43,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='company',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, verbose_name='Notes'),
field=models.TextField(blank=True, verbose_name='Notes'),
),
migrations.AlterField(
model_name='supplierpart',
Expand Down
19 changes: 19 additions & 0 deletions InvenTree/company/migrations/0045_alter_company_notes.py
@@ -0,0 +1,19 @@
# Generated by Django 3.2.13 on 2022-06-20 11:23

import InvenTree.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('company', '0044_auto_20220607_2204'),
]

operations = [
migrations.AlterField(
model_name='company',
name='notes',
field=InvenTree.fields.InvenTreeNotesField(blank=True, help_text='Company Notes', max_length=50000, null=True, verbose_name='Notes'),
),
]
4 changes: 2 additions & 2 deletions InvenTree/company/models.py
Expand Up @@ -11,12 +11,12 @@
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

from markdownx.models import MarkdownxField
from moneyed import CURRENCIES
from stdimage.models import StdImageField

import common.models
import common.settings
import InvenTree.fields
import InvenTree.validators
from common.settings import currency_code_default
from InvenTree.fields import InvenTreeURLField
Expand Down Expand Up @@ -135,7 +135,7 @@ class Meta:
verbose_name=_('Image'),
)

notes = MarkdownxField(blank=True, verbose_name=_('Notes'))
notes = InvenTree.fields.InvenTreeNotesField(help_text=_("Company Notes"))

is_customer = models.BooleanField(default=False, verbose_name=_('is customer'), help_text=_('Do you sell items to this company?'))

Expand Down
5 changes: 2 additions & 3 deletions InvenTree/order/migrations/0015_auto_20200201_2346.py
@@ -1,7 +1,6 @@
# Generated by Django 2.2.9 on 2020-02-01 23:46

from django.db import migrations
import markdownx.models
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -14,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='purchaseorder',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Order notes'),
field=models.TextField(blank=True, help_text='Order notes'),
),
]
3 changes: 1 addition & 2 deletions InvenTree/order/migrations/0020_auto_20200420_0940.py
Expand Up @@ -6,7 +6,6 @@
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import markdownx.models


class Migration(migrations.Migration):
Expand All @@ -29,7 +28,7 @@ class Migration(migrations.Migration):
('status', models.PositiveIntegerField(choices=[(10, 'Pending'), (20, 'Placed'), (30, 'Complete'), (40, 'Cancelled'), (50, 'Lost'), (60, 'Returned')], default=10, help_text='Order status')),
('issue_date', models.DateField(blank=True, null=True)),
('complete_date', models.DateField(blank=True, null=True)),
('notes', markdownx.models.MarkdownxField(blank=True, help_text='Order notes')),
('notes', models.TextField(blank=True, help_text='Order notes')),
('customer_reference', models.CharField(blank=True, help_text='Customer order reference code', max_length=64)),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('customer', models.ForeignKey(help_text='Customer', limit_choices_to={True, 'is_supplier'}, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sales_orders', to='company.Company')),
Expand Down
5 changes: 2 additions & 3 deletions InvenTree/order/migrations/0044_auto_20210404_2016.py
Expand Up @@ -6,7 +6,6 @@
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import markdownx.models


class Migration(migrations.Migration):
Expand Down Expand Up @@ -43,7 +42,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='purchaseorder',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Order notes', verbose_name='Notes'),
field=models.TextField(blank=True, help_text='Order notes', verbose_name='Notes'),
),
migrations.AlterField(
model_name='purchaseorder',
Expand Down Expand Up @@ -148,7 +147,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='salesorder',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Order notes', verbose_name='Notes'),
field=models.TextField(blank=True, help_text='Order notes', verbose_name='Notes'),
),
migrations.AlterField(
model_name='salesorder',
Expand Down
6 changes: 1 addition & 5 deletions InvenTree/order/migrations/0053_salesordershipment.py
Expand Up @@ -4,10 +4,6 @@
from django.db import migrations, models
import django.db.models.deletion

import order.models

import markdownx.models


class Migration(migrations.Migration):

Expand All @@ -23,7 +19,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shipment_date', models.DateField(blank=True, help_text='Date of shipment', null=True, verbose_name='Shipment Date')),
('reference', models.CharField(default='1', help_text='Shipment reference', max_length=100, verbose_name='Reference')),
('notes', markdownx.models.MarkdownxField(blank=True, help_text='Shipment notes', verbose_name='Notes')),
('notes', models.TextField(blank=True, help_text='Shipment notes', verbose_name='Notes')),
('checked_by', models.ForeignKey(blank=True, help_text='User who checked this shipment', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Checked By')),
('order', models.ForeignKey(help_text='Sales Order', on_delete=django.db.models.deletion.CASCADE, related_name='shipments', to='order.salesorder', verbose_name='Order')),
],
Expand Down
29 changes: 29 additions & 0 deletions InvenTree/order/migrations/0070_auto_20220620_0728.py
@@ -0,0 +1,29 @@
# Generated by Django 3.2.13 on 2022-06-20 07:28

import InvenTree.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('order', '0069_auto_20220524_0508'),
]

operations = [
migrations.AlterField(
model_name='purchaseorder',
name='notes',
field=InvenTree.fields.InvenTreeNotesField(blank=True, help_text='Order notes', max_length=50000, null=True, verbose_name='Notes'),
),
migrations.AlterField(
model_name='salesorder',
name='notes',
field=InvenTree.fields.InvenTreeNotesField(blank=True, help_text='Order notes', max_length=50000, null=True, verbose_name='Notes'),
),
migrations.AlterField(
model_name='salesordershipment',
name='notes',
field=InvenTree.fields.InvenTreeNotesField(blank=True, help_text='Shipment notes', max_length=50000, null=True, verbose_name='Notes'),
),
]

0 comments on commit 63b4ff3

Please sign in to comment.