diff --git a/DOSPORTAL/forms.py b/DOSPORTAL/forms.py index e2b9ae7..bbe2f75 100644 --- a/DOSPORTAL/forms.py +++ b/DOSPORTAL/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import Detector, Record, Profile, Organization +from .models import Detector, Record, Profile, Organization, DetectorCalib from django import forms from django.contrib.auth.models import User @@ -83,13 +83,13 @@ def __init__(self,*args, user=None, **kwargs): description = MarkdownxFormField( label="Description", - help_text="Detailed description of the record; markdown supported.", + help_text="Detailed description of measurements. You can add additional information about measurement conditions, locations etc.. (Markdown supported)", required=False, ) - record_type = forms.ChoiceField( - choices=Record.RECORD_TYPES - ) + # record_type = forms.ChoiceField( + # choices=Record.RECORD_TYPES + # ) belongs = forms.ModelChoiceField( queryset=Organization.objects.exclude(user_organizations__user=user), @@ -101,7 +101,7 @@ def __init__(self,*args, user=None, **kwargs): class Meta: model = Record exclude = ("time_end", "measurement", "log_original_filename", "metadata", "duration", "record_duration", "author", 'data_file', - "metadata_file", "created", "detector") + "metadata_file", "created", "detector", "time_of_interest_start", "time_of_interest_end", 'calib', 'record_type') class DetectorEditForm(forms.ModelForm): @@ -109,3 +109,20 @@ class Meta: model = Detector fields = ["name", "type", 'sn', "manufactured_date", "data", "owner", "access"] + +class DetectorCalibForm(forms.ModelForm): + class Meta: + model = DetectorCalib + #fields = ['name', 'description', 'coef0', 'coef1', 'coef2'] + exclude = ['created', 'author'] + + +DetectorCalibFormSet = forms.inlineformset_factory( + Detector, + Detector.calib.through, + #fields= (calib',), + form=DetectorCalibForm, + can_delete=True, + extra=1 +) + diff --git a/DOSPORTAL/migrations/0030_remove_detectorcalib_date_detectorcalib_author.py b/DOSPORTAL/migrations/0030_remove_detectorcalib_date_detectorcalib_author.py new file mode 100644 index 0000000..f1d6634 --- /dev/null +++ b/DOSPORTAL/migrations/0030_remove_detectorcalib_date_detectorcalib_author.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.11 on 2024-04-07 10:48 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('DOSPORTAL', '0029_rename_time_of_interenst_end_record_time_of_interest_end_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='detectorcalib', + name='date', + ), + migrations.AddField( + model_name='detectorcalib', + name='author', + field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='calibrations', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/DOSPORTAL/models.py b/DOSPORTAL/models.py index 28ce26e..e66cbbc 100644 --- a/DOSPORTAL/models.py +++ b/DOSPORTAL/models.py @@ -267,12 +267,19 @@ class DetectorCalib(UUIDMixin): created = models.DateTimeField(auto_now_add=True) + author = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.DO_NOTHING, + related_name="calibrations", + null=True, + default=None + ) + description = models.TextField( _("Description of calibration status") ) - date = models.DateTimeField( - ) + created = models.DateTimeField(auto_now_add=True) coef0 = models.FloatField( _("Coefficient 0 (offset)"), @@ -295,7 +302,7 @@ class DetectorCalib(UUIDMixin): # ) def __str__(self) -> str: - return f"Calibration '{self.name}' ({self.coef0/1000:.2f}, {self.coef1/1000:.2f}, {self.coef2/1000:.2f} KeV), {self.date}, {self.description}" + return f"Calibration '{self.name}' ({self.coef0/1000:.2f}+x*{self.coef1/1000:.2f} KeV), {self.created}, {self.description}" @@ -319,7 +326,7 @@ class Detector(UUIDMixin): DetectorCalib, blank=True, #name=_("Detector calibration"), - #related_name="detectors", + related_name="detectors", help_text=_("Detector calibration"), #limit_choices_to=, ) @@ -517,6 +524,7 @@ def user_directory_path_data(instance, extension='pk'): log_file = models.FileField( verbose_name=_("File log"), + help_text=_("Upload recorded data file form your detector"), upload_to=user_directory_path, blank=True ) @@ -554,11 +562,12 @@ def user_directory_path_data(instance, extension='pk'): time_tracked = models.BooleanField( verbose_name = _("Is time tracked?"), default = False, - help_text=_("When time is tracked, 'time_start' must be filled out") + help_text=_("Tick this box if the record is dependent on absolute time. When you need align record to real time.") ) time_start = models.DateTimeField( verbose_name = _("Measurement beginning time"), + help_text=("When 'time is tracked', you can set start time of the record beginning. "), null=True, blank=True, default=datetime.datetime(2000, 1, 1, 0, 0, 0) @@ -628,10 +637,15 @@ def user_directory_path_data(instance, extension='pk'): on_delete=models.DO_NOTHING, null=True, related_name="records_owning", - help_text=_("Organization, which owns this record") + help_text=_("Organization, which owns this record. If you are the only owner, please leave this field empty.") ) - data_policy = models.CharField(max_length=2, choices= Organization.DATA_POLICY_CHOICES, default='PU') + data_policy = models.CharField( + max_length=2, + choices= Organization.DATA_POLICY_CHOICES, + default='PU', + help_text=_("Data policy of this record. Field can be overridden depending by setting of the organisation, that owns this record."), + ) author = models.ForeignKey( settings.AUTH_USER_MODEL, diff --git a/DOSPORTAL/signals.py b/DOSPORTAL/signals.py index 2c7af36..d11314f 100644 --- a/DOSPORTAL/signals.py +++ b/DOSPORTAL/signals.py @@ -118,8 +118,12 @@ def save_record(sender, instance, created = None, **kwargs): sn = metadata['log_device_info']['DOS']['hw-sn'] print("Traying to find detector with SN", sn) det = Detector.objects.get(sn=sn) - print(det) + print("Found detector", det) instance.detector = det + + instance.calib = det.calib.last() + + except Exception as e: print(e) diff --git a/DOSPORTAL/templates/base.html b/DOSPORTAL/templates/base.html index 637dfdf..0bfd075 100644 --- a/DOSPORTAL/templates/base.html +++ b/DOSPORTAL/templates/base.html @@ -117,7 +117,7 @@ -
+
{% block content %} {% endblock %}
diff --git a/DOSPORTAL/templates/detectors/detectorCalib_detail.html b/DOSPORTAL/templates/detectors/detectorCalib_detail.html new file mode 100644 index 0000000..6855af6 --- /dev/null +++ b/DOSPORTAL/templates/detectors/detectorCalib_detail.html @@ -0,0 +1,15 @@ + +{% extends "base.html" %} +{% load martortags %} + +{% block content %} + + +Kalibrace + +{{calib}} + + + + +{% endblock %} diff --git a/DOSPORTAL/templates/detectors/detectors_detail.html b/DOSPORTAL/templates/detectors/detectors_detail.html index 6721bca..cba14c1 100644 --- a/DOSPORTAL/templates/detectors/detectors_detail.html +++ b/DOSPORTAL/templates/detectors/detectors_detail.html @@ -3,6 +3,8 @@ {% extends "base.html" %} {% block content %} +{% load martortags %} +{% load crispy_forms_tags %}