Skip to content

Commit

Permalink
dosportal improvement, view of users, records, ..
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Dec 3, 2023
1 parent 8f43177 commit 14a92df
Show file tree
Hide file tree
Showing 22 changed files with 802 additions and 175 deletions.
Empty file added DOSPORTAL/detectors/__init__.py
Empty file.
53 changes: 53 additions & 0 deletions DOSPORTAL/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from django import forms
from .models import Detector, record


class DetectorLogblogForm(forms.Form):
text = forms.CharField(
widget=forms.Textarea(
attrs={
'class': 'form-control'
}
)
)



class RecordForm(forms.ModelForm):
log_file = forms.FileField(
required=False,
widget=forms.widgets.FileInput(attrs={
'class': 'form-control',
}),
label="Log file",
#widget=forms.FileInput(attrs={
# 'class': 'form-control',
#})
)

detector = forms.ModelChoiceField(
queryset=Detector.objects.all(),
widget=forms.Select(attrs={
'class': 'form-control',
}),
required=False
)

record_type = forms.ChoiceField(
choices=record.RECORD_TYPES,
widget=forms.Select(attrs={
'class': 'form-control',
})
)

time_start = forms.DateTimeField(
widget=forms.DateTimeInput(attrs={
'type': "datetime-local",
'class': 'form-control datetimepicker-input',
})
)


class Meta:
model = record
exclude = ("time_end", "measurement", "log_filename", "metadata", "duration")
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.7 on 2023-12-03 10:54

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0029_carimodel_flight_cari'),
]

operations = [
migrations.AlterField(
model_name='flight',
name='cari',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='DOSPORTAL.carimodel'),
),
migrations.AlterField(
model_name='measurement',
name='flight',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='measurement', to='DOSPORTAL.flight', verbose_name='Reference na objekt s informacemi o letu'),
),
]
18 changes: 18 additions & 0 deletions DOSPORTAL/migrations/0031_detectorlogbook_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-12-03 16:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0030_alter_flight_cari_alter_measurement_flight'),
]

operations = [
migrations.AddField(
model_name='detectorlogbook',
name='public',
field=models.BooleanField(default=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.7 on 2023-12-03 17:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0031_detectorlogbook_public'),
]

operations = [
migrations.AddField(
model_name='detector',
name='data',
field=models.JSONField(default={}, help_text='Detector metadata, used for advanced data processing and maintaining', verbose_name='Detector data'),
preserve_default=False,
),
migrations.AlterField(
model_name='detectorlogbook',
name='public',
field=models.BooleanField(default=True, help_text='Private logbook will be visible for maintainers of detector and for dosportal admins.', verbose_name='Wish to be visible to everyone?'),
),
migrations.AlterField(
model_name='detectorlogbook',
name='text',
field=models.TextField(help_text='Detailed description of activity made on the detector.', verbose_name='Logbook text'),
),
]
18 changes: 18 additions & 0 deletions DOSPORTAL/migrations/0033_detector_manufactured_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-12-03 17:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0032_detector_data_alter_detectorlogbook_public_and_more'),
]

operations = [
migrations.AddField(
model_name='detector',
name='manufactured_date',
field=models.DateField(blank=True, help_text='Date when detector was manufactured', null=True, verbose_name='Manufactured date'),
),
]
23 changes: 23 additions & 0 deletions DOSPORTAL/migrations/0034_record_metadata_alter_detector_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-12-03 20:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0033_detector_manufactured_date'),
]

operations = [
migrations.AddField(
model_name='record',
name='metadata',
field=models.JSONField(help_text='record metadata, used for advanced data processing and maintaining', null=True, verbose_name='record_metadata'),
),
migrations.AlterField(
model_name='detector',
name='data',
field=models.JSONField(help_text='Detector metadata, used for advanced data processing and maintaining', verbose_name='Detector metadata'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.7 on 2023-12-03 21:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0034_record_metadata_alter_detector_data'),
]

operations = [
migrations.RemoveField(
model_name='record',
name='time_end',
),
migrations.AddField(
model_name='record',
name='record_duration',
field=models.DurationField(help_text='Duration of record', null=True, verbose_name='Record duration'),
),
]
37 changes: 29 additions & 8 deletions DOSPORTAL/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,19 @@ class Detector(UUIDMixin):
related_name="detectors"
)

manufactured_date = models.DateField(
_("Manufactured date"),
help_text=_("Date when detector was manufactured"),
null=True, blank=True
)

data = models.JSONField(
_("Detector metadata"),
help_text="Detector metadata, used for advanced data processing and maintaining"
)

def __str__(self) -> str:
return "Detector {} ({})".format(self.name, self.type.manufacturer.name)
return "Detector {} ({}), SN:{}".format(self.name, self.type.manufacturer.name, self.sn)

class DetectorLogbook(UUIDMixin):

Expand All @@ -210,8 +221,13 @@ class DetectorLogbook(UUIDMixin):
created = models.DateTimeField(auto_now_add=True)

text = models.TextField(
_("Description zásahu")
_("Logbook text"),
help_text="Detailed description of activity made on the detector."
)
public = models.BooleanField(
_("Wish to be visible to everyone?"),
help_text=_("Private logbook will be visible for maintainers of detector and for dosportal admins."),
default=True)

class measurement_campaign(UUIDMixin):

Expand Down Expand Up @@ -342,9 +358,6 @@ class record(UUIDMixin):
)

