Esempio n. 1
0

def sitemap_view(request):
    return views.sitemap(request, sitemaps)


urlpatterns = [
    # path("sermons", sermon_views.sermons, name="sermons"),
    # path("sermon/<uuid:id>", sermon_views.sermon, name="sermon"),
    # path("djrichtextfield/", include("djrichtextfield.urls")),
    # path("jet/", include("jet.urls", "jet")),
    path("admin/", admin.site.urls),
    # path("admin/", include("material.admin.urls")),
    distill_path(
        "morning_prayer/<int:year>-<int:month>-<int:day>/",
        office_views.morning_prayer,
        name="morning_prayer",
        distill_func=get_days,
    ),
    distill_path(
        "midday_prayer/<int:year>-<int:month>-<int:day>/",
        office_views.midday_prayer,
        name="midday_prayer",
        distill_func=get_days,
    ),
    distill_path(
        "evening_prayer/<int:year>-<int:month>-<int:day>/",
        office_views.evening_prayer,
        name="evening_prayer",
        distill_func=get_days,
    ),
    distill_path("compline/<int:year>-<int:month>-<int:day>/",
Esempio n. 2
0
# Replaces the standard django.conf.path, identical syntax
from django_distill import distill_path

from . import views

def get_index():
    # The index URI path, '', contains no parameters, named or otherwise.
    # You can simply just return nothing here.
    return None

urlpatterns = [
    # e.g. / the blog index
    distill_path('',
                 views.IndexView.as_view(),
                 name='index',
                 distill_func=get_index,
                 # / is not a valid file name! override it to index.html
                 distill_file='index.html')
]
Esempio n. 3
0

def __get_all_files(root: Path, folder: typing.Optional[Path] = None) -> list[str]:
    """Find all folders and HTML files recursively starting from `root`."""
    if not folder:
        folder = root

    results = []

    for sub_folder in folder.iterdir():
        results.append(
            sub_folder.relative_to(root).__str__().replace("\\", "/").replace(".html", "")
        )

        if sub_folder.is_dir():
            results.extend(__get_all_files(root, sub_folder))

    return results


def get_all_events() -> typing.Iterator[dict[str, str]]:
    """Yield a dict of all event pages."""
    for file in __get_all_files(Path("pydis_site", "templates", "events", "pages")):
        yield {"path": file}


urlpatterns = [
    distill_path("", IndexView.as_view(), name="index"),
    distill_path("<path:path>/", PageView.as_view(), name="page", distill_func=get_all_events),
]
Esempio n. 4
0
def map_redirect(name: str, data: Redirect) -> list[URLPattern]:
    """Return a pattern using the Redirects app, or a static HTML redirect for static builds."""
    if not settings.env("STATIC_BUILD"):
        # Normal dynamic redirect
        return [
            path(data.original_path,
                 CustomRedirectView.as_view(
                     pattern_name=data.redirect_route,
                     static_args=tuple(data.redirect_arguments),
                     prefix_redirect=data.prefix_redirect),
                 name=name)
        ]

    # Create static HTML redirects for static builds
    new_app_name = data.redirect_route.split(":")[0]

    if __PARAMETER_REGEX.search(data.original_path):
        # Redirects for paths which accept parameters
        # We generate an HTML redirect file for all possible entries
        paths = []

        class RedirectFunc:
            def __init__(self, new_url: str, _name: str):
                self.result = REDIRECT_TEMPLATE.format(url=new_url)
                self.__qualname__ = _name

            def __call__(self, *args, **kwargs):
                return self.result

        if new_app_name == resources_urls.app_name:
            items = resources_urls.get_all_resources()
        elif new_app_name == pages_urls.app_name:
            items = pages_urls.get_all_pages()
        else:
            raise ValueError(f"Unknown app in redirect: {new_app_name}")

        for item in items:
            entry = list(item.values())[0]

            # Replace dynamic redirect with concrete path
            concrete_path = __PARAMETER_REGEX.sub(entry, data.original_path)
            new_redirect = f"/{new_app_name}/{entry}"
            pattern_name = f"{name}_{entry}"

            paths.append(
                distill_path(concrete_path,
                             RedirectFunc(new_redirect, pattern_name),
                             name=pattern_name))

        return paths

    else:
        redirect_path_name = "pages" if new_app_name == "content" else new_app_name
        if len(data.redirect_arguments) > 0:
            redirect_arg = data.redirect_arguments[0]
        else:
            redirect_arg = "resources/"
        new_redirect = f"/{redirect_path_name}/{redirect_arg}"

        if new_redirect == "/resources/resources/":
            new_redirect = "/resources/"

        return [
            distill_path(
                data.original_path,
                lambda *args: REDIRECT_TEMPLATE.format(url=new_redirect),
                name=name,
            )
        ]
Esempio n. 5
0
from django.urls import path
from django_distill import distill_path

from . import views
from .sitemaps import StaticViewSitemap


def get():
    return None


sitemaps = {
    'static': StaticViewSitemap,
}

urlpatterns = [
    distill_path('',
                 views.index,
                 name='landing',
                 distill_func=get,
                 distill_file='index.html'),
    distill_path('portfolio',
                 views.portfolio,
                 name='portfolio',
                 distill_func=get,
                 distill_file='portfolio/index.html'),
    path('sitemap.xml',
         sitemap, {'sitemaps': sitemaps},
         name='django.contrib.sitemaps.views.sitemap'),
]
Esempio n. 6
0
from django_distill import distill_path

from pydis_site.apps.resources import views

app_name = "resources"
urlpatterns = [
    distill_path("", views.resources.ResourceView.as_view(), name="index"),
    distill_path("<resource_type>/",
                 views.resources.ResourceView.as_view(),
                 name="index"),
]
Esempio n. 7
0
from django.http import HttpResponse
from django_distill import distill_path
from django.urls import get_urlconf


app_name = 'test'


def test_url_in_deep_namespace_view(request):
    return HttpResponse(b'test', content_type='application/octet-stream')


def test_no_param_func():
    return None


urlpatterns = [

    distill_path('sub-url-in-sub-namespace',
        test_url_in_deep_namespace_view,
        name='test_url_in_namespace',
        distill_func=test_no_param_func,
        distill_file='test_url_in_sub_namespace'),

]
Esempio n. 8
0
from django_distill import distill_path

from .views import HomeView, timeline

app_name = 'home'
urlpatterns = [
    distill_path('', HomeView.as_view(), name='home'),
    distill_path('timeline/', timeline, name="timeline"),
]
Esempio n. 9
0
def get_index():
    return None


def get_all_artists():
    return list(Artist.objects.values_list('slug', flat=True))


def get_all_releases():
    return list(Release.objects.values_list('slug', flat=True))


urlpatterns = [
    path('admin/', admin.site.urls),
    distill_path('', views.home, name='home'),
    distill_re_path(
        r'^artists/$', views.artists, name='artists', distill_func=get_index),
    distill_re_path(r'^artists/(?P<slug>[\w-]+)/$',
                    views.artist,
                    name='artist',
                    distill_func=get_all_artists),
    distill_re_path(r'^releases/$',
                    views.releases,
                    name='releases',
                    distill_func=get_index),
    distill_re_path(r'^releases/(?P<slug>[\w-]+)/$',
                    views.release,
                    name='release',
                    distill_func=get_all_releases),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Esempio n. 10
0
from django_distill import distill_path
from .views import SiteIndexView


def get_index():
    return None


urlpatterns = [
    distill_path('',
                 SiteIndexView.as_view(),
                 name='index',
                 distill_func=get_index,
                 distill_file='index.html'),
]
Esempio n. 11
0
from django.urls import path
from django_distill import distill_path
from . import views


def get_index():
    return None


app_name = 'blog'
urlpatterns = [
    distill_path('',
                 views.index,
                 name="index",
                 distill_func=get_index,
                 distill_file="blog/index.html")
]
Esempio n. 12
0
def get_index():
    return None


def get_posts():
    for post in Post.objects.published():
        yield {'slug': post.slug}


def get_tags():
    for tag in Tag.objects.all():
        yield {'tag': tag.name}


urlpatterns = [
    distill_path('',
                 IndexView.as_view(),
                 name='blog-index',
                 distill_func=get_index,
                 distill_file='index.html'),
    distill_path('post/<slug:slug>.html',
                 PostView.as_view(),
                 name='blog-post',
                 distill_func=get_posts),
    distill_path('tag/<slug:tag>.html',
                 TagView.as_view(),
                 name='blog-tag',
                 distill_func=get_tags),
]
Esempio n. 13
0
from django_distill import distill_path
from . import views


def get_index():
    return None


urlpatterns = [
    path('', views.index, name='index'),
    path('admin/', admin.site.urls),
    path('blog/', include('blog.urls')),
    path('about/', views.about, name='about'),
]

urlpatterns = [
    path('admin/', admin.site.urls),
    path('blog/', include('blog.urls')),
    distill_path('',
                 views.index,
                 name='index',
                 distill_func=get_index,
                 distill_file="index.html"),
    distill_path('about.html',
                 views.about,
                 name='d_about',
                 distill_func=get_index,
                 distill_file="about.html"),
    path('about/', views.about, name='about'),
]
Esempio n. 14
0
    results = []

    for item in folder.iterdir():
        name = item.relative_to(root).__str__().replace("\\", "/")

        if item.is_dir():
            results.append(name)
            results.extend(__get_all_files(root, item))
        else:
            path, extension = name.rsplit(".", maxsplit=1)
            if extension == "md":
                results.append(path)

    return results


def get_all_pages() -> typing.Iterator[dict[str, str]]:
    """Yield a dict of all page categories."""
    for location in __get_all_files(
            Path("pydis_site", "apps", "content", "resources")):
        yield {"location": location}


urlpatterns = [
    distill_path("", views.PageOrCategoryView.as_view(), name='pages'),
    distill_path("<path:location>/",
                 views.PageOrCategoryView.as_view(),
                 name='page_category',
                 distill_func=get_all_pages),
]
def get_index():
    return None


def get_sitemap():
    return 'sitemap.xml'


def get_all_blog():
    for post in Blog.objects.filter(is_active=True):
        yield {'slug': post.slug}


urlpatterns = [
    path('admin/', admin.site.urls),
    distill_path('', home.view, name="home", distill_func=get_index),
    distill_path('', home.not_found_view, name="not_found", distill_func=get_index, distill_file="404.html"),
    distill_path('', home.cname_view, name="cname", distill_func=get_index, distill_file="CNAME"),
    # distill_path('', home.sitemap_view, name="sitemap", distill_func=get_index, distill_file="sitemap.xml"),
    distill_path('', home.robots_txt_view, name="robots_txt", distill_func=get_index, distill_file="robots.txt"),
    distill_path('success/', home.form_success, name="form_success", distill_func=get_index),
    distill_path('about/', about.view, name="about", distill_func=get_index),
    distill_path('seo-toronto/', seo.view, name="seo", distill_func=get_index),
    distill_path('social-media-marketing/', social_media.view, name="social_media", distill_func=get_index),
    distill_path('web-design-development-toronto/', web_development.view, name="web_development",
                 distill_func=get_index),
    distill_path('graphic-design/', graphic_design.view, name="graphic_design", distill_func=get_index),
    distill_path('app-development/', app_development.view, name="app_development", distill_func=get_index),
    # distill_path('blog/', blog.view, name="blog", distill_func=get_index),
    distill_path('contact/', contact.view, name="contact", distill_func=get_index),
    distill_path('privacy/', privacy.view, name="privacy", distill_func=get_index),
Esempio n. 16
0
from django.urls import path
import jobs.views
from django.conf import settings
from django.conf.urls.static import static


def get_index():
    return None


def get_detail():
    return None


urlpatterns = [
    path('admin/', admin.site.urls),
    distill_path('',
                 jobs.views.homepage,
                 name='home',
                 distill_func=get_index,
                 distill_file='home.html'),
    distill_path('jobs/<int:job_id>',
                 jobs.views.detail,
                 name='detail',
                 distill_func=get_detail,
                 distill_file='detail.html'),
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Esempio n. 17
0
                        distill_func=test_named_param_func),
        distill_re_path(r'^re_path/broken$',
                        test_broken_view,
                        name='re_path-broken',
                        distill_func=test_no_param_func),
        distill_re_path(r'^re_path/ignore-sessions$',
                        test_session_view,
                        name='re_path-ignore-sessions',
                        distill_func=test_no_param_func),
    ]

if settings.HAS_PATH:
    urlpatterns += [
        distill_path('path/',
                     test_no_param_view,
                     name='path-no-param',
                     distill_func=test_no_param_func,
                     distill_file='test'),
        distill_path('path/<int>',
                     test_positional_param_view,
                     name='path-positional-param',
                     distill_func=test_positional_param_func),
        distill_path('path/<str:param>',
                     test_named_param_view,
                     name='path-named-param',
                     distill_func=test_named_param_func),
        distill_path('path/broken',
                     test_broken_view,
                     name='path-broken',
                     distill_func=test_no_param_func),
        distill_path('path/ignore-sessions',
Esempio n. 18
0
                        name='re_path-positional-param',
                        distill_func=test_positional_param_func),
        distill_re_path(r'^re_path/(?P<param>[\w]+)$',
                        test_named_param_view,
                        name='re_path-named-param',
                        distill_func=test_named_param_func),

    ]


if settings.HAS_PATH:
    urlpatterns += [

        distill_path('path/',
                    test_no_param_view,
                    name='path-no-param',
                    distill_func=test_no_param_func,
                    distill_file='test'),
        distill_path('path/<int>',
                    test_positional_param_view,
                    name='path-positional-param',
                    distill_func=test_positional_param_func),
        distill_path('path/<str:param>',
                    test_named_param_view,
                    name='path-named-param',
                    distill_func=test_named_param_func),

    ]


# eof