mirror of
https://github.com/boostorg/website-v2.git
synced 2026-01-19 04:42:17 +00:00
Add exception logic to load the Detail docs links
- Add a button to the LibraryVersion admin to reload the docs links - Add some minimal docs on the admin features
This commit is contained in:
5
docs/admin.md
Normal file
5
docs/admin.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Admin Features
|
||||||
|
|
||||||
|
## LibraryVersions
|
||||||
|
|
||||||
|
- Button **Refresh Documentation Links** will re-run the task that retrieves the links to external documentation for every version of every Boost library.
|
||||||
@@ -3,7 +3,10 @@ from django.http import HttpResponseRedirect
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .models import Category, Issue, Library, LibraryVersion, PullRequest
|
from .models import Category, Issue, Library, LibraryVersion, PullRequest
|
||||||
from .tasks import update_libraries
|
from .tasks import (
|
||||||
|
update_libraries,
|
||||||
|
update_library_version_documentation_urls_all_versions,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Category)
|
@admin.register(Category)
|
||||||
@@ -46,6 +49,25 @@ class LibraryVersionAdmin(admin.ModelAdmin):
|
|||||||
list_filter = ["library", "version"]
|
list_filter = ["library", "version"]
|
||||||
ordering = ["library__name", "-version__name"]
|
ordering = ["library__name", "-version__name"]
|
||||||
search_fields = ["library__name", "version__name"]
|
search_fields = ["library__name", "version__name"]
|
||||||
|
change_list_template = "admin/libraryversion_change_list.html"
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
my_urls = [
|
||||||
|
path("update_docs_urls/", self.update_docs_urls, name="update_docs_urls"),
|
||||||
|
]
|
||||||
|
return my_urls + urls
|
||||||
|
|
||||||
|
def update_docs_urls(self, request):
|
||||||
|
"""Run the task to refresh the documentation URLS from S3"""
|
||||||
|
update_library_version_documentation_urls_all_versions.delay()
|
||||||
|
self.message_user(
|
||||||
|
request,
|
||||||
|
"""
|
||||||
|
Documentation links are being refreshed.
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect("../")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Issue)
|
@admin.register(Issue)
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
import structlog
|
import structlog
|
||||||
|
|
||||||
from config.celery import app
|
from config.celery import app
|
||||||
|
from django.db.models import Q
|
||||||
from core.boostrenderer import get_content_from_s3
|
from core.boostrenderer import get_content_from_s3
|
||||||
from core.htmlhelper import get_library_documentation_urls
|
from core.htmlhelper import get_library_documentation_urls
|
||||||
from libraries.github import LibraryUpdater
|
from libraries.github import LibraryUpdater
|
||||||
from libraries.models import LibraryVersion
|
from libraries.models import LibraryVersion
|
||||||
from libraries.utils import get_first_last_day_last_month
|
from libraries.utils import get_first_last_day_last_month
|
||||||
from versions.models import Version
|
from versions.models import Version
|
||||||
|
from .utils import generate_library_docs_url
|
||||||
|
|
||||||
logger = structlog.getLogger(__name__)
|
logger = structlog.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
LIBRARY_DOCS_EXCEPTIONS = {"detail": generate_library_docs_url}
|
||||||
|
|
||||||
|
|
||||||
|
@app.task
|
||||||
|
def update_library_version_documentation_urls_all_versions():
|
||||||
|
"""Run the task to update all documentation URLs for all versions"""
|
||||||
|
for version in Version.objects.all():
|
||||||
|
get_and_store_library_version_documentation_urls_for_version.delay(version.pk)
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def get_and_store_library_version_documentation_urls_for_version(version_pk):
|
def get_and_store_library_version_documentation_urls_for_version(version_pk):
|
||||||
"""
|
"""
|
||||||
@@ -64,6 +76,20 @@ def get_and_store_library_version_documentation_urls_for_version(version_pk):
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# See if we can load missing docs URLS another way
|
||||||
|
library_versions = LibraryVersion.objects.filter(version=version).filter(
|
||||||
|
Q(documentation_url="") | Q(documentation_url__isnull=True)
|
||||||
|
)
|
||||||
|
for library_version in library_versions:
|
||||||
|
exception_url_generator = LIBRARY_DOCS_EXCEPTIONS.get(
|
||||||
|
library_version.library.name.lower()
|
||||||
|
)
|
||||||
|
if exception_url_generator:
|
||||||
|
library_version.documentation_url = exception_url_generator(
|
||||||
|
version.boost_url_slug, library_version.library.slug.lower()
|
||||||
|
)
|
||||||
|
library_version.save()
|
||||||
|
|
||||||
|
|
||||||
@app.task
|
@app.task
|
||||||
def update_libraries(update_all=False):
|
def update_libraries(update_all=False):
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import os
|
|||||||
from libraries.utils import (
|
from libraries.utils import (
|
||||||
decode_content,
|
decode_content,
|
||||||
generate_fake_email,
|
generate_fake_email,
|
||||||
|
generate_library_docs_url,
|
||||||
get_first_last_day_last_month,
|
get_first_last_day_last_month,
|
||||||
parse_date,
|
parse_date,
|
||||||
write_content_to_tempfile,
|
write_content_to_tempfile,
|
||||||
@@ -28,6 +29,11 @@ def test_generate_fake_email():
|
|||||||
assert "@example.com" in result
|
assert "@example.com" in result
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_library_docs_url():
|
||||||
|
expected = "/doc/libs/boost_1_84_0/libs/detail/doc/html/index.html"
|
||||||
|
assert generate_library_docs_url("boost_1_84_0", "detail") == expected
|
||||||
|
|
||||||
|
|
||||||
def test_get_first_last_day_last_month():
|
def test_get_first_last_day_last_month():
|
||||||
first_day, last_day = get_first_last_day_last_month()
|
first_day, last_day = get_first_last_day_last_month()
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ def generate_fake_email(val: str) -> str:
|
|||||||
return f"{local_email}@example.com"
|
return f"{local_email}@example.com"
|
||||||
|
|
||||||
|
|
||||||
|
def generate_library_docs_url(boost_url_slug, library_slug):
|
||||||
|
"""Generate a documentation url with a specific format"""
|
||||||
|
return f"/doc/libs/{boost_url_slug}/libs/{library_slug}/doc/html/index.html"
|
||||||
|
|
||||||
|
|
||||||
def get_first_last_day_last_month():
|
def get_first_last_day_last_month():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
first_day_this_month = now.replace(day=1)
|
first_day_this_month = now.replace(day=1)
|
||||||
|
|||||||
11
templates/admin/libraryversion_change_list.html
Normal file
11
templates/admin/libraryversion_change_list.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
{% load i18n admin_urls %}
|
||||||
|
|
||||||
|
{% block object-tools %}
|
||||||
|
<ul class="object-tools">
|
||||||
|
{% block object-tools-items %}
|
||||||
|
{{ block.super }}
|
||||||
|
<li><a href="{% url 'admin:update_docs_urls' %}" class="addlink">{% trans "Refresh Documentation Links" %}</a></li>
|
||||||
|
{% endblock %}
|
||||||
|
</ul>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user