[catsoop-dev] cs_sole_course

Madison K Landry almonds at mit.edu
Mon Sep 30 11:37:46 EDT 2024


Hi there,

I've found `cs_sole_course` convenient for some projects and come across 
some bugs.  Logging out or in uses a URL naive of the sole course.  The 
"Log Out" menu button anchors to 
`URL_ROOT/sample_course?loginaction=logout` instead of just 
`URL_ROOT?loginaction=logout`, and likewise for logging in.

I've sourced those issues to `dispatch.py` and `login.py` respectively, 
and I'd appreciate a look.  It's unclear to me if this patch is in the 
best spot; it's also unclear whether the pertinent variables/functions 
should refer to catsoop's base or to the context's current path...

With these changes, logging in, logging out, and creating new users 
seems healthy, whether a sole course is set or not.  I haven't tested 
this with auth types other than `login` or `dummy`.

Also attached is a URL handling patch (for video, audio, and source 
tags) that I mentioned a while ago.  The audio tag handler is most 
useful for my purposes.  (Videos do throttle pages noticeably more than 
audios when served from catsoop, so maybe patching just the audio tags 
passively discourages serving videos from catsoop. :p)

Hope all is well
/ Maddie
-------------- next part --------------
# HG changeset patch
# User Madison Landry <almonds at mit.edu>
# Date 1727707967 14400
#      Mon Sep 30 10:52:47 2024 -0400
# Node ID eff0458dcb92ab6f1cca59b3939c5357253d8e23
# Parent  20001520ae7325882ced99f44052aa4333436e11
Fix URLs for logging in/out and creating users when cs_sole_course is set

diff -r 20001520ae73 -r eff0458dcb92 catsoop/__AUTH__/login/login.py
--- a/catsoop/__AUTH__/login/login.py	Mon Sep 09 12:29:35 2024 -0400
+++ b/catsoop/__AUTH__/login/login.py	Mon Sep 30 10:52:47 2024 -0400
@@ -598,7 +598,13 @@
 
 
 def _get_base_url(context):
-    return "/".join([context["cs_url_root"]] + context["cs_path_info"])
+    sole_course = getattr(context["csm_base_context"], "cs_sole_course", None)
+    is_sole_course = bool(sole_course and
+                          sole_course == context.get("cs_course"))
+    path_info = context["cs_path_info"][int(is_sole_course):]
+    url_root = [context.get("cs_url_root",
+                            context["csm_base_context"].cs_url_root)]
+    return "/".join(url_root + path_info)
 
 
 def generate_forgot_password_form(context):
diff -r 20001520ae73 -r eff0458dcb92 catsoop/dispatch.py
--- a/catsoop/dispatch.py	Mon Sep 09 12:29:35 2024 -0400
+++ b/catsoop/dispatch.py	Mon Sep 30 10:52:47 2024 -0400
@@ -642,6 +642,14 @@
         return environment["REMOTE_ADDR"]
 
 
+def _get_path_url(context):
+    sole_course = getattr(base_context, "cs_sole_course", None)
+    is_sole_course = bool(sole_course and
+                          sole_course == context.get("cs_course"))
+    path_info = context["cs_path_info"][int(is_sole_course):]
+    url_root = [context.get("cs_url_root", base_context.cs_url_root)]
+    return "/".join(url_root + path_info)
+
 def main(environment, return_context=False, form_data=None):
     """
     Generate the page content associated with this request, properly handling
@@ -811,10 +819,7 @@
                     return display_page(context)
                 redir = None
                 if user_info.get("cs_reload", False):
-                    redir = "/".join(
-                        [context.get("cs_url_root", base_context.cs_url_root)]
-                        + context["cs_path_info"]
-                    )
+                    redir = _get_path_url(context)
                     if session_data.get("cs_query_string", ""):
                         redir += "?" + session_data["cs_query_string"]
                 if redir is None:
@@ -835,7 +840,7 @@
             menu = context.get("cs_top_menu", None)
             if isinstance(menu, list) and context.get("cs_auth_required", True):
                 uname = context["cs_username"]
-                base_url = "/".join([context["cs_url_root"]] + context["cs_path_info"])
+                base_url = _get_path_url(context)
                 if str(uname) == "None":
                     menu.append(
                         {"text": "Log In", "link": "%s?loginaction=login" % base_url}
-------------- next part --------------
diff -r eff0458dcb92 catsoop/language.py
--- a/catsoop/language.py	Mon Sep 30 10:52:47 2024 -0400
+++ b/catsoop/language.py	Mon Sep 30 11:05:49 2024 -0400
@@ -1004,7 +1004,9 @@
 
     # custom URL handling in img, a, script, link
 
-    URL_FIX_LIST = [("img", "src"), ("a", "href"), ("script", "src"), ("link", "href")]
+    URL_FIX_LIST = [("img", "src"), ("a", "href"), ("script", "src"),
+                    ("link", "href"), ("source", "src"), ("audio", "src"),
+                    ("video", "src")]
 
     for tag, field in URL_FIX_LIST:
         for i in tree.find_all(tag):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x543E615FD80A35F6.asc
Type: application/pgp-keys
Size: 920 bytes
Desc: OpenPGP public key
URL: <http://mailman.mit.edu/pipermail/catsoop-dev/attachments/20240930/363530eb/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.mit.edu/pipermail/catsoop-dev/attachments/20240930/363530eb/attachment.sig>


More information about the catsoop-dev mailing list