Refactor package URL generation

This commit is contained in:
rubenwardy
2021-07-24 04:30:14 +01:00
parent 187202d363
commit 4e83adc032
35 changed files with 129 additions and 198 deletions

View File

@@ -32,7 +32,7 @@
{% set cover_image = package.cover_image.url or package.getMainScreenshotURL() %}
{% set tags = package.tags | sort(attribute="views", reverse=True) %}
<div class="carousel-item {% if loop.index == 1 %}active{% endif %}">
<a href="{{ package.getDetailsURL() }}">
<a href="{{ package.getURL("packages.view") }}">
<div class="embed-responsive embed-responsive-16by9">
<img class="embed-responsive-item" src="{{ cover_image }}"
alt="{{ _('%(title)s by %(author)s', title=package.title, author=package.author.display_name) }}">

View File

@@ -18,9 +18,9 @@
{% set message %}
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
{% if package.update_config %}
<a class="btn btn-sm btn-warning float-right" href="{{ package.getCreateReleaseURL() }}">Create first release</a>
<a class="btn btn-sm btn-warning float-right" href="{{ package.getURL("packages.create_release") }}">Create first release</a>
{% else %}
<a class="btn btn-sm btn-warning float-right" href="{{ package.getSetupReleasesURL() }}">Set up releases</a>
<a class="btn btn-sm btn-warning float-right" href="{{ package.getURL("packages.setup_releases") }}">Set up releases</a>
{% endif %}
{{ _("You need to create a release before this package can be approved.") }}
{% else %}

View File

@@ -1,5 +1,5 @@
{% macro render_pkgtile(package, show_author) -%}
<li class="packagetile flex-fill"><a href="{{ package.getDetailsURL() }}"
<li class="packagetile flex-fill"><a href="{{ package.getURL("packages.view") }}"
style="background-image: url({{ package.getThumbnailOrPlaceholder(2) }});">
<div class="packagegridscrub"></div>
<div class="packagegridinfo">

View File

@@ -88,7 +88,7 @@
created {{ rel.releaseDate | date }}.
</small>
{% if (package.checkPerm(current_user, "MAKE_RELEASE") or rel.checkPerm(current_user, "APPROVE_RELEASE")) and rel.task_id %}
<a href="{{ url_for('tasks.check', id=rel.task_id, r=package.getDetailsURL()) }}">Importing...</a>
<a href="{{ url_for('tasks.check', id=rel.task_id, r=package.getURL("packages.view")) }}">Importing...</a>
{% elif not rel.approved %}
Waiting for approval.
{% endif %}

View File

@@ -33,7 +33,7 @@
<div class="card-body markdown">
{% if current_user == review.author %}
<a class="btn btn-primary btn-sm ml-1 float-right"
href="{{ review.package.getReviewURL() }}">
href="{{ review.package.getURL("packages.review") }}">
<i class="fas fa-pen"></i>
</a>
{% endif %}
@@ -46,7 +46,7 @@
<p class="mt-2 mb-0">
{% if show_package_link %}
<a class="btn btn-primary mr-1" href="{{ review.package.getDetailsURL() }}">
<a class="btn btn-primary mr-1" href="{{ review.package.getURL("packages.view") }}">
{{ _("%(title)s by %(author)s",
title="<b>" | safe + review.package.title + "</b>" | safe,
author=review.package.author.display_name) }}
@@ -78,7 +78,7 @@
<div class="card-header">
{{ _("Review") }}
</div>
<form method="post" action="{{ package.getReviewURL() }}" class="card-body">
<form method="post" action="{{ package.getURL("packages.review") }}" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
{{ _("Do you recommend this %(type)s?", type=package.type.value | lower) }}
@@ -117,7 +117,7 @@
<div class="card-header">
{{ _("Review") }}
</div>
<form method="post" action="{{ package.getReviewURL() }}" class="card-body">
<form method="post" action="{{ package.getURL("packages.review") }}" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
{{ _("Do you recommend this %(type)s?", type=package.type.value | lower) }}

View File

