Skip to content

Commit

Permalink
Merge pull request #802 from hackerspace-ntnu/ckeditor-to-markdown
Browse files Browse the repository at this point in the history
Ckeditor to markdown
  • Loading branch information
michaelbrusegard authored Apr 11, 2024
2 parents ac91eae + 2dba2a6 commit 99e7bad
Show file tree
Hide file tree
Showing 33 changed files with 138 additions and 220 deletions.
5 changes: 2 additions & 3 deletions inventory/migrations/0006_auto_20201021_0135.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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'),
),
]
3 changes: 1 addition & 2 deletions inventory/migrations/0007_auto_20201021_0154.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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',
Expand Down
19 changes: 19 additions & 0 deletions inventory/migrations/0031_alter_item_description.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
29 changes: 19 additions & 10 deletions inventory/models/item.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) + ")"
Expand Down Expand Up @@ -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)
9 changes: 3 additions & 6 deletions inventory/templates/inventory/edit_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

{% block head %}
{{ jquery | safe }}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'inventory/css/inventory.css' %}">
{% endblock head %}

Expand Down Expand Up @@ -63,10 +61,9 @@
</div>
</div>

<div class="input-field">
<p>{{ form.description.label }}</p>
<span class="helper-text hs-red-text">{{ form.description.errors }}</span>
{{ form.description }}

<div class="input-field col s12">
{% include "website/inputs/markdown.html" with form=form form_field=form.description %}
</div>

<div>
Expand Down
4 changes: 1 addition & 3 deletions inventory/templates/inventory/equipment/equipment_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{% load static %}

{% block head %}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'news/css/news_style.css' %}">
{% endblock head %}

Expand Down Expand Up @@ -62,4 +60,4 @@ <h5>Innhold</h5>
</div>
</form>
</div>
{% endblock content %}
{% endblock content %}
2 changes: 1 addition & 1 deletion inventory/templates/inventory/item_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h6>
{% if item.description %}
<div class="divider"></div>
{% autoescape off %}
{{ item.description }}
{{ item.body_formatted_markdown | safe }}
{% endautoescape %}
{% endif %}

Expand Down
9 changes: 4 additions & 5 deletions news/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')),
Expand All @@ -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')),
Expand Down
5 changes: 2 additions & 3 deletions news/migrations/0028_auto_20210210_2032.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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',
Expand All @@ -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'),
),
]
15 changes: 0 additions & 15 deletions news/templates/news/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,4 @@ <h5 class="hs-grey-text">{% trans 'Neste artikkel' %}</h5>
</div>

</div>
<script>
// Prevent ckeditor hard fields to allow responsive images
window.addEventListener('DOMContentLoaded', function(event) {
var container = document.getElementsByClassName('card-panel')[0];
var images = container.getElementsByTagName("img");
console.log(images);
var i;

for(i = 0; i < images.length; i++) {
images[i].className = "responsive-img";
images[i].style.height = "";
}
});

</script>
{% endblock content %}
11 changes: 1 addition & 10 deletions news/templates/news/edit_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{% load static %}

{% block head %}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'news/css/news_style.css' %}">
{% endblock head %}

Expand Down Expand Up @@ -35,15 +33,8 @@ <h5>{% trans "Innhold" %}</h5>
</div>

<div class="input-field col s12">
<p>{{ form.main_content.label }}</p>
<span class="helper-text hs-red-text">{{ form.main_content.errors }}</span>
{{ form.main_content }}
<div class="helper-text">
<p>{% trans "Bare markdown støttes i dette feltet, html blir returnert som plaintext. Bilder kan legges til ved drag-and-drop." %}</p>
<p><a href="https://www.markdownguide.org/cheat-sheet/">Markdown cheat-sheet</a></p>
</div>
{% include "website/inputs/markdown.html" with form=form form_field=form.main_content%}
</div>
{{ form.media }}

<div class="col s12 input-field">
<div class="col s12">
Expand Down
11 changes: 1 addition & 10 deletions news/templates/news/edit_event.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{% load static %}

