Skip to content

Commit

Permalink
Set default base path (#326)
Browse files Browse the repository at this point in the history
* set base path using force_script_name

* get base_path from config file

* add slash for media url

* remove hard code url with url template

* default base_path is /tickets

* update base_path for account dropdown menu
  • Loading branch information
odkhang authored Sep 24, 2024
1 parent 19853cc commit 98d72f5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/pretix/presale/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def _default_context(request):
],
timeout=300 # The cache timeout
)
ctx['base_path'] = settings.BASE_PATH

ctx['html_head'] = "".join(h for h in _html_head if h)
ctx['html_foot'] = "".join(h for h in _html_foot if h)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{% endcompress %}
{{ request.event.organizer.slug|json_script:"organizer_name" }}
{{ request.event.slug|json_script:"event_slug" }}
{{ base_path|json_script:"base_path" }}
{% endblock %}
{% block content %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script type="text/javascript" src="{% static "pretixpresale/js/ui/popover.js" %}"></script>
{% endcompress %}
{{ request.organizer.slug|json_script:"organizer_name" }}
{{ base_path|json_script:"base_path" }}
{% if organizer.settings.locales|length > 1 or request.organizer.settings.customer_accounts %}
{% if organizer.settings.theme_color_background|upper != "#FFFFFF" or organizer.settings.organizer_logo_image_large %}
<div class="container page-header-links">
Expand Down
2 changes: 1 addition & 1 deletion src/pretix/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
}
DATABASE_ROUTERS = ['pretix.helpers.database.ReplicaRouter']

BASE_PATH = config.get('pretix', 'base_path', fallback='')
BASE_PATH = config.get('pretix', 'base_path', fallback='/tickets')

FORCE_SCRIPT_NAME = BASE_PATH

Expand Down
13 changes: 7 additions & 6 deletions src/pretix/static/pretixpresale/js/ui/popover.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
$(function () {
var organizerName = JSON.parse(document.getElementById('organizer_name').textContent);
var eventSlug = JSON.parse(document.getElementById('event_slug').textContent);
var basePath = JSON.parse(document.getElementById('base_path').textContent);
var options = {
html: true,
content: `<div data-name="popover-content">
<div class="options">
<a href="/${organizerName}/${eventSlug}" target="_self" class="btn btn-outline-success">
<a href="${basePath}/${organizerName}/${eventSlug}" target="_self" class="btn btn-outline-success">
<i class="fa fa-ticket"></i> ${window.gettext('Tickets')}
</a>
</div>
<div class="options">
<a href="/${organizerName}/account" target="_self" class="btn btn-outline-success">
<a href="${basePath}/${organizerName}/account" target="_self" class="btn btn-outline-success">
<i class="fa fa-shopping-cart"></i> ${window.gettext('My Orders')}
</a>
</div>
Expand All @@ -28,7 +29,7 @@ $(function () {

$(function () {
var organizerName = JSON.parse(document.getElementById('organizer_name').textContent);
var eventSlug = JSON.parse(document.getElementById('event_slug').textContent);
var basePath = JSON.parse(document.getElementById('base_path').textContent);
var currentPath = window.location.pathname;
var queryString = window.location.search;
var logoutPath = `/${organizerName}/account/logout?next=${encodeURIComponent(currentPath)}%3F${encodeURIComponent(queryString)}`;
Expand All @@ -37,17 +38,17 @@ $(function () {
html: true,
content: `<div data-name="popover-profile-menu">
<div class="profile-menu">
<a href="/${organizerName}/account/order" target="_self" class="btn btn-outline-success">
<a href="${basePath}/${organizerName}/account/order" target="_self" class="btn btn-outline-success">
<i class="fa fa-shopping-cart"></i> ${window.gettext('My Orders')}
</a>
</div>
<div class="profile-menu">
<a href="/${organizerName}/account" target="_self" class="btn btn-outline-success">
<a href="${basePath}/${organizerName}/account" target="_self" class="btn btn-outline-success">
<i class="fa fa-user"></i> ${window.gettext('Account')}
</a>
</div>
<div class="profile-menu">
<a href="${logoutPath}" target="_self" class="btn btn-outline-success">
<a href="${basePath}${logoutPath}" target="_self" class="btn btn-outline-success">
<i class="fa fa-sign-out"></i> ${window.gettext('Logout')}
</a>
</div>
Expand Down

0 comments on commit 98d72f5

Please sign in to comment.