@@ -49,7 +49,7 @@
{% if current_user == thread.author and thread.review and thread.replies[0] == r %}
<a class="float-right btn btn-primary btn-sm ml-2"
href="{{ thread.review.package.getReviewURL() }}">
href="{{ thread.review.package.getURL("packages.review") }}">
<i class="fas fa-pen"></i>
</a>
{% elif r.checkPerm(current_user, "EDIT_REPLY") %}

View File

@@ -5,7 +5,7 @@
<li class="list-group-item">
<div class="row">
{% if package %}
<a class="col-sm-auto text-muted" style="min-width: 200px;" href="{{ package.getDetailsURL() }}">
<a class="col-sm-auto text-muted" style="min-width: 200px;" href="{{ package.getURL("packages.view") }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"
@@ -45,7 +45,7 @@
</a>
{% if package.checkPerm(current_player, "MAKE_RELEASE") %}
<a class="btn btn-sm btn-secondary" href="{{ package.getUpdateConfigURL() }}">
<a class="btn btn-sm btn-secondary" href="{{ package.getURL("packages.update_config") }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>

View File

@@ -5,11 +5,11 @@
{% endblock %}
{% block link %}
<a href="{{ package.getDetailsURL() }}">{{ package.title }}</a>
<a href="{{ package.getURL("packages.view") }}">{{ package.title }}</a>
{% endblock %}
{% block content %}
<a class="btn btn-secondary" href="{{ package.getAliasListURL() }}">Back to Aliases</a>
<a class="btn btn-secondary" href="{{ package.getURL("packages.alias_list") }}">Back to Aliases</a>
{% from "macros/forms.html" import render_field, render_submit_field, render_toggle_field %}
<form method="POST" action="" enctype="multipart/form-data" class="mt-4">

View File

@@ -5,11 +5,11 @@
{% endblock %}
{% block link %}
<a href="{{ package.getDetailsURL() }}">{{ package.title }}</a>
<a href="{{ package.getURL("packages.view") }}">{{ package.title }}</a>
{% endblock %}
{% block content %}
<a class="btn btn-primary float-right" href="{{ package.getAliasCreateURL() }}">Create</a>
<a class="btn btn-primary float-right" href="{{ package.getURL("packages.alias_create_edit") }}">Create</a>
<h1>{{ _("Aliases for %(title)s by %(author)s", title=self.link(), author=package.author.display_name) }}</h1>
<div class="list-group">

View File

@@ -6,7 +6,7 @@
<div class="row">
<div class="col-md-3 mb-4">
<div class="list-group">
<a class="list-group-item list-group-item-action" href="{{ package.getDetailsURL() }}">
<a class="list-group-item list-group-item-action" href="{{ package.getURL("packages.view") }}">
<span class="row m-0 p-0">
<span class="col-auto m-0 p-0">
<img class="img-fluid user-photo img-thumbnail img-thumbnail-1"

View File

@@ -9,7 +9,7 @@
{% if package.update_config %}
<p class="alert alert-secondary mb-4">
<a class="float-right btn btn-sm btn-secondary" href="{{ package.getUpdateConfigURL() }}">{{ _("Settings") }}</a>
<a class="float-right btn btn-sm btn-secondary" href="{{ package.getURL("packages.update_config") }}">{{ _("Settings") }}</a>
{% if package.update_config.make_release %}
{{ _("You have automatic releases enabled.") }}
{% else %}
@@ -20,12 +20,12 @@
{% else %}
<p class="alert alert-info mb-4">
{% if package.repo %}
<a class="float-right btn btn-sm btn-info" href="{{ package.getSetupReleasesURL() }}">{{ _("Set up") }}</a>
<a class="float-right btn btn-sm btn-info" href="{{ package.getURL("packages.setup_releases") }}">{{ _("Set up") }}</a>
<i class="fas fa-info mr-2"></i>
{{ _("You can create releases automatically when you push commits or tags to your repository.") }}
{% else %}
<a class="float-right btn btn-sm btn-info" href="{{ package.getEditURL() }}">{{ _("Add Git repo") }}</a>
<a class="float-right btn btn-sm btn-info" href="{{ package.getURL("packages.create_edit") }}">{{ _("Add Git repo") }}</a>
<i class="fas fa-info mr-2"></i>
{{ _("Using Git would allow you to create releases automatically when you push code or tags.") }}

