Merge remote-tracking branch 'origin/master'

# Conflicts:
#	MUOR/requirements.txt
This commit is contained in:
makram89 2022-01-30 16:43:11 +01:00
commit 3f25594788
7 changed files with 80 additions and 21 deletions

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous">
<meta charset="utf-8">
<title>MultiUserOpenRefine}</title>
</head>
<body>
<main>
<div class="container">
<div style="position: page; vertical-align: center">
<div class="row justify-content-center">
<div class="col-8">
<img src="static/images/logo.png" alt="logo"
style="padding-top: 10px; height: auto; width: 50%; display: block; margin-left: auto; margin-right: auto;">
<h1 class="mt-2"
style="text-align: center; padding-bottom: 10px">
MultiUserOpenRefine</h1>
<div style="border-radius: 25px; border: 4px solid #e0e0e0; padding: 20px; box-shadow: rgba(0, 0, 0, 0.24) 0 3px 8px;">
<h3 style="text-align: center;">Your instance is getting
ready. Please wait... </h3>
<div class="d-flex justify-content-center">
<div class="spinner-grow"
style="width: 3rem; height: 3rem;"
role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"
integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"
integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
crossorigin="anonymous"></script>
</body>
</html>

View File

@ -25,7 +25,7 @@ SECRET_KEY = 'django-insecure-t52#vo-k9ty*$@u9bf75hrkd#^o_)gadrz9$7w%xnkb-0#y!bi
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['django']
ALLOWED_HOSTS = ['django', 'localhost']
# Application definition
@ -126,7 +126,7 @@ STATICFILES_DIRS = (
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
LOGIN_REDIRECT_URL = 'loader'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
# Default primary key field type
@ -141,4 +141,14 @@ AVAILABLE_PORTS_RANGE = (6000, 7000)
DOCKER_IMAGE = 'openrefine:latest'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 60 * 60
CELERY_BROKER_URL = 'redis+socket:///var/run/redis/redis-server.sock'
CELERY_TIMEZONE = "Europe/Warsaw"
CELERY_BEAT_SCHEDULE = {
'daily_report': {
'task': 'clear_sessions',
'schedule': 60,
}
}

View File

@ -1,10 +1,11 @@
from django.db.models.signals import post_save
from django.db.models.signals import post_save, pre_delete
from django.dispatch import receiver
from .DockerManager import DockerManager
from .NGINXConfigurator import NGINXConfigurator
from .models import Profile, Session
from django.contrib.auth.signals import user_logged_in, user_logged_out
from django.conf import settings
from django.contrib.sessions.models import Session as DjangoSession
def get_sessions_data():
@ -57,11 +58,11 @@ def profile_start_up(sender, user, request, **kwargs):
NGINXConfigurator.refresh_config(get_sessions_data())
@receiver(user_logged_out)
def profile_logged_out(sender, user, request, **kwargs):
@receiver(pre_delete, sender=DjangoSession)
def close_session(sender, instance, **kwargs):
# Obtaining container_id
try:
session = Session.objects.get(user=user)
session = Session.objects.get(sessionid=instance.session_key)
container_id = session.container_id
# Turn off and delete container
@ -70,6 +71,7 @@ def profile_logged_out(sender, user, request, **kwargs):
# Delete session
session.delete()
print("Closed session!")
except Session.DoesNotExist:
pass
NGINXConfigurator.refresh_config(get_sessions_data())

7
MUOR/MUOR/tasks.py Normal file
View File

@ -0,0 +1,7 @@
from celery import shared_task
from django.core import management
@shared_task(name="clear_sessions")
def clear_sessions():
management.call_command('clearsessions')

View File

@ -25,7 +25,6 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('', include('django.contrib.auth.urls')),
path('signup/', SignUpView.as_view(), name='signup'),
path('loader/', TemplateView.as_view(template_name='loader.html'), name='loader'),
path('welcome/', TemplateView.as_view(template_name='home.html'), name='home'),
path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url('images/favicon.ico'))),
path('', views.home, name='home')

View File

@ -1,4 +1,7 @@
Django
django-crispy-forms
docker
uwsgi
uwsgi
celery
redis
django-redis

View File

@ -1,13 +0,0 @@
<!-- templates/loader.html -->
{% extends 'base.html' %}
{% block title %}Loader{% endblock %}
{% block content %}
<h3 style="text-align: center;">Your instance is getting ready. Please wait... </h3>
<div class="d-flex justify-content-center">
<div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
{% endblock %}