2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

Markdownify the notes field for Build model

This commit is contained in:
Oliver Walters
2020-02-02 00:00:19 +11:00
parent 51fab36074
commit a7846940c4
11 changed files with 461 additions and 209 deletions

View File

@ -26,7 +26,6 @@ class EditBuildForm(HelperForm):
'take_from',
'batch',
'URL',
'notes',
]

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.9 on 2020-02-01 12:47
from django.db import migrations
import markdownx.models
class Migration(migrations.Migration):
dependencies = [
('build', '0007_auto_20191118_2321'),
]
operations = [
migrations.AlterField(
model_name='build',
name='notes',
field=markdownx.models.MarkdownxField(blank=True, help_text='Extra build notes'),
),
]

View File

@ -16,6 +16,8 @@ from django.db import models, transaction
from django.db.models import Sum
from django.core.validators import MinValueValidator
from markdownx.models import MarkdownxField
from InvenTree.status_codes import BuildStatus
from InvenTree.fields import InvenTreeURLField
@ -92,7 +94,7 @@ class Build(models.Model):
URL = InvenTreeURLField(blank=True, help_text=_('Link to external URL'))
notes = models.TextField(blank=True, help_text=_('Extra build notes'))
notes = MarkdownxField(blank=True, help_text=_('Extra build notes'))
@transaction.atomic
def cancelBuild(self, user):

View File

@ -1,74 +1,67 @@
{% extends "build/build_base.html" %}
{% load static %}
{% load i18n %}
{% block details %}
{% include "build/tabs.html" with tab='details' %}
<h4>Build Details</h4>
<h4>{% trans "Build Details" %}</h4>
<hr>
<table class='table table-striped'>
<tr>
<td>Title</td><td>{{ build.title }}</td>
<td>{% trans "Title" %}</td><td>{{ build.title }}</td>
</tr>
<tr>
<td>Part</td><td><a href="{% url 'part-build' build.part.id %}">{{ build.part.full_name }}</a></td>
<td>{% trans "Part" %}</td><td><a href="{% url 'part-build' build.part.id %}">{{ build.part.full_name }}</a></td>
</tr>
<tr>
<td>Quantity</td><td>{{ build.quantity }}</td>
<td>{% trans "Quantity" %}</td><td>{{ build.quantity }}</td>
</tr>
<tr>
<td>Stock Source</td>
<td>{% trans "Stock Source" %}</td>
<td>
{% if build.take_from %}
<a href="{% url 'stock-location-detail' build.take_from.id %}">{{ build.take_from }}</a>
{% else %}
Stock can be taken from any available location.
{% trans "Stock can be taken from any available location." %}
{% endif %}
</td>
</tr>
<tr>
<td>Status</td><td>{% include "build_status.html" with build=build %}</td>
<td>{% trans "Status" %}</td><td>{% include "build_status.html" with build=build %}</td>
</tr>
{% if build.batch %}
<tr>
<td>Batch</td><td>{{ build.batch }}</td>
<td>{% trans "Batch" %}</td><td>{{ build.batch }}</td>
</tr>
{% endif %}
{% if build.URL %}
<tr>
<td>URL</td><td><a href="{{ build.URL }}">{{ build.URL }}</a></td>
<td>{% trans "URL" %}</td><td><a href="{{ build.URL }}">{{ build.URL }}</a></td>
</tr>
{% endif %}
<tr>
<td>Created</td><td>{{ build.creation_date }}</td>
<td>{% trans "Created" %}</td><td>{{ build.creation_date }}</td>
</tr>
{% if build.is_active %}
<tr>
<td>Enough Parts?</td>
<td>{% trans "Enough Parts?" %}</td>
<td>
{% if build.can_build %}
Yes
{% trans "Yes" %}
{% else %}
No
{% trans "No" %}
{% endif %}
</td>
</tr>
{% endif %}
{% if build.completion_date %}
<tr>
<td>Completed</td><td>{{ build.completion_date }}{% if build.completed_by %}<span class='badge'>{{ build.completed_by }}</span>{% endif %}</td>
<td>{% trans "Completed" %}</td><td>{{ build.completion_date }}{% if build.completed_by %}<span class='badge'>{{ build.completed_by }}</span>{% endif %}</td>
</tr>
{% endif %}
</table>
{% if build.notes %}
<div class="panel panel-default">
<div class="panel-heading"><b>Notes</b></div>
<div class="panel-body">{{ build.notes }}</div>
</div>
{% endif %}
{% endblock %}

