Skip to content

Commit

Permalink
add markdown description field
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Apr 4, 2024
1 parent db597ec commit 3476717
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
2 changes: 1 addition & 1 deletion DOSPORTAL/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from .models import *

from markdownx.admin import MarkdownxModelAdmin

from import_export import resources
from import_export.admin import ImportExportModelAdmin
Expand Down
6 changes: 5 additions & 1 deletion DOSPORTAL/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm

from markdownx.fields import MarkdownxFormField

class LoginForm(forms.Form):
username = forms.CharField(
Expand Down Expand Up @@ -81,6 +81,10 @@ def __init__(self,*args, user=None, **kwargs):
help_text="Select used detector. It is not mandatory in case of detectors with auto-detect feature."
)

description = MarkdownxFormField(

)

record_type = forms.ChoiceField(
choices=Record.RECORD_TYPES
)
Expand Down
19 changes: 19 additions & 0 deletions DOSPORTAL/migrations/0009_record_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.11 on 2024-04-04 16:43

from django.db import migrations
import markdownx.models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0008_record_created_alter_record_data_file'),
]

operations = [
migrations.AddField(
model_name='record',
name='description',
field=markdownx.models.MarkdownxField(blank=True, help_text='Description of the record', verbose_name='Description'),
),
]
15 changes: 12 additions & 3 deletions DOSPORTAL/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.contrib.gis.db import models as geomodels

from markdownx.models import MarkdownxField
import json
from markdownx.utils import markdownify

from .tasks import process_flight_entry, process_record_entry

Expand Down Expand Up @@ -472,6 +473,11 @@ def user_directory_path_data(instance, filename):
blank=True
)

description = MarkdownxField(
verbose_name=_("Description"),
help_text=_("Description of the record"),
blank=True
)

log_original_filename = models.CharField(
verbose_name = _("Original filename of log file"),
Expand Down Expand Up @@ -552,10 +558,13 @@ def save(self, *args, **kwargs):
def __str__(self) -> str:
return "record ({}, {}, start {}, {})".format(self.belongs, self.log_original_filename, self.time_start, 0)

def description(self) -> str:
return "Record ({}, {})".format(get_enum_dsc(self.RECORD_TYPES, self.record_type), self.time_start.strftime("%Y-%m-%d_%H:%M"))
# def description(self) -> str:
# return "Record ({}, {})".format(get_enum_dsc(self.RECORD_TYPES, self.record_type), self.time_start.strftime("%Y-%m-%d_%H:%M"))


@property
def formatted_markdown(self):
return markdownify(self.description)



Expand Down
6 changes: 5 additions & 1 deletion DOSPORTAL/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@
'crispy_forms',
'crispy_bootstrap5',
'django_gravatar',

'markdownx',

'prettyjson',
'organizations',
]

MARKDOWNX_MARKDOWN_EXTENSIONS = [
'markdown.extensions.extra'
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down
26 changes: 13 additions & 13 deletions DOSPORTAL/templates/records/record_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<script charset="utf-8" src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>

<nav aria-label="breadcrumb">
<!-- <nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a>Records</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ record.id }}</li>
</ol>
</nav>
</nav> -->

<div class="card my-4">
<div class="card-header d-flex justify-content-between">
Expand All @@ -30,18 +30,18 @@
<li><strong>Detector:</strong> <a href="/detector/{{record.detector.id}}">{{ record.detector }}</a>
<li><strong>Record start time:</strong> {{ record.time_start }}
<li><strong>Record duration:</strong> {{ record.record_duration }}</li>
<li><strong>Type:</strong> {{ record.record_type }}
<li><strong>Organization:</strong> {{ record.belongs }}, {{record.data_policy}}, {{record.author}}</li>
<li><strong>Type:</strong> {{ record.get_record_type_display }}
<li><strong>Author:</strong> {{record.author}} behalf of {{ record.belongs }}, Log is {{record.get_data_policy_display}}, {{record.author}}</li>
{% if record.metadata|length > 4 %}
<li><strong>Advanced metadata:</strong></li>
<div class="callout">{{ record.metadata }}</div>
<li><strong>Description:</strong> {{record}}
<div class="callout">{{ record.metadata }}</div>
{% endif %}
{% if record.description|length > 1 %}
<li><strong>Description:</strong>
<div class="callout"> {{record.formatted_markdown | safe }} </div>
{% endif %}
<li><strong>Log file: </strong> {{record.log_original_filename}} ({{ record.log_file | filesize_mb }})

<li>{{record.log_file}}</li>
<li>{{record.log_file.size}}</li>
<li>{{record.log_file.url}}</li>
<li>{{record.log_original_filename}}</li>
<li>{{record.data_file}}</li>
</ul>
</div>
</div>
Expand All @@ -59,15 +59,15 @@ <h3>Graphs:</h3>
</div>
</div>


<!--
<div class="card my-4">
<div class="card-header">
<h3>Energetic spectrogram:</h3>
</div>
<div class="card-body p-1">
<div id="graph2" style="width:100%;height:1000px;"></div>
</div>
</div>
</div> -->

</div>

Expand Down
1 change: 1 addition & 0 deletions DOSPORTAL/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
path("accounts/", include("django.contrib.auth.urls")),

path('login/', login_view, name='login'),
path('markdownx/', include('markdownx.urls')),

#path(r'accounts/', include('organizations.urls')),
#path(r'invitations/', include(invitation_backend().get_urls())),
Expand Down

0 comments on commit 3476717

Please sign in to comment.