{% block head %}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'news/css/news_style.css' %}">
<link href="{% static 'website/css/select2.min.css' %}" rel="stylesheet" />
<style>
Expand Down Expand Up @@ -49,15 +47,8 @@ <h5>{% trans "Innhold" %}</h5>
<span class="helper-text hs-red-text">{{ form.ingress_content.errors }}</span>
</div>
<div class="input-field col s12">
<p>{{ form.main_content.label }}</p>
<span class="helper-text hs-red-text">{{ form.main_content.errors }}</span>
{{ form.main_content }}
<div class="helper-text">
<p>{% trans "Bare markdown støttes i dette feltet, html blir returnert som plaintext. Bilder kan legges til ved drag-and-drop." %}</p>
<p><a href="https://www.markdownguide.org/cheat-sheet/">Markdown cheat-sheet</a></p>
</div>
{% include "website/inputs/markdown.html" with form=form form_field=form.main_content%}
</div>
{{ form.media }}
</div>
</div>
<div class="card-panel">
Expand Down
15 changes: 0 additions & 15 deletions news/templates/news/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,4 @@ <h4>{% trans 'Informasjon om påmelding' %}</h4>
</div>
</form>
</div>

<script>
// Prevent ckeditor hard fields to allow responsive images
window.addEventListener('DOMContentLoaded', function(event) {
var container = document.getElementsByClassName('card-panel')[0];
var images = container.getElementsByTagName("img");
console.log(images);
var i;

for(i = 0; i < images.length; i++) {
images[i].className = "responsive-img";
images[i].style.height = "";
}
});
</script>
{% endblock content %}
3 changes: 1 addition & 2 deletions projectarchive/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 3.1.7 on 2022-01-19 20:29

import ckeditor_uploader.fields
from django.conf import settings
import django.core.validators
from django.db import migrations, models
Expand Down Expand Up @@ -33,7 +32,7 @@ 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='Brødtekst')),
('main_content', models.TextField(blank=True, verbose_name='Brødtekst')),
('ingress_content', models.TextField(blank=True, help_text='En kort introduksjon til teksten', max_length=400, validators=[django.core.validators.MaxLengthValidator(400)], verbose_name='Ingress')),
('internal', models.BooleanField(default=False, verbose_name='Intern artikkel')),
('pub_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Publication date')),
Expand Down
15 changes: 0 additions & 15 deletions projectarchive/templates/projectarchive/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,4 @@ <h5>Administrator-meny</h5>


</div>
<script>
// Prevent ckeditor hard fields to allow responsive images
window.addEventListener('DOMContentLoaded', function(event) {
var container = document.getElementsByClassName('card-panel')[0];
var images = container.getElementsByTagName("img");
console.log(images);
var i;

for(i = 0; i < images.length; i++) {
images[i].className = "responsive-img";
images[i].style.height = "";
}
});

</script>
{% endblock content %}
2 changes: 0 additions & 2 deletions projectarchive/templates/projectarchive/edit_article.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
{% load i18n %}

{% block head %}
<script src="{% static 'ckeditor/ckeditor/ckeditor.js' %}"></script>
<script src="{% static 'ckeditor/ckeditor-init.js' %}"></script>
<link rel="stylesheet" type="text/css" href="{% static 'projectarchive/css/projectarchive_style.css' %}">
{% endblock head %}

Expand Down
3 changes: 1 addition & 2 deletions userprofile/migrations/0026_auto_20200211_1917.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 3.0.2 on 2020-02-11 19:17

import ckeditor_uploader.fields
from django.db import migrations, models
import django.utils.timezone

Expand All @@ -20,6 +19,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='termsofservice',
name='text',
field=ckeditor_uploader.fields.RichTextUploadingField(blank=True),
field=models.TextField(blank=True),
),
]
5 changes: 2 additions & 3 deletions userprofile/migrations/0027_auto_20200211_1945.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.0.2 on 2020-02-11 19:45

import ckeditor.fields
from django.db import migrations
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -14,6 +13,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='termsofservice',
name='text',
field=ckeditor.fields.RichTextField(blank=True),
field=models.TextField(blank=True),
),
]
3 changes: 1 addition & 2 deletions userprofile/migrations/0029_auto_20200304_2007.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 3.0.2 on 2020-03-04 20:07

import ckeditor.fields
from django.db import migrations, models


Expand All @@ -26,7 +25,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='termsofservice',
name='text',
field=ckeditor.fields.RichTextField(),
field=models.TextField(),
),
migrations.DeleteModel(
name='Skill',
Expand Down
Loading

0 comments on commit 99e7bad

Please sign in to comment.