def user_directory_path(instance, filename):
# return "data/user_records/{0}/{1}".format(instance.user.id, filename)
print(".....")
print(instance.measurement.author.pk)
return "data/user_records/log_{1}".format(instance.measurement.author.pk, instance.pk)

log_file = models.FileField(
Expand All @@ -361,9 +374,11 @@ def user_directory_path(instance, filename):
null=True,
)

time_end = models.DateTimeField(
verbose_name = _("Measurement beginning time"),
null=True,

record_duration = models.DurationField(
verbose_name = _("Record duration"),
help_text=_("Duration of record"),
null=True
)


Expand All @@ -380,6 +395,12 @@ def user_directory_path(instance, filename):
help_text=_("Type of log file")
)

metadata = models.JSONField(
_("record_metadata"),
help_text=_("record metadata, used for advanced data processing and maintaining"),
null=True
)

def __str__(self) -> str:
return "record ({}, {}, start {}, {})".format( get_enum_dsc(self.RECORD_TYPES, self.record_type), self.id, self.time_start, 0)

Expand Down
3 changes: 3 additions & 0 deletions DOSPORTAL/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'bootstrap5',
#'background_task',
'django_json_widget',
'rest_framework',
'corsheaders',
'jquery',
'import_export',
'django_select2',
'martor',
'django_tables2',

'DOSPORTAL',
'django_q',
Expand Down
84 changes: 72 additions & 12 deletions DOSPORTAL/templates/detectors/detectors_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,58 @@
{% extends "base.html" %}

{% block content %}
<span class="pt-3">Detektor: <span class="h1">{{ detector.name }}</span> {% if user.is_authenticated %}<a href="{{detector.get_admin_url}}"> <i class="bi bi-pencil"></i></a>{%endif%}</span>
<h3 class="text-muted small">DOSPORTAL ID: {{ detector.id }}</h3>
<h3 class="text-muted small">Serial number: {{ detector.sn }}</h3>
<h3 class="text-muted small">Type: {{ detector.type }}</h3>
<hr>

<h2>Měření s tímto detektorem: </h2>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/detectors/">Detectors</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ detector.name }}</li>
</ol>
</nav>

<div class="card my-4">
<div class="card-header d-flex justify-content-between">
<span > Detector: <span class="h2">{{detector.name}} </span></span>
<span class="text-muted"> {{detector.id}}
{% if user.is_authenticated %}
<a href="{{detector.get_admin_url}}"><i class="bi bi-pencil"></i></a>
{%endif%}
</span>
</div>
<div class="card-body">
{% if detector.description %}
<div class="m-3 callout">
{{detector.description }}
</div>
{%endif%}
<ul>
{%for record in detector.records.all %}
<li> record {{record.id}} -> <a href="/measurement/{{ record.measurement.id }}/">{{ record.measurement }}</a>
{%endfor%}
</ul>
<li><strong>Serial number:</strong> {{ detector.sn }}</a>
<li><strong>Type:</strong> <a href="/detector_type/{{ detector.type.id }}/">{{ detector.type }}</a>
<li><strong>Advanced metadata:</strong></li>
<span class="ml-3">{{detector.data}}</span>
<li><strong>Measurements conducted with this detector:</strong>
<ul>
{%for record in detector.records.all %}
<li> <a href="/measurement/{{ record.measurement.id }}/">{{ record.measurement }}</a>
{%endfor%}
</ul>

<li><strong>Records created with this detector:</strong>
<ul>
{%for record in detector.records.all %}
<li> <a href="/record/{{ record.id }}/">{{ record.id }}</a>
{%endfor%}
</ul>
</ul>
</div>
</div>


</div>




<hr>
<h2>Servisní záznamy: </h2>
<h3>Servisní záznamy: </h3>
{% for logbook in detector.logbook.all %}
<div class="card mb-3">

Expand All @@ -33,5 +69,29 @@ <h2>Servisní záznamy: </h2>
</div>

{%endfor%}
{% if not detector.logbook.all %}

<div class="alert alert-warning" role="alert">
No log in logbook of this detector.
</div>
{%endif%}


<div class="card mb-5">
<div class="card-header">
<a class="small" type="button" data-bs-toggle="collapse" data-bs-target="#add_record_collapse" aria-expanded="false" aria-controls="collapseExample">
Add new service log
</a>

</div>
<div class="card-body collapse py-2" id="add_record_collapse">
<form method="post" action="new_logbook_record">
{% csrf_token %}
{{ DetectorLogblogForm.as_p }}
<button type="submit">Submit</button>
</form>

</div>
</div>

{% endblock %}
Loading

0 comments on commit 14a92df

Please sign in to comment.