diff options
Diffstat (limited to 'pydis_site')
-rw-r--r-- | pydis_site/apps/home/templatetags/extra_tags.py | 65 | ||||
-rw-r--r-- | pydis_site/static/css/wiki/style.css | 14 | ||||
-rw-r--r-- | pydis_site/templates/base/paginator.html | 65 | ||||
-rw-r--r-- | pydis_site/templates/wiki/dir.html | 132 | ||||
-rw-r--r-- | pydis_site/templates/wiki/history.html | 6 | ||||
-rw-r--r-- | pydis_site/templates/wiki/includes/pagination.html | 26 | ||||
-rw-r--r-- | pydis_site/templates/wiki/plugins/images/index.html | 4 | ||||
-rw-r--r-- | pydis_site/templates/wiki/search.html | 102 |
8 files changed, 156 insertions, 258 deletions
diff --git a/pydis_site/apps/home/templatetags/extra_tags.py b/pydis_site/apps/home/templatetags/extra_tags.py deleted file mode 100644 index a4da1742..00000000 --- a/pydis_site/apps/home/templatetags/extra_tags.py +++ /dev/null @@ -1,65 +0,0 @@ -from urllib.parse import urlparse, ParseResult, urlunparse - -from django.template import Context, Library -from django.urls import resolve, reverse, NoReverseMatch - -register = Library() - - [email protected]_tag(takes_context=True) -def url_extend(context: Context, *args, **kwargs): - current_url = context["request"].get_full_path() - resolved = resolve(current_url) - - url = resolved.url_name - app_name = resolved.app_name - - try: - _args = resolved.args - _kwargs = resolved.kwargs.copy() - - _args += args - _kwargs.update(kwargs) - - if app_name: - pattern = f"{app_name}:{url}" - else: - pattern = url - - return reverse(pattern, args=_args, kwargs=_kwargs) - except NoReverseMatch: - _args = resolved.args - _kwargs = resolved.kwargs.copy() - - if app_name: - pattern = f"{app_name}:{url}" - else: - pattern = url - - reversed_url = reverse(pattern, args=_args, kwargs=_kwargs) - parsed: ParseResult = urlparse(reversed_url) - - params = parsed.params - - if params: - params += f"&" - else: - params = "?" - - params += "&".join(args) - kwarg_list = [] - - for key, value in kwargs.items(): - kwarg_list.append(f"{key}={value}") - - params += "&".join(kwarg_list) - - parsed = ParseResult( - parsed.scheme, parsed.netloc, parsed.path, - "", parsed.query, parsed.fragment - ) - - unparsed = urlunparse(parsed) + params - print(parsed) - print(unparsed) - return unparsed diff --git a/pydis_site/static/css/wiki/style.css b/pydis_site/static/css/wiki/style.css index 61ded7ce..c5dbd7c3 100644 --- a/pydis_site/static/css/wiki/style.css +++ b/pydis_site/static/css/wiki/style.css @@ -5,3 +5,17 @@ div.control.is-fullwidth { width: 100%; } + +ul.pagination-list { + list-style: none; + margin: 0; +} + +ul.pagination-list li + li { + margin: 0; +} + +.pagination { + margin-top: 0.5rem; + margin-bottom: 0.5rem; +} diff --git a/pydis_site/templates/base/paginator.html b/pydis_site/templates/base/paginator.html deleted file mode 100644 index 9cf031f0..00000000 --- a/pydis_site/templates/base/paginator.html +++ /dev/null @@ -1,65 +0,0 @@ -{% load extra_tags %} -{% comment %} -This template inserts a Bulma paginator wherever one is required. Simply include it as follows: - -{% include "base/paginator.html" with page_obj=paginator_object %} -{% endcomment %} - -<nav class="pagination" role="navigation" aria-label="pagination"> - {% if page_obj.has_previous %} - <a class="pagination-previous" href="{% url_extend page=page_obj.previous_page_number %}">Newer</a> - {% else %} - <a class="pagination-previous" title="This is the first page" disabled>Newer</a> - {% endif %} - - {% if page_obj.has_next %} - <a class="pagination-next" href="{% url_extend page=1 %}">Older</a> - {% else %} - <a class="pagination-next" title="This is the last page" disabled>Older</a> - {% endif %} - - <ul class="pagination-list"> - {% if page_obj.has_previous %} - <li> - <a class="pagination-link" aria-label="Goto page 1" - href="{% url_extend page=1 %}"> - 1 - </a> - </li> - <li> - <span class="pagination-ellipsis">…</span> - </li> - <li> - <a class="pagination-link" aria-label="Goto page {{ page_obj.previous_page_number }}" - href="{% url_extend page=page_obj.previous_page_number %}"> - {{ page_obj.previous_page_number }} - </a> - </li> - {% endif %} - - <li> - <a class="pagination-link is-current" aria-label="Page {{ page_obj.number }}" aria-current="page" - href="{% url_extend page=page_obj.number %}"> - {{ page_obj.number }} - </a> - </li> - - {% if page_obj.has_next %} - <li> - <a class="pagination-link" aria-label="Goto page {{ page_obj.next_page_number }}" - href="{% url_extend page=page_obj.next_page_number %}"> - {{ page_obj.next_page_number }} - </a> - </li> - <li> - <span class="pagination-ellipsis">…</span> - </li> - <li> - <a class="pagination-link" aria-label="Goto page {{ page_obj.paginator.num_pages }}" - href="{% url_extend page=page_obj.paginator.num_pages %}"> - {{ page_obj.paginator.num_pages }} - </a> - </li> - {% endif %} - </ul> -</nav> diff --git a/pydis_site/templates/wiki/dir.html b/pydis_site/templates/wiki/dir.html index 283fe598..d8560089 100644 --- a/pydis_site/templates/wiki/dir.html +++ b/pydis_site/templates/wiki/dir.html @@ -5,80 +5,76 @@ {% block wiki_pagetitle %}{% trans "Listing articles in" %} {{ article.current_revision.title }}{% endblock %} {% block wiki_contents_tab %} + {% url 'wiki:dir' urlpath.path as self_url %} -{% url 'wiki:dir' urlpath.path as self_url %} - -<form class="form-search directory-toolbar"> -<div class="well well-small"> - <div class="btn-group pull-left"> - {% if urlpath.parent %} - <a href="{% url 'wiki:dir' path=urlpath.parent.path %}" class="btn btn-default"> - <span class="fa fa-arrow-up"></span> - {% trans "Up one level" %} - </a> - {% endif %} - <a href="{% url 'wiki:create' path=urlpath.path %}" class="btn btn-default"> - <span class="fa fa-plus"></span> - {% trans "Add article" %} - </a> - </div> - <div class="pull-right"> - {{ filter_form.query }} - </div> - {% if filter_query %} - <div class="pull-right filter-clear"> - <a href="{{ self_url }}">({% trans "clear" %})</a> + <form class="form-search directory-toolbar"> + <div class="well well-small"> + <div class="btn-group pull-left"> + {% if urlpath.parent %} + <a href="{% url 'wiki:dir' path=urlpath.parent.path %}" class="btn btn-default"> + <span class="fa fa-arrow-up"></span> + {% trans "Up one level" %} + </a> + {% endif %} + <a href="{% url 'wiki:create' path=urlpath.path %}" class="btn btn-default"> + <span class="fa fa-plus"></span> + {% trans "Add article" %} + </a> + </div> + <div class="pull-right"> + {{ filter_form.query }} </div> - {% endif %} + {% if filter_query %} + <div class="pull-right filter-clear"> + <a href="{{ self_url }}">({% trans "clear" %})</a> + </div> + {% endif %} - <div class="clearfix"></div> -</div> -</form> + <div class="clearfix"></div> + </div> + </form> -<p> - {% with paginator.object_list.count as cnt %} - {% blocktrans with urlpath.path as path and cnt|pluralize:_("article,articles") as articles_plur and cnt|pluralize:_("is,are") as articles_plur_verb trimmed %} - Browsing <strong><a href="{{ self_url }}">/{{ path }}</a></strong>. There {{ articles_plur_verb }} <strong>{{ cnt }} {{ articles_plur }}</strong> in this level. - {% endblocktrans %} - {% endwith %} -</p> + <p> + {% with paginator.object_list.count as cnt %} + {% blocktrans with urlpath.path as path and cnt|pluralize:_("article,articles") as articles_plur and cnt|pluralize:_("is,are") as articles_plur_verb trimmed %} + Browsing <strong><a href="{{ self_url }}">/{{ path }}</a></strong>. There {{ articles_plur_verb }} <strong>{{ cnt }} {{ articles_plur }}</strong> in this level. + {% endblocktrans %} + {% endwith %} + </p> -<table class="table table-striped"> - <tr> - <th>{% trans "Title" %}</th> - <th>{% trans "Slug" %}</th> - <th>{% trans "Last modified" %}</th> - </tr> - {% for urlpath in directory %} + <table class="table table-striped"> <tr> - <td> - <a href="{% url 'wiki:get' path=urlpath.path %}"> {{ urlpath.article.current_revision.title }} </a> - <a href="{% url 'wiki:dir' path=urlpath.path %}" class="list-children"> › </a> - {% if urlpath.article.current_revision.deleted %} - <span class="fa fa-trash"></span> - {% endif %} - {% if urlpath.article.current_revision.locked %} - <span class="fa fa-lock"></span> - {% endif %} - </td> - <td> - {{ urlpath.slug }} - </td> - <td> - {{ urlpath.article.current_revision.created|naturaltime }} - </td> + <th>{% trans "Title" %}</th> + <th>{% trans "Slug" %}</th> + <th>{% trans "Last modified" %}</th> </tr> - {% empty%} - <tr> - <td colspan="100"> - <em>{% trans "There are no articles in this level" %}</em> - </td> - </tr> - {% endfor %} -</table> - -{% if is_paginated %} - {% include "base/paginator.html" with page=page_obj %} -{% endif %} + {% for urlpath in directory %} + <tr> + <td> + <a href="{% url 'wiki:get' path=urlpath.path %}"> {{ urlpath.article.current_revision.title }} </a> + <a href="{% url 'wiki:dir' path=urlpath.path %}" class="list-children"> › </a> + {% if urlpath.article.current_revision.deleted %} + <span class="fa fa-trash"></span> + {% endif %} + {% if urlpath.article.current_revision.locked %} + <span class="fa fa-lock"></span> + {% endif %} + </td> + <td> + {{ urlpath.slug }} + </td> + <td> + {{ urlpath.article.current_revision.created|naturaltime }} + </td> + </tr> + {% empty%} + <tr> + <td colspan="100"> + <em>{% trans "There are no articles in this level" %}</em> + </td> + </tr> + {% endfor %} + </table> + {% include "wiki/includes/pagination.html" %} {% endblock %} diff --git a/pydis_site/templates/wiki/history.html b/pydis_site/templates/wiki/history.html index afc6eafe..793b4888 100644 --- a/pydis_site/templates/wiki/history.html +++ b/pydis_site/templates/wiki/history.html @@ -49,6 +49,8 @@ {% trans "Click each revision to see a list of edited lines. Click the Preview button to see how the article looked at this stage. At the bottom of this page, you can change to a particular revision or merge an old revision with the current one." %} </p> + {% include "wiki/includes/pagination.html" %} + <form method="GET"> <div class="tab-content" style="overflow: visible;"> {% for revision in revisions %} @@ -120,10 +122,6 @@ {% include "wiki/includes/pagination.html" %} - {% if is_paginated %} - {% include "base/paginator.html" %} - {% endif %} - {% if revisions.count > 1 and article|can_write:user and not article.current_revision.locked %} <div class="form-group form-actions"> diff --git a/pydis_site/templates/wiki/includes/pagination.html b/pydis_site/templates/wiki/includes/pagination.html new file mode 100644 index 00000000..bd113dd6 --- /dev/null +++ b/pydis_site/templates/wiki/includes/pagination.html @@ -0,0 +1,26 @@ +{% load i18n %} +{% if is_paginated %} + <nav class="pagination" role="navigation" aria-label="pagination"> + {% if page_obj.has_previous %} + <a class="pagination-previous" href="?{% if search_query %}q={{ search_query }}&{% endif %}page={{ page_obj.previous_page_number }}{% if appended_key %}&{{ appended_key }}={{ appended_value }}{% endif %}">Previous</a> + {% else %} + <a class="pagination-previous tooltip" data-tooltip="This is the first page" disabled>Previous</a> + {% endif %} + + {% if page_obj.has_next %} + <a class="pagination-next" href="{% if search_query %}q={{ search_query }}&{% endif %}page={{ page_obj.next_page_number }}{% if appended_key %}&{{ appended_key }}={{ appended_value }}{% endif %}">Next</a> + {% else %} + <a class="pagination-next tooltip" data-tooltip="This is the last page" disabled>Older</a> + {% endif %} + + <ul class="pagination-list"> + {% for pc in paginator.page_range %} + {% if pc == 0 %} + <li><span class="pagination-ellipsis">…</span></li> + {% else %} + <li><a class="pagination-link{% if pc == page_obj.number %} is-current{% endif %}" href="?{% if search_query %}q={{ search_query }}&{% endif %}page={{ pc }}{% if appended_key %}&{{ appended_key }}={{ appended_value }}{% endif %}">{{ pc }}</a></li> + {% endif %} + {% endfor %} + </ul> + </nav> +{% endif %} diff --git a/pydis_site/templates/wiki/plugins/images/index.html b/pydis_site/templates/wiki/plugins/images/index.html index 64515208..4973ea6f 100644 --- a/pydis_site/templates/wiki/plugins/images/index.html +++ b/pydis_site/templates/wiki/plugins/images/index.html @@ -149,8 +149,6 @@ {% endfor %} </table> - {% if is_paginated %} - {% include "base/paginator.html" with page=page_obj %} - {% endif %} + {% include "wiki/includes/pagination.html" %} {% endblock %} diff --git a/pydis_site/templates/wiki/search.html b/pydis_site/templates/wiki/search.html index 700ed8c4..80379a1d 100644 --- a/pydis_site/templates/wiki/search.html +++ b/pydis_site/templates/wiki/search.html @@ -5,59 +5,55 @@ {% block wiki_pagetitle %}Search results for: "{{ search_query }}"{% endblock %} {% block wiki_contents %} - -<h1 class="page-header">Search results for: "{{ search_query }}"</h1> - -<form class="form-search directory-toolbar"> - <p> - {% if urlpath %} - Searching: <strong>in {{ urlpath.article }}</strong> - {% else %} - Searching: <strong>everywhere</strong> - {% endif %} - </p> - - <div class="field has-addons"> - <div class="control has-icons-left is-expanded"> - <input type="search" class="input" name="q" value="{{ search_query }}" /> - <span class="icon is-left"> - <i class="fas fa-search"></i> - </span> - </div> - <div class="control"> - <button class="button is-primary" type="submit"> - Search - </button> + <h1 class="page-header">Search results for: "{{ search_query }}"</h1> + + <form class="form-search directory-toolbar"> + <p> + {% if urlpath %} + Searching: <strong>in {{ urlpath.article }}</strong> + {% else %} + Searching: <strong>everywhere</strong> + {% endif %} + </p> + + <div class="field has-addons"> + <div class="control has-icons-left is-expanded"> + <input type="search" class="input" name="q" value="{{ search_query }}" /> + <span class="icon is-left"> + <i class="fas fa-search"></i> + </span> + </div> + <div class="control"> + <button class="button is-primary" type="submit"> + Search + </button> + </div> </div> - </div> - - <p> - {% blocktrans with paginator.object_list.count as cnt %} - Your search returned <strong>{{ cnt }}</strong> results. - {% endblocktrans %} - </p> -</form> - -<table class="table is-striped"> - <tr> - <th>Title</th> - <th class="has-text-right">Last modified</th> - </tr> - {% for article in articles %} - {% block wiki_search_loop %} - {% include "wiki/includes/searchresult.html" %} - {% endblock %} - {% empty %} - <tr> - <td colspan="2"> - <em>No articles were found for that search query.</em> - </td> - </tr> - {% endfor %} -</table> - -{% if is_paginated %} - {% include "base/paginator.html" with page=page_obj %} -{% endif %} + <p> + {% blocktrans with paginator.object_list.count as cnt %} + Your search returned <strong>{{ cnt }}</strong> results. + {% endblocktrans %} + </p> + </form> + + <table class="table is-striped"> + <tr> + <th>Title</th> + <th class="has-text-right">Last modified</th> + </tr> + {% for article in articles %} + {% block wiki_search_loop %} + {% include "wiki/includes/searchresult.html" %} + {% endblock %} + {% empty %} + <tr> + <td colspan="2"> + <em>No articles were found for that search query.</em> + </td> + </tr> + {% endfor %} + </table> + + {% include "wiki/includes/pagination.html" %} {% endblock %} |