diff --git a/inventory/migrations/0006_auto_20201021_0135.py b/inventory/migrations/0006_auto_20201021_0135.py index d4489ada6..37b6cda98 100644 --- a/inventory/migrations/0006_auto_20201021_0135.py +++ b/inventory/migrations/0006_auto_20201021_0135.py @@ -1,7 +1,6 @@ # Generated by Django 3.1.2 on 2020-10-21 01:35 -import ckeditor_uploader.fields -from django.db import migrations +from django.db import migrations, models class Migration(migrations.Migration): @@ -14,6 +13,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='item', name='description', - field=ckeditor_uploader.fields.RichTextUploadingField(verbose_name='Beskrivelse'), + field=models.TextField(verbose_name='Beskrivelse'), ), ] diff --git a/inventory/migrations/0007_auto_20201021_0154.py b/inventory/migrations/0007_auto_20201021_0154.py index 57c4f756c..d8d1dc3ee 100644 --- a/inventory/migrations/0007_auto_20201021_0154.py +++ b/inventory/migrations/0007_auto_20201021_0154.py @@ -1,6 +1,5 @@ # Generated by Django 3.1.2 on 2020-10-21 01:54 -import ckeditor_uploader.fields from django.db import migrations, models @@ -19,7 +18,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='item', name='description', - field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, verbose_name='Beskrivelse'), + field=models.TextField(blank=True, verbose_name='Beskrivelse'), ), migrations.AlterField( model_name='item', diff --git a/inventory/migrations/0031_alter_item_description.py b/inventory/migrations/0031_alter_item_description.py new file mode 100644 index 000000000..a2613a3fd --- /dev/null +++ b/inventory/migrations/0031_alter_item_description.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.3 on 2024-04-10 20:32 + +import markdownx.models +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('inventory', '0030_alter_itemloan_loan_from'), + ] + + operations = [ + migrations.AlterField( + model_name='item', + name='description', + field=markdownx.models.MarkdownxField(blank=True, verbose_name='Beskrivelse'), + ), + ] diff --git a/inventory/models/item.py b/inventory/models/item.py index 0b406ec50..3dfc0bab3 100644 --- a/inventory/models/item.py +++ b/inventory/models/item.py @@ -1,6 +1,10 @@ -from ckeditor_uploader.fields import RichTextUploadingField +from bleach import clean +from bleach_whitelist import markdown_attrs, markdown_tags from django.core.validators import MinValueValidator from django.db import models +from django.utils.translation import gettext_lazy as _ +from markdownx.models import MarkdownxField +from markdownx.utils import markdownify from files.models import Image from inventory.models.item_loan import ItemLoan @@ -9,22 +13,24 @@ class Item(models.Model): """Represents a single item in inventory""" - name = models.CharField("Navn", max_length=50) - stock = models.IntegerField("Lagerbeholdning", validators=[MinValueValidator(0)]) + name = models.CharField(_("Navn"), max_length=50) + stock = models.IntegerField(_("Lagerbeholdning"), validators=[MinValueValidator(0)]) unknown_stock = models.BooleanField( - "Ukjent lagerbeholdning", null=False, blank=False, default=False + _("Ukjent lagerbeholdning"), null=False, blank=False, default=False ) - can_loan = models.BooleanField("Kan lånes", null=False, blank=False, default=True) - description = RichTextUploadingField("Beskrivelse", blank=True) + can_loan = models.BooleanField( + _("Kan lånes"), null=False, blank=False, default=True + ) + description = MarkdownxField(_("Beskrivelse"), blank=True) thumbnail = models.ForeignKey( - Image, on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Bilde" + Image, on_delete=models.SET_NULL, null=True, blank=True, verbose_name=_("Bilde") ) - location = models.CharField("Hylleplass", max_length=50, blank=True) + location = models.CharField(_("Hylleplass"), max_length=50, blank=True) max_loan_duration = models.PositiveIntegerField( - "Maks lånevarighet (dager)", blank=True, null=True + _("Maks lånevarighet (dager)"), blank=True, null=True ) - views = models.IntegerField("Detaljsidevisninger", default=0, editable=True) + views = models.IntegerField(_("Detaljsidevisninger"), default=0, editable=True) def __str__(self): return self.name + " (x" + str(self.stock) + ")" @@ -82,3 +88,6 @@ def popularity(self): def save(self, *args, **kwargs): self.location = self.location.lower() return super(Item, self).save(*args, **kwargs) + + def body_formatted_markdown(self): + return clean(markdownify(self.description), markdown_tags, markdown_attrs) diff --git a/inventory/templates/inventory/edit_item.html b/inventory/templates/inventory/edit_item.html index 16647e6bd..cdf83b666 100644 --- a/inventory/templates/inventory/edit_item.html +++ b/inventory/templates/inventory/edit_item.html @@ -4,8 +4,6 @@ {% block head %} {{ jquery | safe }} - - {% endblock head %} @@ -63,10 +61,9 @@ -
{{ form.description.label }}
- {{ form.description.errors }} - {{ form.description }} + +{{ form.main_content.label }}
- {{ form.main_content.errors }} - {{ form.main_content }} -{% trans "Bare markdown støttes i dette feltet, html blir returnert som plaintext. Bilder kan legges til ved drag-and-drop." %}
- -