WIP: fix http redirects, fix some JS urls

This commit is contained in:
Emmanuel Viennet 2021-06-21 14:40:58 +02:00
parent ede5aa680d
commit 64615036ec
9 changed files with 99 additions and 79 deletions

View File

@ -7,6 +7,8 @@ import inspect
import types
import logging
import werkzeug
from werkzeug.exceptions import BadRequest
import flask
from flask import g
from flask import abort, current_app
@ -14,7 +16,6 @@ from flask import request
from flask_login import current_user
from flask_login import login_required
from flask import current_app
from werkzeug.exceptions import BadRequest
from app.auth.models import Permission
@ -80,7 +81,8 @@ class ZResponse(object):
self.headers = {}
def redirect(self, url):
return flask.redirect(url) # http 302
current_app.logger.debug("ZResponse redirect to:" + str(url))
return flask.redirect(url.decode("utf-8")) # http 302 # #sco8 unicode
def setHeader(self, header, value):
self.headers[header.lower()] = value
@ -188,6 +190,8 @@ def scodoc7func(context):
if not top_level:
return value
else:
if isinstance(value, werkzeug.wrappers.response.Response):
return value # redirected
# Build response, adding collected http headers:
headers = []
kw = {"response": value, "status": 200}

View File

@ -231,6 +231,8 @@ def sco_header(
<script language="javascript" type="text/javascript" src="/ScoDoc/static/libjs/bubble.js"></script>
<script type="text/javascript">
window.onload=function(){enableTooltips("gtrcontent")};
var SCO_URL="%(ScoURL)s";
</script>"""
% params
)

View File

@ -248,6 +248,7 @@ def do_evaluation_create(
evaluation_type=None,
numero=None,
REQUEST=None,
**kw # ceci pour absorber les arguments excedentaires de tf #sco8
):
"""Create an evaluation"""
if not sco_permissions_check.can_edit_evaluation(

View File

@ -53,15 +53,17 @@ from PIL import Image as PILImage
from cStringIO import StringIO
import glob
from flask import request
from config import Config
import app.scodoc.sco_utils as scu
import app.scodoc.notesdb as ndb
from app.scodoc.notes_log import log
from app.scodoc.scolog import logdb
from app.scodoc import sco_etud
from app.scodoc import sco_portal_apogee
from app.scodoc import sco_preferences
from app.scodoc import sco_etud
from app.scodoc.notes_log import log
from app.scodoc.scolog import logdb
import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu
# Full paths on server's filesystem. Something like "/opt/scodoc/var/scodoc/photos"
PHOTO_DIR = os.path.join(Config.INSTANCE_HOME, "var", "scodoc", "photos")
@ -89,7 +91,10 @@ def etud_photo_url(context, etud, size="small", fast=False, REQUEST=None):
"""url to the image of the student, in "small" size or "orig" size.
If ScoDoc doesn't have an image and a portal is configured, link to it.
"""
photo_url = "get_photo_image?etudid=%s&size=%s" % (etud["etudid"], size)
photo_url = scu.ScoURL() + "/get_photo_image?etudid=%s&size=%s" % (
etud["etudid"],
size,
)
if fast:
return photo_url
path = photo_pathname(context, etud, size=size)
@ -98,7 +103,7 @@ def etud_photo_url(context, etud, size="small", fast=False, REQUEST=None):
ext_url = photo_portal_url(context, etud)
if not ext_url:
# fallback: Photo "unknown"
photo_url = UNKNOWN_IMAGE_URL
photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL
else:
# essaie de copier la photo du portail
new_path, _ = copy_portal_photo_to_fs(context, etud, REQUEST=REQUEST)
@ -141,7 +146,7 @@ def _http_jpeg_file(context, filename, REQUEST=None):
RESPONSE.setHeader("Last-Modified", last_modified_str)
RESPONSE.setHeader("Cache-Control", "max-age=3600")
RESPONSE.setHeader("Content-Length", str(file_size))
header = REQUEST.get_header("If-Modified-Since", None)
header = request.headers.get("If-Modified-Since")
if header is not None:
header = header.split(";")[0]
# Some proxies seem to send invalid date strings for this

View File

@ -32,7 +32,7 @@ $().ready(function(){
$(elems[i]).qtip({
content: {
ajax: {
url: "etud_info_html?etudid=" + get_etudid_from_elem(elems[i]) + qs,
url: SCO_URL + "/etud_info_html?etudid=" + get_etudid_from_elem(elems[i]) + qs,
type: "GET"
//success: function(data, status) {
// this.set('content.text', data);

View File

@ -5,7 +5,7 @@ $().ready(function(){
for (var i = 0; i < spans.length; i++) {
var sp = spans[i];
var etudid = sp.id;
$(sp).load('etud_photo_html?etudid='+etudid);
$(sp).load(SCO_URL + '/etud_photo_html?etudid=' + etudid);
}
});
@ -160,7 +160,7 @@ $().ready(function(){
{
content: {
ajax: {
url: "etud_info_html?with_photo=0&etudid=" + get_etudid_from_elem(elems[i])
url: SCO_URL + "/etud_info_html?with_photo=0&etudid=" + get_etudid_from_elem(elems[i])
},
text: "Loading..."
},

View File

@ -77,3 +77,11 @@ def sco_get_version(REQUEST):
@permission_required(Permission.ScoView)
def sco_test_view(REQUEST=None):
return """Vous avez vu sco_test_view !"""
import flask
@bp.route("/essrep")
def essrep():
return flask.Response(status=200, response="Bonjour")

View File

@ -1482,7 +1482,7 @@ sco_publish(
)
@bp.route("/evaluation_edit")
@bp.route("/evaluation_edit", methods=["GET", "POST"])
@permission_required(Permission.ScoEnsView)
@scodoc7func(context)
def evaluation_edit(context, evaluation_id, REQUEST):
@ -1492,7 +1492,7 @@ def evaluation_edit(context, evaluation_id, REQUEST):
)
@bp.route("/evaluation_create")
@bp.route("/evaluation_create", methods=["GET", "POST"])
@permission_required(Permission.ScoEnsView)
@scodoc7func(context)
def evaluation_create(context, moduleimpl_id, REQUEST):

View File

@ -184,7 +184,7 @@ def about(context, REQUEST):
# --------------------------------------------------------------------
@bp.route("/edit_preferences")
@bp.route("/edit_preferences", methods=["GET", "POST"])
@permission_required(Permission.ScoChangePreferences)
@scodoc7func(context)
def edit_preferences(context, REQUEST):