def _add_links(df, slug, conc=True): """ add a markdown href to the match try/except is basically for runserver/development stuff """ try: if not management_handling(): show_row = "match" if conc else "file" df[show_row] = df.apply(_apply_href, axis=1, slug=slug, conc=conc) except ObjectDoesNotExist: print("Unable to add links, hopefully because this is management command.") return df return df
def ready(self): # Singleton utility # We load them here to avoid multiple instantiation across other # modules, that would take too much time. if not management_handling(): global corpora, initial_tables, initial_concs, layouts print("Loading corpora in AppConfig") corpora, initial_tables, initial_concs = _get_or_load_corpora( force=False) layouts = dict() for slug in list(corpora): print(f"Loading layout: {slug}") layouts[slug] = load_layout(slug, set_and_register=False, return_layout=True) print("AppConfig loaded") else: print("Not loading data because this is a management command.")
from django.urls import path from buzzword.utils import management_handling app_name = "read" if not management_handling(): from .views import epub_view urlpatterns = [ path("", epub_view, name="epub_view"), path("<str:slug>/", epub_view, name="epub_view"), ] else: urlpatterns = []
def _register_urls(): from . import views # we need to make a regex matching each corpus slug # so that signout and other urls are still matched # try-except is to catch migrate (etc) calls slugs = [i.slug for i in Corpus.objects.all()] slugs = "(" + "|".join(set(slugs)) + ")" paths = f"^(?P<slug>{slugs})/" urlpatterns = [ re_path(paths, views.start_specific, name="start_specific"), path("user/<str:username>/", views.user_profile, name="user_profile") ] # in specific mode, disallow the homepage, redirecting always to the specific if not settings.BUZZWORD_SPECIFIC_CORPUS: urlpatterns += [path("", views.start, name="start")] else: pages = {"", "about/", "howto/"} urlpatterns += [path(x, views.start_specific) for x in pages] return urlpatterns if management_handling(): urlpatterns = [] else: urlpatterns = _register_urls()