Time machine mode [Z#23129725] (#3961)

Allows organizers to test their shop as if it were a different date and time.

Implemented using a time_machine_now() function which is used instead of regular now(), which can overlay the real date time with a value from a ContextVar, assigned from a session value in EventMiddleware.

For more information, see doc/development/implementation/timemachine.rst

---------

Co-authored-by: Richard Schreiber <schreiber@rami.io>
Co-authored-by: Raphael Michel <michel@rami.io>
This commit is contained in:
Mira
2024-05-17 10:52:17 +02:00
committed by GitHub
parent bfcca7046a
commit b638c00952
38 changed files with 789 additions and 142 deletions

View File

@@ -111,9 +111,40 @@
{% if request.event.testmode %}
{% if request.sales_channel.testmode_supported %}
<div class="alert alert-warning">
<p><strong><span class="sr-only">{% trans "Warning" context "alert-messages" %}:</span>
{% trans "This ticket shop is currently in test mode. Please do not perform any real purchases as your order might be deleted without notice." %}
<p><strong>
<span class="sr-only">{% trans "Warning" context "alert-messages" %}:</span>
{% trans "This ticket shop is currently in test mode." %}
</strong></p>
<p>
{% trans "Please do not perform any real purchases as your order might be deleted without notice." %}
</p>
{% if request.now_dt_is_fake %}
<p>
{% blocktrans trimmed with datetime=request.now_dt|date:"SHORT_DATETIME_FORMAT" %}
You are currently using the time machine. The ticket shop is rendered as if it were {{ datetime }}.
{% endblocktrans %}
<a href="{% eventurl event "presale:event.timemachine" %}"><span class="fa fa-clock-o" aria-hidden="true"></span>{% trans "Change" %}</a>
</p>
{% elif request.user.is_authenticated or request.event_access_user.is_authenticated %}
<p>
{% eventurl event "presale:event.timemachine" as time_machine_link %}
{% blocktrans trimmed with time_machine_link=time_machine_link %}
To view your shop at different points in time, you can enable
<a href="{{ time_machine_link }}"><span class="fa fa-clock-o" aria-hidden="true"></span>time machine</a>.
{% endblocktrans %}
</p>
{% elif request.event_domain or request.organizer_domain %}
<p>
{% absmainurl "control:event.transfer_session" event=event.slug organizer=event.organizer.slug as transfer_session_link %}
{% eventurl event "presale:event.timemachine" as time_machine_link %}
{% with time_machine_link_encoded=time_machine_link|urlencode %}
{% blocktrans trimmed with time_machine_link=transfer_session_link|add:"?next="|add:time_machine_link_encoded %}
To view your shop at different points in time, you can enable
<a href="{{ time_machine_link }}"><span class="fa fa-clock-o" aria-hidden="true"></span>time machine</a>.
{% endblocktrans %}
{% endwith %}
</p>
{% endif %}
</div>
{% else %}
<div class="alert alert-danger">
@@ -122,6 +153,8 @@
</strong></p>
</div>
{% endif %}
{% endif %}
{% if messages %}
{% for message in messages %}
@@ -152,9 +185,13 @@
{% if request.event.testmode %}
{% if request.sales_channel.testmode_supported %}
<div class="alert alert-testmode alert-warning">
<p><strong><span class="sr-only">{% trans "Warning" context "alert-messages" %}:</span>
{% trans "This ticket shop is currently in test mode. Please do not perform any real purchases as your order might be deleted without notice." %}
<p><strong>
<span class="sr-only">{% trans "Warning" context "alert-messages" %}:</span>
{% trans "This ticket shop is currently in test mode." %}
</strong></p>
<p>
{% trans "Please do not perform any real purchases as your order might be deleted without notice." %}
</p>
</div>
{% else %}
<div class="alert alert-testmode alert-danger">

View File

@@ -0,0 +1,47 @@
{% extends "pretixpresale/event/base.html" %}
{% load i18n %}
{% load l10n %}
{% load money %}
{% load eventurl %}
{% load eventsignal %}
{% load thumb %}
{% load rich_text %}
{% load bootstrap3 %}
{% block title %}{% trans "Time machine" %}{% endblock %}
{% block content %}
<div class="panel {% if request.session.timemachine_now_dt %}panel-success{% else %}panel-default{% endif %}">
<div class="panel-heading">
{% trans "Time machine" %}
</div>
<div class="panel-body">
<form action="" method="post" class="">
{% csrf_token %}
{% bootstrap_form_errors timemachine_form "all" %}
<p>{% trans "Test your shop as if it were a different date and time." %}</p>
<div class="row">
<div class="col-md-6">
{% bootstrap_field timemachine_form.now_dt layout="inline" show_label=False %}
</div>
<div class="col-md-6 text-right">
<button type="submit" class="btn btn-primary btn-lg btn-save">
{% if request.session.timemachine_now_dt %}{% trans "Change" %}{% else %}{% trans "Enable time machine" %}{% endif %}
</button>
{% if request.session.timemachine_now_dt %}
<button form="disable_form" type="submit" class="btn btn-default btn-lg btn-save">
{% trans "Disable" %}
</button>
{% endif %}
</div>
</div>
</form>
<form action="" method="post" class="" id="disable_form">
{% csrf_token %}
<input type="hidden" name="timemachine_disable" value="true">
</form>
<div class="clear"></div>
</div>
</div>
{% endblock %}