From 3c3ae43c18f719547df99b06396e30782fe0d4df Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 1 Feb 2020 13:36:09 +1100 Subject: [PATCH] Add special view for displaying / editing notes field for part --- InvenTree/InvenTree/urls.py | 2 +- InvenTree/part/templates/part/notes.html | 23 ++++++++++++------ InvenTree/part/urls.py | 2 +- InvenTree/part/views.py | 30 +++++++++++++++++++++++- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 94e57b5be9..31b498ea2b 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -101,7 +101,7 @@ urlpatterns = [ url(r'^api/', include(apipatterns)), url(r'^api-doc/', include_docs_urls(title='InvenTree API')), - url(r'^md/', include('markdownx.urls')), + url(r'^markdownx/', include('markdownx.urls')), ] # Static file access diff --git a/InvenTree/part/templates/part/notes.html b/InvenTree/part/templates/part/notes.html index 39d5e19842..2c50d235c6 100644 --- a/InvenTree/part/templates/part/notes.html +++ b/InvenTree/part/templates/part/notes.html @@ -1,5 +1,6 @@ {% extends "part/part_base.html" %} {% load static %} +{% load crispy_forms_tags %} {% load i18n %} {% load markdownify %} @@ -9,18 +10,26 @@

{% trans "Part Notes" %}

+{% if editing %} + +
+ {% csrf_token %} + + {{ form }} + + +
+ +{{ form.media }} + +{% else %} +
{{ part.notes | markdownify }}
-
- {% csrf_token %} - - {{ form }} -
- -{{ form.media }} +{% endif %} {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/urls.py b/InvenTree/part/urls.py index c8ad8b0e6c..0a9adefe8f 100644 --- a/InvenTree/part/urls.py +++ b/InvenTree/part/urls.py @@ -52,7 +52,7 @@ part_detail_urls = [ url(r'^orders/?', views.PartDetail.as_view(template_name='part/orders.html'), name='part-orders'), url(r'^track/?', views.PartDetail.as_view(template_name='part/track.html'), name='part-track'), url(r'^attachments/?', views.PartDetail.as_view(template_name='part/attachments.html'), name='part-attachments'), - url(r'^notes/?', views.PartDetail.as_view(template_name='part/notes.html'), name='part-notes'), + url(r'^notes/?', views.PartNotes.as_view(), name='part-notes'), url(r'^qr_code/?', views.PartQRCode.as_view(), name='part-qr'), diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 6d4eb5203b..6f2e71bc6d 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -11,7 +11,7 @@ from django.shortcuts import get_object_or_404 from django.shortcuts import HttpResponseRedirect from django.utils.translation import gettext_lazy as _ from django.urls import reverse, reverse_lazy -from django.views.generic import DetailView, ListView, FormView +from django.views.generic import DetailView, ListView, FormView, UpdateView from django.forms.models import model_to_dict from django.forms import HiddenInput, CheckboxInput @@ -519,6 +519,34 @@ class PartCreate(AjaxCreateView): return initials +class PartNotes(UpdateView): + """ View for editing the 'notes' field of a Part object. + Presents a live markdown editor. + """ + + context_object_name = 'part' + # form_class = part_forms.EditNotesForm + template_name = 'part/notes.html' + model = Part + + fields = ['notes'] + + def get_context_data(self, **kwargs): + + part = self.get_object() + + ctx = super().get_context_data(**kwargs) + + ctx['editing'] = str2bool(self.request.GET.get('edit', '')) + + ctx['starred'] = part.isStarredBy(self.request.user) + ctx['disabled'] = not part.active + + ctx['OrderStatus'] = OrderStatus + + return ctx + + class PartDetail(DetailView): """ Detail view for Part object """