View File

@@ -5,7 +5,7 @@
{% endblock %}
{% block content %}
<a class="btn btn-secondary float-right" href="{{ package.getDetailsURL() }}">
<a class="btn btn-secondary float-right" href="{{ package.getURL("packages.view") }}">
{{ _("Later") }}
</a>
<h1>{{ self.title() }}</h1>
@@ -30,13 +30,13 @@
<div class="col-md-6 mt-5">
<h3 class="mt-0">{{ _("Automatically (Recommended)") }}</h3>
<p>
<a class="btn btn-primary" href="{{ package.getUpdateConfigURL(trigger="commit") }}">
<a class="btn btn-primary" href="{{ package.getURL("packages.update_config", trigger="commit") }}">
{{ _("Rolling Release") }}
</a>
<a class="btn btn-primary ml-2" href="{{ package.getUpdateConfigURL(trigger="tag") }}">
<a class="btn btn-primary ml-2" href="{{ package.getURL("packages.update_config", trigger="tag") }}">
{{ _("On Git Tag") }}
</a>
{# <a class="btn btn-secondary ml-2" href="{{ package.getUpdateConfigURL() }}">#}
{# <a class="btn btn-secondary ml-2" href="{{ package.getURL("packages.update_config") }}">#}
{# {{ _("Advanced") }}#}
{# </a>#}
</p>
@@ -45,10 +45,10 @@
<div class="col-md-6 mt-5">
<h3 class="mt-0">{{ _("Manually") }}</h3>
<p>
<a class="btn btn-secondary" href="{{ package.getUpdateConfigURL(action="notification") }}">
<a class="btn btn-secondary" href="{{ package.getURL("packages.update_config", action="notification") }}">
{{ _("With reminders") }}
</a>
<a class="btn btn-secondary ml-2" href="{{ package.getCreateReleaseURL() }}">
<a class="btn btn-secondary ml-2" href="{{ package.getURL("packages.create_release") }}">
{{ _("No reminders") }}
</a>
</p>
@@ -65,9 +65,9 @@
</p>
<p class="mt-5">
<a class="btn btn-primary" href="{{ package.getEditURL() }}">Add Git repo</a>
<a class="btn btn-secondary ml-2" href="{{ package.getCreateReleaseURL() }}">Create releases manually</a>
<a class="btn btn-secondary ml-2" href="{{ package.getDetailsURL() }}">Later</a>
<a class="btn btn-primary" href="{{ package.getURL("packages.create_edit") }}">Add Git repo</a>
<a class="btn btn-secondary ml-2" href="{{ package.getURL("packages.create_release") }}">Create releases manually</a>
<a class="btn btn-secondary ml-2" href="{{ package.getURL("packages.view") }}">Later</a>
</p>
{% endif %}
{% endblock %}

View File

@@ -8,23 +8,23 @@
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<p class="float-right">
{% if package.update_config %}
<a class="btn btn-secondary" href="{{ package.getUpdateConfigURL() }}">
<a class="btn btn-secondary" href="{{ package.getURL("packages.update_config") }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>
{% elif package.repo %}
<a class="btn btn-secondary" href="{{ package.getSetupReleasesURL() }}">
<a class="btn btn-secondary" href="{{ package.getURL("packages.setup_releases") }}">
<i class="fas fa-hat-wizard mr-1"></i>
{{ _("Set up automatic releases") }}
</a>
{% endif %}
<a class="btn btn-secondary ml-1" href="{{ package.getBulkReleaseURL() }}">
<a class="btn btn-secondary ml-1" href="{{ package.getURL("packages.bulk_change_release") }}">
<i class="fas fa-wrench mr-1"></i>
Bulk update
</a>
<a class="btn btn-primary ml-1" href="{{ package.getCreateReleaseURL() }}">
<a class="btn btn-primary ml-1" href="{{ package.getURL("packages.create_release") }}">
<i class="fas fa-plus mr-1"></i>
Create
</a>

View File

@@ -23,7 +23,7 @@ Remove {{ package.title }}
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<a class="btn btn-secondary float-right" href="{{ package.getDetailsURL() }}">Cancel</a>
<a class="btn btn-secondary float-right" href="{{ package.getURL("packages.view") }}">Cancel</a>
<input type="submit" name="delete" value="Remove" class="btn btn-danger mr-2" />

View File

@@ -5,7 +5,7 @@
{% endblock %}
{% block link %}
<a href="{{ package.getDetailsURL() }}">{{ package.title }}</a>
<a href="{{ package.getURL("packages.view") }}">{{ package.title }}</a>
{% endblock %}
{% block content %}

View File

@@ -6,7 +6,7 @@
{% block content %}
{% if package.checkPerm(current_user, "ADD_SCREENSHOTS") %}
<a href="{{ package.getNewScreenshotURL() }}" class="btn btn-primary float-right">
<a href="{{ package.getURL("packages.create_screenshot") }}" class="btn btn-primary float-right">
<i class="fas fa-plus mr-1"></i>
{{ _("Add Image") }}
</a>

View File

@@ -13,7 +13,7 @@ Share and Badges
Review link:
</p>
<pre><code>{{ package.getReviewURL(external=True) }}</code></pre>
<pre><code>{{ package.getURL("packages.review", absolute=True) }}</code></pre>
<h3>Badges</h3>

View File

@@ -10,7 +10,7 @@
<meta name="og:title" content="{{ package.title }}"/>
<meta name="og:description" content="{{ package.short_desc }}"/>
<meta name="description" content="{{ package.short_desc }}"/>
<meta name="og:url" content="{{ package.getDetailsURL(absolute=True) }}"/>
<meta name="og:url" content="{{ package.getURL("packages.view", absolute=True) }}"/>
{% if package.getMainScreenshotURL() %}
<meta name="og:image" content="{{ package.getMainScreenshotURL(absolute=True) }}"/>
{% endif %}
@@ -35,19 +35,19 @@
<div class="container">
<div class="btn-group float-right mb-4">
{% if package.checkPerm(current_user, "EDIT_PACKAGE") %}
<a class="btn btn-primary" href="{{ package.getEditURL() }}">
<a class="btn btn-primary" href="{{ package.getURL("packages.create_edit") }}">
<i class="fas fa-pen mr-1"></i>
{{ _("Edit") }}
</a>
{% endif %}
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<a class="btn btn-primary" href="{{ package.getCreateReleaseURL() }}">
<a class="btn btn-primary" href="{{ package.getURL("packages.create_release") }}">
<i class="fas fa-plus mr-1"></i>
{{ _("Release") }}
</a>
{% endif %}
{% if package.checkPerm(current_user, "DELETE_PACKAGE") or package.checkPerm(current_user, "UNAPPROVE_PACKAGE") %}
<a class="btn btn-danger" href="{{ package.getRemoveURL() }}">
<a class="btn btn-danger" href="{{ package.getURL("packages.remove") }}">
<i class="fas fa-trash mr-1"></i>
{{ _("Remove") }}
</a>
@@ -94,7 +94,7 @@
</span>
</a>
{% if release %}
<a class="btn" rel="nofollow" href="{{ package.getDownloadURL() }}" title="{{ _("Downloads") }}"
<a class="btn" rel="nofollow" href="{{ package.getURL("packages.download") }}" title="{{ _("Downloads") }}"
download="{{ release.getDownloadFileName() }}">
<i class="fas fa-download"></i>
<span class="count">{{ package.downloads }}</span>
@@ -154,7 +154,7 @@
<div class="btn-group btn-group-horizontal col-md-auto">
{% if release %}
<a class="btn btn-download" rel="nofollow" download="{{ release.getDownloadFileName() }}"
href="{{ package.getDownloadURL() }}">
href="{{ package.getURL("packages.download") }}">
{{ _("Download") }}
</a>
{% if package.type == package.type.MOD %}
@@ -209,7 +209,7 @@
{% set screenshots = package.screenshots.all() %}
{% if screenshots or package.checkPerm(current_user, "ADD_SCREENSHOTS") %}
{% if package.checkPerm(current_user, "ADD_SCREENSHOTS") %}
<a href="{{ package.getEditScreenshotsURL() }}" class="btn btn-primary float-right">
<a href="{{ package.getURL("packages.screenshots") }}" class="btn btn-primary float-right">
<i class="fas fa-images mr-1"></i>
Edit
</a>
@@ -229,7 +229,7 @@
{% endif %}
{% else %}
<li>
<a href="{{ package.getNewScreenshotURL() }}">
<a href="{{ package.getURL("packages.create_screenshot") }}">
<i class="fas fa-plus screenshot-add"></i>
</a>
</li>
@@ -249,7 +249,7 @@
{% if current_user.is_authenticated %}
{% if has_review %}
<p>
<a class="btn btn-primary" href="{{ package.getReviewURL() }}">
<a class="btn btn-primary" href="{{ package.getURL("packages.review") }}">
{{ _("Edit Review") }}
</a>
</p>
@@ -307,7 +307,7 @@
<i class="fas fa-plus mr-1"></i>
{{ _("Release") }}
</a>
<a class="btn btn-warning" href="{{ package.getUpdateConfigURL() }}">
<a class="btn btn-warning" href="{{ package.getURL("packages.update_config") }}">
<i class="fas fa-cog mr-1"></i>
{{ _("Update settings") }}
</a>
@@ -329,7 +329,7 @@
{% for dep in package.getSortedHardDependencies() %}
{%- if dep.package %}
<a class="badge badge-primary"
href="{{ dep.package.getDetailsURL() }}">
href="{{ dep.package.getURL("packages.view") }}">
{{ dep.package.title }} by {{ dep.package.author.display_name }}
</a>
{% elif dep.meta_package %}
@@ -352,7 +352,7 @@
{% for dep in optional_deps %}
{%- if dep.package %}
<a class="badge badge-secondary"
href="{{ dep.package.getDetailsURL() }}">
href="{{ dep.package.getURL("packages.view") }}">
{{ dep.package.title }} by {{ dep.package.author.display_name }}
{% elif dep.meta_package %}
<a class="badge badge-secondary"
@@ -399,7 +399,7 @@
{% endfor %}
{% if current_user in package.maintainers and current_user != package.author %}
<form class="mt-2" method="post" action="{{ package.getRemoveSelfMaintainerURL() }}">
<form class="mt-2" method="post" action="{{ package.getURL("packages.remove_self_maintainers") }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input class="btn btn-sm btn-link p-0" type="submit" value="{{ _('Remove myself') }}" />
</form>
@@ -422,7 +422,7 @@
<h3>
{% if package.checkPerm(current_user, "MAKE_RELEASE") %}
<a class="btn btn-primary btn-sm float-right" href="{{ package.getCreateReleaseURL() }}"><i class="fas fa-plus"></i></a>
<a class="btn btn-primary btn-sm float-right" href="{{ package.getURL("packages.create_release") }}"><i class="fas fa-plus"></i></a>
{% endif %}
{{ _("Releases") }}
</h3>
@@ -433,7 +433,7 @@
{% else %}
{{ render_releases_download(releases, package) }}
{% endif %}
<a class="list-group-item list-group-item-action text-center py-1 text-muted" href="{{ package.getReleaseListURL() }}">
<a class="list-group-item list-group-item-action text-center py-1 text-muted" href="{{ package.getURL("packages.list_releases") }}">
More
</a>
</div>
@@ -459,7 +459,7 @@
</a>
{% endif %}
{% if package.checkPerm(current_user, "EDIT_PACKAGE") %}
<a class="float-right" href="{{ package.getAuditLogURL() }}">
<a class="float-right" href="{{ package.getURL("packages.audit") }}">
See audit log
</a>
{% endif %}

View File

@@ -37,7 +37,7 @@
{% if current_user == thread.author and thread.review %}
<a class="btn btn-primary ml-1 float-right mr-2"
href="{{ thread.review.package.getReviewURL() }}">
href="{{ thread.review.package.getURL("packages.review") }}">
<i class="fas fa-pen"></i>
{{ _("Edit Review") }}
</a>
@@ -56,7 +56,7 @@
{% if thread.package %}
<p>
Package: <a href="{{ thread.package.getDetailsURL() }}">{{ thread.package.title }}</a>
Package: <a href="{{ thread.package.getURL("packages.view") }}">{{ thread.package.title }}</a>
</p>
{% endif %}

View File

@@ -17,7 +17,7 @@
</h3>
<ul class="card-body d-flex p-0 flex-row flex-wrap justify-content-start align-content-start p-4">
{% for s in screenshots %}
<li class="packagetile flex-fill"><a href="{{ s.getEditURL() }}"
<li class="packagetile flex-fill"><a href="{{ s.getURL("packages.create_edit") }}"
style="background-image: url({{ s.getThumbnailURL(3) }});">
<div class="packagegridscrub"></div>
<div class="packagegridinfo">
@@ -46,7 +46,7 @@
<h3 class="card-header">Packages</h3>
<div class="list-group list-group-flush">
{% for p in packages %}
<a href="{{ p.getDetailsURL() }}" class="list-group-item list-group-item-action">
<a href="{{ p.getURL("packages.view") }}" class="list-group-item list-group-item-action">
<span class="float-right" title="Created {{ p.created_at | datetime }}">
<small>
{{ p.created_at | timedelta }} ago
@@ -83,7 +83,7 @@
{% endif %}
<a href="{{ r.getEditURL() }}">{{ r.title }}</a>
on
<a href="{{ r.package.getDetailsURL() }}">
<a href="{{ r.package.getURL("packages.view") }}">
{{ r.package.title }} by {{ r.package.author.display_name }}
</a>
</li>
@@ -139,7 +139,7 @@
<h3 class="card-header">WIP Packages</h3>
<div class="list-group list-group-flush" style="max-height: 300px; overflow: hidden auto;">
{% for p in wip_packages %}
<a href="{{ p.getDetailsURL() }}" class="list-group-item list-group-item-action">
<a href="{{ p.getURL("packages.view") }}" class="list-group-item list-group-item-action">
<span class="float-right" title="Created {{ p.created_at | datetime }}">
<small>
{{ p.created_at | timedelta }} ago

View File

@@ -42,7 +42,7 @@
{% for package in packages %}
<tr>
<td>
<a href="{{ package.getDetailsURL() }}">
<a href="{{ package.getURL("packages.view") }}">
{{ package.title }}
</a>
@@ -50,7 +50,7 @@
</td>
<td class="text-center">
{% if package.checkPerm(current_user, "EDIT_PACKAGE") %}
<a class="btn btn-link btn-sm py-0" href="{{ package.getEditURL() }}">
<a class="btn btn-link btn-sm py-0" href="{{ package.getURL("packages.create_edit") }}">
<i class="fas fa-pen"></i>
</a>
{% endif %}

View File

@@ -8,7 +8,7 @@
<h2>{{ _("Unapproved Packages Needing Action") }}</h2>
<div class="list-group mt-3 mb-5">
{% for package in unapproved_packages %}
<a class="list-group-item list-group-item-action" href="{{ package.getDetailsURL() }}">
<a class="list-group-item list-group-item-action" href="{{ package.getURL("packages.view") }}">
<div class="row">
<div class="col-sm-2 text-muted">
<img
@@ -62,7 +62,7 @@
</p>
<div class="list-group mt-3 mb-5">
{% for package in needs_tags %}
<a class="list-group-item list-group-item-action" href="{{ package.getDetailsURL() }}">
<a class="list-group-item list-group-item-action" href="{{ package.getURL("packages.view") }}">
<img
class="img-fluid"
style="max-height: 22px; max-width: 22px;"