1616from werkzeug .local import LocalProxy
1717
1818from naucse import models
19- from naucse .freezer import temporary_url_for_logger
19+ from naucse .freezer import temporary_url_for_logger , record_url
2020from naucse .models import allowed_elements_parser
2121from naucse .templates import setup_jinja_env , vars_functions
2222from naucse .urlconverters import register_url_converters
2626from naucse .utils .models import arca
2727from naucse .utils .views import get_recent_runs , list_months
2828from naucse .utils .views import does_course_return_info
29- from naucse .utils .views import absolute_urls_to_freeze , raise_errors_from_forks
29+ from naucse .utils .views import raise_errors_from_forks
3030from naucse .utils .views import page_content_cache_key , get_edit_info
3131from naucse .validation import DisallowedStyle , DisallowedElement , InvalidHTML
3232
@@ -276,6 +276,13 @@ def lesson_static_generator():
276276 yield from lesson_static_generator_dir (lesson .slug , static , static )
277277
278278
279+ def record_content_urls (data_from_fork , prefix ):
280+ # Freeze URLs generated by the code in fork, but only if
281+ # they start with the given prefix
282+ for url in data_from_fork .get ("urls" , ()):
283+ if url .startswith (prefix ):
284+ record_url (url )
285+
279286def course_content (course ):
280287 def lesson_url (lesson , * args , ** kwargs ):
281288 if kwargs .get ("page" ) == "index" :
@@ -319,6 +326,7 @@ def course(course):
319326 root_slug = model .meta .slug ,
320327 travis_build_id = os .environ .get ("TRAVIS_BUILD_ID" ),
321328 )
329+ record_content_urls (data_from_fork , f"/{ course .slug } /" )
322330 kwargs = {
323331 "course_content" : content ,
324332 "edit_info" : edit_info ,
@@ -464,7 +472,6 @@ def content_creator():
464472 subpage_url = subpage_url ,
465473 vars = variables
466474 )
467-
468475 absolute_urls = [url_for (logged [0 ], ** logged [1 ]) for logged in logger .logged_calls ]
469476
470477 relative_urls = [get_relative_url (request .path , x ) for x in absolute_urls ]
@@ -485,11 +492,10 @@ def content_creator():
485492 content_key = page_content_cache_key (Repo ("." ), lesson .slug , page .slug , solution , variables )
486493 cached = arca .region .get_or_create (content_key , content_creator )
487494
488- # The urls are added twice to ``absolute_urls_to_freeze``
489- # when the content is created.
495+ # The urls are recorded twice when the content is created.
490496 # But it doesn't matter, duplicate URLs are skipped.
491- absolute_urls = [ urljoin ( request . path , x ) for x in cached ["urls" ]]
492- absolute_urls_to_freeze . extend ( absolute_urls )
497+ for x in cached ["urls" ]:
498+ record_url ( urljoin ( request . path , x ) )
493499
494500 return cached
495501
@@ -530,20 +536,23 @@ def course_page(course, lesson, page, solution=None):
530536 if content_offer :
531537 fork_kwargs ["content_key" ] = content_key
532538
533- data_from_fork = course .render_page (lesson_slug , page , solution , ** fork_kwargs )
539+ data_from_fork = course .render_page (
540+ lesson_slug , page , solution ,
541+ ** fork_kwargs )
542+ record_content_urls (data_from_fork , f"/{ course .slug } /" )
534543
535544 content = data_from_fork ["content" ]
536545
537546 if content is None :
538547 # the offer was accepted
539548 content = content_offer ["content" ]
540- absolute_urls_to_freeze . extend ([ urljoin ( request . path , x )
541- for x in content_offer [ "urls" ]] )
549+ for x in content_offer [ "urls" ]:
550+ record_url ( urljoin ( request . path , x ) )
542551 else :
543552 # the offer was rejected or the the fragment was not in cache
544553 arca .region .set (content_key , {"content" : content , "urls" : data_from_fork ["content_urls" ]})
545- absolute_urls_to_freeze . extend ([ urljoin ( request . path , x )
546- for x in data_from_fork [ "content_urls" ]] )
554+ for x in data_from_fork [ "content_urls" ]:
555+ record_url ( urljoin ( request . path , x ) )
547556
548557 # compatibility
549558 page = process_page_data (data_from_fork .get ("page" ))
@@ -573,8 +582,17 @@ def course_page(course, lesson, page, solution=None):
573582 title = '{}: {}' .format (course .title , page .title )
574583
575584 try :
576- prev_link , session_link , next_link = course .get_footer_links (lesson .slug , page_slug ,
577- request_url = request .path )
585+ footer_links = course .get_footer_links (
586+ lesson .slug ,
587+ page_slug ,
588+ request_url = request .path ,
589+ )
590+ for link in footer_links :
591+ _prefix = f"/{ course .slug } /"
592+ if link and link ["url" ].startswith (_prefix ):
593+ record_url (link ["url" ])
594+ prev_link , session_link , next_link = footer_links
595+
578596 except POSSIBLE_FORK_EXCEPTIONS as e :
579597 if raise_errors_from_forks ():
580598 raise
@@ -726,7 +744,9 @@ def session_coverpage(course, session, coverpage):
726744 naucse .utils .views .forks_raise_if_disabled ()
727745
728746 try :
729- data_from_fork = course .render_session_coverpage (session , coverpage , request_url = request .path )
747+ data_from_fork = course .render_session_coverpage (
748+ session , coverpage , request_url = request .path )
749+ record_content_urls (data_from_fork , f"/{ course .slug } /" )
730750
731751 content = data_from_fork .get ("content" )
732752 if content is None :
@@ -790,6 +810,7 @@ def course_calendar(course):
790810
791811 try :
792812 data_from_fork = course .render_calendar (request_url = request .path )
813+ record_content_urls (data_from_fork , f"/{ course .slug } /" )
793814
794815 course = process_course_data (data_from_fork .get ("course" ), slug = course .slug )
795816 edit_info = links .process_edit_info (data_from_fork .get ("edit_info" ))
@@ -865,7 +886,9 @@ def course_calendar_ics(course):
865886 naucse .utils .views .forks_raise_if_disabled ()
866887
867888 try :
868- data_from_fork = course .render_calendar_ics (request_url = request .path )
889+ data_from_fork = course .render_calendar_ics (
890+ request_url = request .path )
891+ record_content_urls (data_from_fork , f"/{ course .slug } /" )
869892
870893 calendar = data_from_fork .get ("calendar" )
871894
0 commit comments