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 }} + +
+ {% include "website/inputs/markdown.html" with form=form form_field=form.description %}
diff --git a/inventory/templates/inventory/equipment/equipment_edit.html b/inventory/templates/inventory/equipment/equipment_edit.html index 631c39b83..9c88d7c7a 100644 --- a/inventory/templates/inventory/equipment/equipment_edit.html +++ b/inventory/templates/inventory/equipment/equipment_edit.html @@ -2,8 +2,6 @@ {% load static %} {% block head %} - - {% endblock head %} @@ -62,4 +60,4 @@
Innhold
-{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/inventory/templates/inventory/item_detail.html b/inventory/templates/inventory/item_detail.html index cb07c35a7..f0e005639 100644 --- a/inventory/templates/inventory/item_detail.html +++ b/inventory/templates/inventory/item_detail.html @@ -46,7 +46,7 @@
{% if item.description %}
{% autoescape off %} - {{ item.description }} + {{ item.body_formatted_markdown | safe }} {% endautoescape %} {% endif %} diff --git a/news/migrations/0001_initial.py b/news/migrations/0001_initial.py index 4b02afd76..b8d13d1a0 100644 --- a/news/migrations/0001_initial.py +++ b/news/migrations/0001_initial.py @@ -2,7 +2,6 @@ # Generated by Django 1.9.2 on 2017-05-04 23:34 from __future__ import unicode_literals -import ckeditor_uploader.fields from django.conf import settings from django.db import migrations, models import django.db.models.deletion @@ -24,8 +23,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('title', models.CharField(max_length=100, verbose_name='Title')), - ('main_content', ckeditor_uploader.fields.RichTextUploadingField(blank=True)), - ('ingress_content', ckeditor_uploader.fields.RichTextUploadingField(blank=True)), + ('main_content', models.TextField(blank=True)), + ('ingress_content', models.TextField(blank=True)), ('internal', models.BooleanField(default=False, verbose_name='Intern')), ('pub_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Publication date')), ('thumbnail', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='files.Image')), @@ -39,8 +38,8 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('title', models.CharField(max_length=100, verbose_name='Tittel')), - ('main_content', ckeditor_uploader.fields.RichTextUploadingField(blank=True, verbose_name='Artikkel')), - ('ingress_content', ckeditor_uploader.fields.RichTextUploadingField(blank=True, verbose_name='Ingress')), + ('main_content', models.TextField(blank=True, verbose_name='Artikkel')), + ('ingress_content', models.TextField(blank=True, verbose_name='Ingress')), ('pub_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Publiseringsdato')), ('internal', models.BooleanField(default=False, verbose_name='Intern')), ('registration', models.BooleanField(default=False, verbose_name='Påmelding')), diff --git a/news/migrations/0028_auto_20210210_2032.py b/news/migrations/0028_auto_20210210_2032.py index e93cc6ad5..e40dfeb57 100644 --- a/news/migrations/0028_auto_20210210_2032.py +++ b/news/migrations/0028_auto_20210210_2032.py @@ -1,6 +1,5 @@ # Generated by Django 3.1.1 on 2021-02-10 20:32 -import ckeditor_uploader.fields import django.core.validators from django.db import migrations, models @@ -25,7 +24,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='article', name='main_content', - field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, verbose_name='Brødtekst'), + field=models.TextField(blank=True, verbose_name='Brødtekst'), ), migrations.AlterField( model_name='article', @@ -40,6 +39,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='event', name='main_content', - field=ckeditor_uploader.fields.RichTextUploadingField(blank=True, verbose_name='Hovedtekst'), + field=models.TextField(blank=True, verbose_name='Hovedtekst'), ), ] diff --git a/news/templates/news/article.html b/news/templates/news/article.html index 5f8ac5539..8e4e2dad4 100644 --- a/news/templates/news/article.html +++ b/news/templates/news/article.html @@ -164,19 +164,4 @@
{% trans 'Neste artikkel' %}
- {% endblock content %} diff --git a/news/templates/news/edit_article.html b/news/templates/news/edit_article.html index 2c64abaf5..66f22359d 100644 --- a/news/templates/news/edit_article.html +++ b/news/templates/news/edit_article.html @@ -3,8 +3,6 @@ {% load static %} {% block head %} - - {% endblock head %} @@ -35,15 +33,8 @@
{% trans "Innhold" %}
-

{{ 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." %}

-

Markdown cheat-sheet

-
+ {% include "website/inputs/markdown.html" with form=form form_field=form.main_content%}
- {{ form.media }}
diff --git a/news/templates/news/edit_event.html b/news/templates/news/edit_event.html index b5904ec47..45f71dac4 100644 --- a/news/templates/news/edit_event.html +++ b/news/templates/news/edit_event.html @@ -3,8 +3,6 @@ {% load static %} {% block head %} - -