summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuchita Lad2025-03-03 17:20:56 +0530
committerSuchita Lad2025-03-03 17:20:56 +0530
commit6aebbb5673823cf1c0b3b1584df40c87ae6d4069 (patch)
tree8cdaf14e698036749042783ef24051d2fde8d5c2
parent12b69bccbc2f62b209947cacbb615c0dcea44094 (diff)
downloadCommon-Interface-Project-6aebbb5673823cf1c0b3b1584df40c87ae6d4069.tar.gz
Common-Interface-Project-6aebbb5673823cf1c0b3b1584df40c87ae6d4069.tar.bz2
Common-Interface-Project-6aebbb5673823cf1c0b3b1584df40c87ae6d4069.zip
Store session details in table
-rw-r--r--blocks/eda-frontend/src/App.js2
-rw-r--r--blocks/simulationAPI/models.py5
-rw-r--r--blocks/simulationAPI/views.py13
3 files changed, 14 insertions, 6 deletions
diff --git a/blocks/eda-frontend/src/App.js b/blocks/eda-frontend/src/App.js
index 67442800..dd4bbe3a 100644
--- a/blocks/eda-frontend/src/App.js
+++ b/blocks/eda-frontend/src/App.js
@@ -84,7 +84,7 @@ const App = () => {
if (!sessionId) {
// Generate a new session ID
- api.get('simulation/get_session')
+ api.get('simulation/get_session?app_name=' + process.env.REACT_APP_NAME)
.then(res => {
sessionId = res.data.session_id
localStorage.setItem('session_id', sessionId)
diff --git a/blocks/simulationAPI/models.py b/blocks/simulationAPI/models.py
index ac44d65d..2de65687 100644
--- a/blocks/simulationAPI/models.py
+++ b/blocks/simulationAPI/models.py
@@ -1,14 +1,17 @@
from django.db import models
from django.core.files.storage import FileSystemStorage
from django.conf import settings
+from django.utils import timezone
+from datetime import timedelta
import uuid
# session
class Session(models.Model):
- session_id = models.CharField(primary_key=True, max_length=100, null=False, editable=False)
+ session_id = models.CharField(primary_key=True, max_length=40, null=False, editable=False)
app_name = models.CharField(max_length=100, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
+ expire_at = models.DateTimeField(default=timezone.now() + timedelta(days=1))
def __str__(self):
return self.session_id
diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py
index 3c31848e..413a8d3f 100644
--- a/blocks/simulationAPI/views.py
+++ b/blocks/simulationAPI/views.py
@@ -13,7 +13,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from blocks.celery_tasks import app
-from simulationAPI.models import Task
+from simulationAPI.models import Task, Session
from simulationAPI.negotiation import IgnoreClientContentNegotiation
from simulationAPI.serializers import TaskSerializer
from simulationAPI.tasks import process_task
@@ -344,6 +344,11 @@ def get_session(request):
if not request.session.session_key:
request.session.save() # Create a new session if not already exists
- return JsonResponse({
- 'session_id': request.session.session_key
- })
+ session_id = request.session.session_key
+
+ # Save or update session in the custom table
+ session, created = Session.objects.update_or_create(
+ session_id=session_id
+ )
+
+ return JsonResponse({'session_id': session_id, 'stored': not created})