View File

@ -0,0 +1,56 @@
{% extends "build/build_base.html" %}
{% load static %}
{% load i18n %}
{% load markdownify %}
{% block details %}
{% include "build/tabs.html" with tab='notes' %}
{% if editing %}
<h4>{% trans "Build Notes" %}</h4>
<hr>
<form method='POST'>
{% csrf_token %}
{{ form }}
<hr>
<input type="submit" value='{% trans "Save" %}'/>
</form>
{{ form.media }}
{% else %}
<div class='row'>
<div class='col-sm-6'>
<h4>{% trans "Build Notes" %}</h4>
</div>
<div class='col-sm-6'>
<button title='{% trans "Edit notes" %}' class='btn btn-default btn-glyph float-right' id='edit-notes'><span class='glyphicon glyphicon-edit'></span></button>
</div>
</div>
<hr>
<div class='panel panel-default'>
<div class='panel-content'>
{{ build.notes | markdownify }}
</div>
</div>
{% endif %}
{% endblock %}
{% block js_ready %}
{{ block.super }}
{% if editing %}
{% else %}
$("#edit-notes").click(function() {
location.href = "{% url 'build-notes' build.id %}?edit=1";
});
{% endif %}
{% endblock %}

View File

@ -1,8 +1,13 @@
{% load i18n %}
<ul class='nav nav-tabs'>
<li{% if tab == 'details' %} class='active'{% endif %}>
<a href="{% url 'build-detail' build.id %}">Details</a>
<a href="{% url 'build-detail' build.id %}">{% trans "Details" %}</a>
</li>
<li{% if tab == 'notes' %} class='active'{% endif %}>
<a href="{% url 'build-notes' build.id %}">{% trans "Notes" %}</a>
</li>
<li{% if tab == 'allocate' %} class='active'{% endif %}>
<a href="{% url 'build-allocate' build.id %}">Assign Parts</a>
<a href="{% url 'build-allocate' build.id %}">{% trans "Assign Parts" %}</a>
</li>
</ul>

View File

@ -25,6 +25,7 @@ build_detail_urls = [
url(r'^auto-allocate/?', views.BuildAutoAllocate.as_view(), name='build-auto-allocate'),
url(r'^unallocate/', views.BuildUnallocate.as_view(), name='build-unallocate'),
url(r'^notes/', views.BuildNotes.as_view(), name='build-notes'),
url(r'^.*$', views.BuildDetail.as_view(), name='build-detail'),
]

View File

@ -7,8 +7,9 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext as _
from django.core.exceptions import ValidationError
from django.views.generic import DetailView, ListView
from django.views.generic import DetailView, ListView, UpdateView
from django.forms import HiddenInput
from django.urls import reverse
from part.models import Part
from .models import Build, BuildItem
@ -309,6 +310,28 @@ class BuildComplete(AjaxUpdateView):
}
class BuildNotes(UpdateView):
""" View for editing the 'notes' field of a Build object.
"""
context_object_name = 'build'
template_name = 'build/notes.html'
model = Build
fields = ['notes']
def get_success_url(self):
return reverse('build-notes', kwargs={'pk': self.get_object().id})
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)
ctx['editing'] = str2bool(self.request.GET.get('edit', ''))
return ctx
class BuildDetail(DetailView):
""" Detail view of a single Build object. """
model = Build