Skip to content

Commit

Permalink
update settings py
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak committed Mar 27, 2024
1 parent 3df59dc commit c5abd47
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 22 deletions.
8 changes: 8 additions & 0 deletions DOSPORTAL/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class DosportalConfig(AppConfig):
name = 'DOSPORTAL'

def ready(self):
import DOSPORTAL.signals
23 changes: 10 additions & 13 deletions DOSPORTAL/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.postgres',
'django.contrib.gis',
'bootstrap5',
#'background_task',
#'django_json_widget',
Expand Down Expand Up @@ -105,7 +106,8 @@
# 'NAME': BASE_DIR / 'db.sqlite3',
# }
"default": {
"ENGINE": "django.db.backends.postgresql",
#"ENGINE": "django.db.backends.postgresql",
"ENGINE": "django.contrib.gis.db.backends.postgis",
"NAME": "dosportal",
"USER": "dosportal_user",
"PASSWORD": "dosportal_password",
Expand Down Expand Up @@ -147,15 +149,6 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


Expand All @@ -168,6 +161,9 @@
STATIC_ROOT = BASE_DIR / 'static'
STATIC_URL = 'static/'

MEDIA_ROOT = BASE_DIR / 'data/media'
MEDIA_URL = 'media/'

REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
Expand Down Expand Up @@ -211,9 +207,10 @@
'save_limit': 250,
'queue_limit': 500,
'cpu_affinity': 1,
'label': 'Django Q',
#'redis': {
# 'host': '127.0.0.1',
'label': 'Worker',
'redis': {
'host': 'redis',
# 'port': 6379,
# 'db': 0, }
}
}
37 changes: 37 additions & 0 deletions DOSPORTAL/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver
from .models import Profile, record


@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)


@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
instance.profile.save()



@receiver(post_save, sender=record)
def save_record(sender, instance, **kwargs):
print("AFTER SAVE.... ")
print(sender)
print(instance)
print(kwargs)

filepath = 'data/media/'+instance.log_file
print(filepath)

metadata = instance.metadata

if 'device_info' not in metadata:
metadata['device_info'] = {}

with open(filepath, 'r') as file:
for line in file:
print(line)

24 changes: 24 additions & 0 deletions DOSPORTAL/templates/detectors/detector_edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


{% extends "base.html" %}
{% load crispy_forms_tags %}

{% block content %}

<div class="d-flex justify-content-between"><div class="h1">Edit detector</div>

<div class="container">
<div class="row">
<div class="col-md-12">
<form action="" method="post">
{% csrf_token %}
{{ detectorEditForm | crispy }}
<button class="btn btn-success is-success is-fullwidth is-medium mt-5" type="submit"> Submit </button>
</form>
</div>
</div>
</div>
</div>


{% endblock %}
46 changes: 46 additions & 0 deletions DOSPORTAL/templates/organizations/organization_profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

{% extends "base.html" %}
{% load martortags %}

{% block content %}

Organizace <a href="{%url 'organization-detail' slug=organization.slug %}"><b> {{ organization.name }} {% if user.is_authenticated %} <a href="{{organization.get_admin_url}}"><i class="bi bi-pencil"></i></a>{%endif%}</b>

<br>

<div class="d-flex flex-wrap align-items-center text-decoration-none">
{% for a in organization.user_organizations.all %}
<a href="{%url 'user_profile' username=a.user.username %}" class="text-decoration-none">
<div class="d-flex align-items-center m-2">
<img src="{{a.user.profile.image.url}}" class="rounded-circle" alt="{{a.user.full_name }}" style="width: 40px; height: 40px; object-fit: cover;">
<small class="ml-2 py-2 pr-3">{{a.user}}</small>
</div>
</a>
{% endfor %}
</div>



</div>

<hr>

<h2>Detectors</h2>
{% for detector in organization.detectors.all %}


<a href="{% url 'detector-view' pk=detector.pk %}"> {{detector}}</a> <br>
{% endfor %}
<hr>
<h2>Maintainer of detectors:</h2>

TODO:

<h2>Author of measurements</h2>

TODO:




{% endblock %}
2 changes: 1 addition & 1 deletion DOSPORTAL/templates/records/record_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li><strong>Advanced metadata:</strong></li>
<div class="callout">{{record.metadata }}</div>
<li><strong>Description:</strong> {{record}}
<li><strong>File size:</strong> {{record.log_file.size}}
{# <li><strong>File size:</strong> {{record.log_file.size}} #}

</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion DOSPORTAL/templates/records/record_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% block content %}

<div class="column is-one-third">
<form method="post">
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form | crispy }}
<button class="btn btn-primary is-success is-fullwidth is-medium mt-5" type="submit"> Submit </button>
Expand Down
11 changes: 6 additions & 5 deletions DOSPORTAL/templates/records/records_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{% block content %}
<div class="d-flex justify-content-between"><div class="h1">Recorded data</div>

{{ records_list|length}}

{% if user.is_authenticated %}
<a href="/record/new" class="btn btn-outline-success" role="button" style="height: max-content;"><i class="bi bi-plus-square me-2"></i> New record </a>
{% endif %}
Expand All @@ -16,18 +18,17 @@
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Type</th>
<th scope="col">Autor</th>
<th scope="col">Popis</th>
<th scope="col">Author</th>
</tr>
</thead>
<tbody>
{% for record in record_list.reverse %}
<tr>
<th scope="row">{{ forloop.counter }}</th>
<td><a href="/record/{{record.id}}/" class="link" style="text-decoration: none;">{{ record.name }}</a></td>
<th scope="row"><a href="{%url 'record-view' pk=record.id %}">{{ forloop.counter }}</a></th>
<td><a href="{%url 'record-view' pk=record.id %}" class="link" style="text-decoration: none;">{{ record | truncatechars:50 }}</a></td>
<td>{{ record.record_type }}</td>
<td>{{record.author}}</td>
<td> <div style="max-height: 50pt;overflow-y: auto;">{{record.description | safe_markdown }}</div></td>
<td> <div style="max-height: 50pt;overflow-y: auto;">{{ record }}</div></td>
</tr>

{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions DOSPORTAL/templates/user/user_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block content %}

<p>Username: {{ user.username }} {% if user.is_authenticated %} <a href="{{user.get_admin_url}}"><i class="bi bi-pencil"></i></a>{%endif%}</p>
<p>Username: {{ user.username }} {% if user.is_authenticated %} <a href="{{ user.get_admin_url }}"><i class="bi bi-pencil"></i></a>{%endif%}</p>
<p>Email: {{ user.email }}</p>
<p>First Name: {{ user.first_name }}</p>
<p>Last Name: {{ user.last_name }}</p>
Expand All @@ -15,7 +15,7 @@ <h3> Organisations: </h3>

{% for a in user.organization_users.all %}

<a href="{{a.get_absolute_url}}">{{a}}</a><br>
<a href="{{a.organization.get_absolute_url}}">{{a}}</a><br>
{% endfor %}


Expand Down

0 comments on commit c5abd47

Please sign in to comment.