Commit 61e11758 authored by Artur André Almeida de Macedo Oliveira's avatar Artur André Almeida de Macedo Oliveira
Browse files

- SessionId fixes

parent d93644c6
......@@ -3,6 +3,19 @@ from django.db import models
from django.contrib.auth.models import User
import uuid
# Ref.: https://arthurpemberton.com/2015/04/fixing-uuid-is-not-json-serializable
'''
Dealing with no UUID serialization support in json
'''
from json import JSONEncoder
from uuid import UUID
JSONEncoder_olddefault = JSONEncoder.default
def JSONEncoder_newdefault(self, o):
if isinstance(o, UUID): return str(o)
return JSONEncoder_olddefault(self, o)
JSONEncoder.default = JSONEncoder_newdefault
class GeoImage(models.Model):
"""
featureReference - Some unique string used as an Id
......
......@@ -136,43 +136,54 @@
this.uiView.clearSelections();
}
onClickSaveSessionBtn() {
async onClickSaveSessionBtn() {
let currentSessionName = this.uiModel.currentSessionName;
let sessionName = this.uiView.askSessionName(currentSessionName);
this.uiModel.saveSession(sessionName);
await this.uiModel.saveSession(sessionName);
}
onClickNewSessionBtn() {
this.uiModel.newSession();
async onClickNewSessionBtn() {
await this.uiModel.newSession();
}
onClickExecuteQueryBtn() {
async onClickExecuteQueryBtn() {
this.uiView.setLoadingText(this.uiView.jqbtnExecuteQuery);
let unset = (() => this.uiView.unsetLoadingText(this.uiView.jqbtnExecuteQuery));
this.uiModel.executeQuery.bind(this.uiModel)(this.uiView.SelectedMapMiner, this.uiView.SelectedMapFeature).then(unset, error => { alert(error); unset(); });
try
{
//await this.uiModel.executeQuery.bind(this.uiModel)();
await this.uiModel.executeQuery();
}
finally
{
this.uiView.unsetLoadingText(this.uiView.jqbtnExecuteQuery)
}
}
async onClickExecuteImageFilterBtn() {
this.uiView.setLoadingText(this.uiView.jqbtnExecuteImageFilter);
let unset = (() => this.uiView.unsetLoadingText(this.uiView.jqbtnExecuteImageFilter));
let filterId = this.uiModel.SelectedImageFilter;
await this.uiModel.getProcessedImages.bind(this.uiModel)()
//.then(function (filterId) {
unset();
//Set the geoImageManager to display this collection
this.geoImageManager.updateDisplayingLayers(filterId);
// }.bind(this), error => { unset(); alert(error); });
let filterId = this.uiModel.SelectedImageFilter;
try
{
await this.uiModel.getProcessedImages.bind(this.uiModel)()
//Set the geoImageManager to display this collection
this.geoImageManager.updateDisplayingLayers(filterId);
}
finally
{
this.uiView.unsetLoadingText(this.uiView.jqbtnExecuteImageFilter)
}
}
onClickGetImagesBtn() {
async onClickGetImagesBtn() {
this.uiView.setLoadingText(this.uiView.jqbtnCollectImages);
let unset = (() => this.uiView.unsetLoadingText(this.uiView.jqbtnCollectImages));
this.uiModel.getImages(this.uiModel.SelectedImageProvider.idprovider).then(
() => {
unset();
//Set the geoImageManager to display this collection
this.geoImageManager.updateDisplayingLayers();
}, error => { unset(); alert(error); });
try {
await this.uiModel.getImages(this.uiModel.SelectedImageProvider.idprovider);
//Set the geoImageManager to display this collection
this.geoImageManager.updateDisplayingLayers();
}
finally {
this.uiView.unsetLoadingText(this.uiView.jqbtnCollectImages)
}
}
}
\ No newline at end of file
......@@ -845,7 +845,7 @@ class UIModel extends Subject {
/**
* @todo Display success and error messages.
*/
saveSession(sessionName) {
async saveSession(sessionName) {
if (this._loading) return;
let sentData = "";
sessionName = sessionName ? sessionName :
......@@ -862,7 +862,7 @@ class UIModel extends Subject {
uiModelJSON: this.saveToJSON()
});
}
$.ajax('/savesession/',
return await $.ajax('/savesession/',
{
method: 'POST',
processData: false,
......@@ -874,15 +874,16 @@ class UIModel extends Subject {
//data -> sessionId
}.bind(this),
error: function (jqXHR, textStatus, errorThrown) {
defaultAjaxErrorHandler('saveSession', textStatus, errorThrown);
throw new Error(`${errorThrown}: ${jqXHR.responseText}`)
//defaultAjaxErrorHandler('saveSession', textStatus, errorThrown);
},
complete: function (jqXHR, textStatus) { }.bind(this)
});
}
newSession() {
$.ajax('newsession/',
async newSession() {
return await $.ajax('newsession/',
{
method: 'POST',
processData: false,
......@@ -1090,10 +1091,10 @@ class UIModel extends Subject {
async executeQuery() {
let layerId = Layer.createLayerId(this.SelectedMapMiner, this.SelectedMapFeature);
return await executeQuery(layerId);
return await this._executeQuery(layerId);
}
async executeQuery(layerId) {
async _executeQuery(layerId) {
//return new Promise(function (resolve, reject) {
let noSelectedRegions = true;
//let numCalls = 0;
......
......@@ -7,7 +7,7 @@ from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.http import Http404, HttpResponse, JsonResponse, HttpResponseRedirect
from django.utils.translation import gettext
from django.utils.crypto import get_random_string
from uuid import uuid4
from urllib.parse import unquote, urlparse
......@@ -196,10 +196,10 @@ def register(request):
@api_view(['POST'])
def newsession(request):
request.session['sessionId'] = get_random_string()
request.session['sessionId'] = str(uuid4())
if request.session.get('uiModelJSON') is not None: del request.session['uiModelJSON']
print(f"request.session['sessionId']: {request.session['sessionId']}")
return HttpResponse(status=200)
return HttpResponse(request.session.get('sessionId'), status=200)
@api_view(['POST'])
def getlastsessionid(request):
......@@ -224,7 +224,7 @@ def loadsession(request):
session = Session.objects.get(id = sessionId)
if not isUserSession(request.user, session):
if request.session.get('sessionId') is not None:
request.session['sessionId'] = get_random_string()
request.session['sessionId'] = str(uuid4())
return forbiddenUserSessionHttpResponse()
request.session['sessionId'] = sessionId
request.session['uiModelJSON'] = ast.literal_eval(session.uimodelJSON)
......@@ -259,7 +259,7 @@ def savesession(request):
if uiModelJSON is None:
return HttpResponse('No content to be saved!', status = 400)
sessionName = (uiModelJSON.get('sessionName') or request.session.get('sessionName'))
sessionName = (uiModelJSON.get('sessionName') or request.session.get('sessionName') or request.session.get('sessionId'))
print(request.session.get('sessionId'))
print(f'sessionName: {sessionName}')
if request.user.is_authenticated:
......@@ -273,7 +273,7 @@ def savesession(request):
try:
session = Session.objects.get(id = sessionId)
if not isUserSession(request.user, session):
request.session['sessionId'] = get_random_string()
request.session['sessionId'] = str(uuid4())
return forbiddenUserSessionHttpResponse()
if (sessionName is not None) and (len(sessionName) > 0):
session.sessionName = sessionName
......@@ -312,7 +312,7 @@ def renamesession(request):
# Clears session data
@api_view(['POST'])
def clearsession(request):
request.session['sessionId'] = get_random_string()
request.session['sessionId'] = str(uuid4())
del request.session['uiModelJSON']
return HttpResponse(status=204)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment