mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-20 15:05:12 +00:00
[Refactor] Notes (#11971)
* Display note info
* Support user locale
* Add unit testing for HTML content
* Observe color mode
* Add link between Note and NotesImage
* Ensure image file is deleted when NotesImage is deleted
* Add support for image upload in editor
* Skeleton for data migration
* Updates
* Update data migration
- Find any NoteImage items which do not link to a model
- Try to associate them with an existing note
* Remove validator
* Updated API endpoints for NotesImage model
* Update server side sanitizing
* Specify max field length
* Remove old fields from NotesImage model
* Refactor clean_string
* Remove obsolete task
* Remove legacy "notes" field from older models
* Adjust search params when switching notes
* Remove NotesFieldMixin
* Change editor
* Resizable image support
* Support tables
* Add table style
* Adjust header actions
* Add data migration for SalesOrderShipment notes
* Adjust back-end sanitizing
* Adjust
* Use subtle editor variant
* Move undo/redo
* Enhance editing logic
* Add report tags for notes
* Add unit test for note image cleanup
* Render note to HTML
- Automatically replace images
* Fix migration order
* Adjust migration text
* Fix "dirty" trigger on notes
* Prevent navigate from dirty notes
* Add documentation
* Prevent image clicking if not in editing mode
* Update API
* Update migration files
* Fix migrations
* remove notes from test fixtures
* remove notes field that does not exsist anymore
* add missing ruleset
* fix assertation
* fix assertation
* Update docs/docs/concepts/notes.md
Co-authored-by: Matthias Mair <code@mjmair.com>
* Remove blocknote deps
* Move old helper functions
- Only used for this migration
- Will potentially be removed at some point in the future?
* Revert change
* Fix note image URL
* Fix migration conflicts
* Fix migrations
* Fix delete call
* Fix content mixin
* Fix note duplication
* Make save method atomic
* Fix double-save
* Add "template" field to Note model
* Adjust migrations
* Frontend updates
* Fix for NotesEditor
* Render Note instance in forms
* Fix button-within-button
* Fix migrations
* Fix missing import
* add docs
* docs for rendering notes in reports
* Restrict queryset based on user view permissions
* APi unit tests for note permissions
* Duplicate embedded images when copying notes
* Add unit test for note duplication
* Add CHANGELOG
* Add 'copy_note' option to duplicate serializer
* Add unit tests for data migrations
* implement note duplication serializers
* frontend UI elements
* Fix migration conflicts
* Use branch for playwrigh testing
* Implement duplicate action for stock item
* Fix import
* Updated playwright tests
* Bug fix for receiving stock items
* Add screenshot
* Fix api_version
* Update unit tests
* Fix docs
* Remove defunct tests
* Fix migration order
* Adjust import/export workflow
* Manual cleaning update
* Fix migrations
* Fix migration files
* Fix for note save
* Adjust save ordering
* Skip constraint checking in NoteSerializer
* Custom validate_constraints on Note model
* Revert "Skip constraint checking in NoteSerializer"
This reverts commit b42bc955c1.
* Fix for note search
* Fix for receive_line_items
* Shim model renderer for NoteTemplate
* Fix playwright tests
* Adjust frontend CI
* Fix import/export CI job
* Fix for data migration test
* Fix migration test
* Adjust unit test
* Fix conflicting migration
* Fix unit test
* Run migration tests in parallel
* Robustify migration test
* Disable parallel options
* Fix conflicting migration
* Remove extraneous unit test
* Fix conflicting migrations
* Additional regression tests
* Check permissions before deleting Note instance
* Updated docs
* Validate note model type
* Prevent discard of unsaved changes in note editor
* Clean up dead code
* Fix migration conflict
* Improved data migration
* Prefetch role groups
* UI refactoring
* Refactor permission checking code
* Further code refactoring
* use DuplicateField helper
* Refactoring
* Add prefetch
* Throw exception rather than assert
* Logic fix for notes editor
* reimplement old background task
* Adjust data migration
* Fix notes field when receiving items
* Fix existing report templates
* Fix save action for notes editor
* Refactoring: Add "instance-info" API endpoint for common model properties
* Fix indicator dots
* Tweak nav alert msg
* Adjust layout of buttons
* Sanitize notes during migration
* Fix for NotesImage delete cascade
* Fix caching
* Fix race condition in notes editor
* Fix distinct issue when searching notse
* Fix race condition when saving new note instance
* Fix improper error
* Refactor StockItem duplication
* Refactoring
* Increase query time
* Fix api_version.py
* Additional migration tests
* Fix CI workflow
---------
Co-authored-by: Matthias Mair <code@mjmair.com>
This commit is contained in:
1 parent
d39d0262e6
commit
02da01dfec
108 files changed
+6902
-1643
No files matched your search
@@ -979,9 +979,98 @@ Length: {{ length_value }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
[Notes](../concepts/notes.md) are rich-text documents that can be attached to most InvenTree model instances. Two template tags are available for accessing note content in a report.
|
||||
|
||||
### note
|
||||
|
||||
The `note` tag returns the rendered HTML content of a note, ready to embed directly in a report. Any images embedded in the note are automatically resolved to their base64-encoded data so that they appear in the generated PDF.
|
||||
|
||||
::: report.templatetags.report.note
|
||||
options:
|
||||
show_docstring_description: false
|
||||
show_source: False
|
||||
|
||||
If no `title` argument is given, the [primary note](../concepts/notes.md#primary-note) is returned. If a `title` is given, the note whose title matches (case-insensitively) is returned instead. An empty string is returned when no matching note exists.
|
||||
|
||||
#### Example
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% load report %}
|
||||
|
||||
<!-- Render the primary note for the part -->
|
||||
{% note part as part_note %}
|
||||
<div>{{ part_note }}</div>
|
||||
|
||||
<!-- Render a note by title -->
|
||||
{% note part "Assembly Instructions" as instructions %}
|
||||
<div>{{ instructions }}</div>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
!!! info "Safe HTML Output"
|
||||
The `note` tag returns pre-sanitized HTML and is marked safe for direct template rendering. Do **not** additionally wrap it with `| safe` or `| markdownify` — the content has already been processed.
|
||||
|
||||
### note_instance
|
||||
|
||||
The `note_instance` tag returns the `Note` object itself, giving access to its individual fields. This is useful when you need to display the note title, description, or metadata alongside its content.
|
||||
|
||||
::: report.templatetags.report.note_instance
|
||||
options:
|
||||
show_docstring_description: false
|
||||
show_source: False
|
||||
|
||||
A `Note` object exposes the following attributes:
|
||||
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| `title` | The title of the note |
|
||||
| `description` | An optional short description of the note |
|
||||
| `content` | The raw HTML content of the note |
|
||||
| `primary` | `True` if this is the primary note for the model instance |
|
||||
| `updated` | Timestamp of the last modification |
|
||||
| `updated_by` | The user who last modified the note |
|
||||
|
||||
#### Example
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% load report %}
|
||||
|
||||
{% note_instance part as primary_note %}
|
||||
{% if primary_note %}
|
||||
<h3>{{ primary_note.title }}</h3>
|
||||
{% if primary_note.description %}<p><em>{{ primary_note.description }}</em></p>{% endif %}
|
||||
{% note part as note_content %}
|
||||
<div>{{ note_content }}</div>
|
||||
{% endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
### Iterating Over All Notes
|
||||
|
||||
When a model has multiple notes and you want to render all of them, access the `notes` queryset directly:
|
||||
|
||||
```html
|
||||
{% raw %}
|
||||
{% load report %}
|
||||
|
||||
{% for n in part.notes.all %}
|
||||
<h3>{{ n.title }}</h3>
|
||||
{% note part n.title as note_content %}
|
||||
<div>{{ note_content }}</div>
|
||||
{% endfor %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
## Rendering Markdown
|
||||
|
||||
Some data fields (such as the *Notes* field available on many internal database models) support [markdown formatting](https://en.wikipedia.org/wiki/Markdown). To render markdown content in a custom report, there are template filters made available through the [django-markdownify](https://github.com/erwinmatijsen/django-markdownify) library. This library provides functionality for converting markdown content to HTML representation, allowing it to be then rendered to PDF by the InvenTree report generation pipeline.
|
||||
Some data fields (such as those provided by custom plugin models) may support [markdown formatting](https://en.wikipedia.org/wiki/Markdown). To render markdown content in a custom report, there are template filters made available through the [django-markdownify](https://github.com/erwinmatijsen/django-markdownify) library. This library provides functionality for converting markdown content to HTML representation, allowing it to be then rendered to PDF by the InvenTree report generation pipeline.
|
||||
|
||||
!!! info "Notes"
|
||||
[Notes](../concepts/notes.md) content is rich-text (stored as HTML) rather than markdown, and is already sanitized. Use the [note](#note) tag to render it - do not pass it through `markdownify`.
|
||||
|
||||
To render markdown content in a report, consider the following simplified example:
|
||||
|
||||
@@ -990,9 +1079,9 @@ To render markdown content in a report, consider the following simplified exampl
|
||||
|
||||
{% load markdownify %}
|
||||
|
||||
<h3>Part Notes</h3>
|
||||
<h3>Description</h3>
|
||||
<p>
|
||||
{{ part.notes | markdownify }}
|
||||
{{ some_markdown_field | markdownify }}
|
||||
</p>
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user