Skip to content

Commit

Permalink
updates in view, django-tables2
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Apr 4, 2024
1 parent 2142403 commit db597ec
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 312 deletions.
12 changes: 12 additions & 0 deletions DOSPORTAL/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
from django.contrib.auth.forms import UserCreationForm


class LoginForm(forms.Form):
username = forms.CharField(
widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': 'Username', 'autofocus': False }),
label="Username",
help_text="Enter your username."
)
password = forms.CharField(
label="Password",
widget=forms.PasswordInput(attrs={'class': 'form-control', 'placeholder': 'Password', 'autofocus': False }),
help_text="Enter your password."
)

class UserRegisterForm(UserCreationForm):
email = forms.EmailField()

Expand Down
26 changes: 26 additions & 0 deletions DOSPORTAL/migrations/0008_record_created_alter_record_data_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.11 on 2024-04-04 12:59

import DOSPORTAL.models
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('DOSPORTAL', '0007_record_data_file'),
]

operations = [
migrations.AddField(
model_name='record',
name='created',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now, verbose_name='Time of creation'),
preserve_default=False,
),
migrations.AlterField(
model_name='record',
name='data_file',
field=models.FileField(blank=True, help_text='Processed spectral file', null=True, upload_to=DOSPORTAL.models.Record.user_directory_path_data, verbose_name='Log file'),
),
]
8 changes: 7 additions & 1 deletion DOSPORTAL/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,13 @@ def user_directory_path_data(instance, filename):
null=True,
)

created = models.DateTimeField(
verbose_name = _("Time of creation"),
null=False,
editable=False,
auto_now_add=True
)

record_duration = models.DurationField(
verbose_name = _("Record duration"),
help_text=_("Duration of record"),
Expand Down Expand Up @@ -552,7 +559,6 @@ def description(self) -> str:




class Trajectory(UUIDMixin):
name = models.CharField(
max_length = 80
Expand Down
9 changes: 8 additions & 1 deletion DOSPORTAL/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'import_export',
'django_select2',
'martor',
#'django_tables2',
'django_tables2',

'DOSPORTAL',
'django_q',
Expand Down Expand Up @@ -176,7 +176,14 @@



DJANGO_TABLES2_TEMPLATE = "django_tables2/bootstrap5-responsive.html"

DJANGO_TABLES2_TABLE_ATTRS = {
'class': 'table table-hover',
'thead': {
'class': 'table-light',
},
}

MARTOR_THEME = 'bootstrap'
MARTOR_ENABLE_CONFIGS = {
Expand Down
23 changes: 6 additions & 17 deletions DOSPORTAL/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .models import Profile, Record, SpectrumData
import json
import pandas as pd
import datetime


@receiver(post_save, sender=User)
Expand All @@ -20,15 +21,8 @@ def save_profile(sender, instance, **kwargs):

@receiver(post_save, sender=Record)
def save_record(sender, instance, created = None, **kwargs):
print("AFTER SAVE.... ")
print(sender, created)
print(instance)
print(kwargs)
print(".................")
print(instance.log_file.path, type(instance.log_file))

if created:

filepath = instance.log_file.path
print(filepath)

Expand All @@ -37,10 +31,6 @@ def save_record(sender, instance, created = None, **kwargs):
if type(metadata) is not dict:
metadata = {}

print("MEDATADA")
print(type(metadata))
print(metadata)


metadata['log_device_info'] = {}
metadata['log_runs_count'] = 0
Expand Down Expand Up @@ -95,24 +85,23 @@ def save_record(sender, instance, created = None, **kwargs):
}

df = pd.read_csv(instance.log_file.path, sep = ',', header = None, names=range(max_size))
print(df)

df = df [df[0] == '$HIST']
df = df.drop(columns=[0, 1, 3, 4, 5, 6, 7])
df = df.drop(columns=[0, 1, 3, 4, 5, 6, 7, 8])

new_columns = ['time'] + list(range(df.shape[1] - 1))
df.columns = new_columns

duration = df['time'].max()
instance.record_duration = datetime.timedelta(seconds=float(duration))

new_name = instance.user_directory_path_data('pk')
print("BUDU TO UKLADAT DO ",'data/media/'+new_name)
df.to_pickle('data/media/'+new_name)

instance.data_file.name = new_name

print(instance.data_file)


print("Po ")
print(df)

instance.metadata = json.dumps(metadata)
instance.save()
Binary file added DOSPORTAL/static/img/login_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit db597ec

Please sign in to comment.