mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
Add a read-only view for quotas
This commit is contained in:
@@ -1,91 +1,57 @@
|
||||
{% extends "pretixcontrol/items/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% block title %}{% trans "Quota" %}{% endblock %}
|
||||
{% block title %}{% blocktrans with name=quota.name %}Quota: {{ name }}{% endblocktrans %}{% endblock %}
|
||||
{% block inside %}
|
||||
<h1>{% trans "Quota" %}</h1>
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 {% if quota.pk and quota.size != None %}col-lg-9{% else %}col-lg-12{% endif %}">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_errors form %}
|
||||
<fieldset>
|
||||
<legend>{% trans "General information" %}</legend>
|
||||
{% bootstrap_field form.name layout="horizontal" %}
|
||||
{% bootstrap_field form.size layout="horizontal" %}
|
||||
<legend>{% trans "Items" %}</legend>
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
Please select the products or product variations this quota should be applied to. If you apply two
|
||||
quotas to the same product, it will only be available if
|
||||
<strong>both</strong> quotas have capacity
|
||||
left.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
<div class="panel-group items-on-quota">
|
||||
{% for item in items %}
|
||||
<div class="panel panel-default" data-formset-form>
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion"
|
||||
href="#collapse{{ item.id }}">
|
||||
{{ item.name }}
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapse{{ item.id }}" class="panel-collapse collapse in">
|
||||
<div class="panel-body">
|
||||
<div class="form-horizontal">
|
||||
{% bootstrap_field item.field layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<h1>
|
||||
{% blocktrans with name=quota.name %}Quota: {{ name }}{% endblocktrans %}
|
||||
{% if request.eventperm.can_change_quotas %}
|
||||
<a href="{% url "control:event.items.quotas.edit" event=request.event.slug organizer=request.event.organizer.slug quota=quota.pk %}"
|
||||
class="btn btn-default">
|
||||
<span class="fa fa-edit"></span>
|
||||
{% trans "Edit quota" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</h1>
|
||||
<div class="row" id="quota-stats">
|
||||
<div class="col-md-6 col-xs-12">
|
||||
<legend>{% trans "Usage overview" %}</legend>
|
||||
<div class="chart" id="quota_chart">
|
||||
|
||||
</div>
|
||||
{% if quota.pk and quota.size != None %}
|
||||
<div class="col-xs-12 col-lg-3" id="quota-stats">
|
||||
<fieldset>
|
||||
<legend>{% trans "Availability calculation" %}</legend>
|
||||
<div class="chart" id="quota_chart">
|
||||
<script type="application/json" id="quota-chart-data">{{ quota_chart_data|safe }}</script>
|
||||
</div>
|
||||
<div class="col-md-6 col-xs-12">
|
||||
<legend>{% trans "Availability calculation" %}</legend>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Total quota" %}</div>
|
||||
<div class="col-xs-3 text-right">{{ quota.size }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Paid orders" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_paid_orders }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Pending orders" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_pending_orders }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Vouchers" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_blocking_vouchers }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Current user's carts" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_in_cart }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9"><strong>{% trans "Current availability" %}</strong></div>
|
||||
<div class="col-xs-3 text-right"><strong>{{ quota.availability.1 }}</strong></div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Total quota" %}</div>
|
||||
<div class="col-xs-3 text-right">
|
||||
{% if quota.size == None %}{% trans "Infinite" %}{% else %}{{ quota.size }}{% endif %}
|
||||
</div>
|
||||
<script type="application/json" id="quota-chart-data">{{ quota_chart_data|safe }}</script>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Paid orders" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_paid_orders }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Pending orders" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_pending_orders }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Vouchers" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_blocking_vouchers }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9">{% trans "Current user's carts" %}</div>
|
||||
<div class="col-xs-3 text-right"> – {{ quota.count_in_cart }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-9"><strong>{% trans "Current availability" %}</strong></div>
|
||||
<div class="col-xs-3 text-right">
|
||||
{% if quota.size == None %}{% trans "Infinite" %}{% else %}{{ quota.availability.1 }}{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
{% extends "pretixcontrol/items/base.html" %}
|
||||
{% load i18n %}
|
||||
{% load bootstrap3 %}
|
||||
{% block title %}
|
||||
{% if question %}
|
||||
{% blocktrans with name=quota.name %}Quota: {{ name }}{% endblocktrans %}
|
||||
{% else %}
|
||||
{% trans "Quota" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block inside %}
|
||||
{% if question %}
|
||||
<h1>{% blocktrans with name=quota.name %}Quota: {{ name }}{% endblocktrans %}</h1>
|
||||
{% else %}
|
||||
<h1>{% trans "Quota" %}</h1>
|
||||
{% endif %}
|
||||
<form action="" method="post" class="form-horizontal">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form_errors form %}
|
||||
<fieldset>
|
||||
<legend>{% trans "General information" %}</legend>
|
||||
{% bootstrap_field form.name layout="horizontal" %}
|
||||
{% bootstrap_field form.size layout="horizontal" %}
|
||||
<legend>{% trans "Items" %}</legend>
|
||||
<p>
|
||||
{% blocktrans trimmed %}
|
||||
Please select the products or product variations this quota should be applied to. If you apply two
|
||||
quotas to the same product, it will only be available if
|
||||
<strong>both</strong> quotas have capacity
|
||||
left.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
<div class="panel-group items-on-quota">
|
||||
{% for item in items %}
|
||||
<div class="panel panel-default" data-formset-form>
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion"
|
||||
href="#collapse{{ item.id }}">
|
||||
{{ item.name }}
|
||||
</a>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="collapse{{ item.id }}" class="panel-collapse collapse in">
|
||||
<div class="panel-body">
|
||||
<div class="form-horizontal">
|
||||
{% bootstrap_field item.field layout="horizontal" %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="form-group submit-group">
|
||||
<button type="submit" class="btn btn-primary btn-save">
|
||||
{% trans "Save" %}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -43,20 +43,19 @@
|
||||
{% for q in quotas %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong><a href="{% url "control:event.items.quotas.edit" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}">{{ q.name }}</a></strong>
|
||||
<strong><a href="{% url "control:event.items.quotas.show" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}">{{ q.name }}</a></strong>
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for item in q.items.all %}
|
||||
<li><a href="
|
||||
{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=item.id %}"
|
||||
>{{ item.name }}</a></li>
|
||||
<li><a href="{% url "control:event.item" organizer=request.event.organizer.slug event=request.event.slug item=item.id %}">{{ item.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td>{% if q.size == None %}Unlimited{% else %}{{ q.size }}{% endif %}</td>
|
||||
<td>{% include "pretixcontrol/items/fragment_quota_availability.html" with availability=q.availability %}</td>
|
||||
<td class="text-right">
|
||||
<a href="{% url "control:event.items.quotas.edit" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
|
||||
<a href="{% url "control:event.items.quotas.delete" organizer=request.event.organizer.slug event=request.event.slug quota=q.id %}" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -59,7 +59,8 @@ urlpatterns = [
|
||||
name='event.items.questions.edit'),
|
||||
url(r'^questions/add$', item.QuestionCreate.as_view(), name='event.items.questions.add'),
|
||||
url(r'^quotas/$', item.QuotaList.as_view(), name='event.items.quotas'),
|
||||
url(r'^quotas/(?P<quota>\d+)/$', item.QuotaUpdate.as_view(), name='event.items.quotas.edit'),
|
||||
url(r'^quotas/(?P<quota>\d+)/$', item.QuotaView.as_view(), name='event.items.quotas.show'),
|
||||
url(r'^quotas/(?P<quota>\d+)/change$', item.QuotaUpdate.as_view(), name='event.items.quotas.edit'),
|
||||
url(r'^quotas/(?P<quota>\d+)/delete$', item.QuotaDelete.as_view(),
|
||||
name='event.items.quotas.delete'),
|
||||
url(r'^quotas/add$', item.QuotaCreate.as_view(), name='event.items.quotas.add'),
|
||||
|
||||
@@ -89,7 +89,7 @@ def quota_widgets(sender, **kwargs):
|
||||
text=_('{quota} left').format(quota=q.name)),
|
||||
'width': 3,
|
||||
'priority': 50,
|
||||
'url': reverse('control:event.items.quotas.edit', kwargs={
|
||||
'url': reverse('control:event.items.quotas.show', kwargs={
|
||||
'event': sender.slug,
|
||||
'organizer': sender.organizer.slug,
|
||||
'quota': q.id
|
||||
|
||||
@@ -572,7 +572,7 @@ class QuotaEditorMixin:
|
||||
class QuotaCreate(EventPermissionRequiredMixin, QuotaEditorMixin, CreateView):
|
||||
model = Quota
|
||||
form_class = QuotaForm
|
||||
template_name = 'pretixcontrol/items/quota.html'
|
||||
template_name = 'pretixcontrol/items/quota_edit.html'
|
||||
permission = 'can_change_items'
|
||||
context_object_name = 'quota'
|
||||
|
||||
@@ -591,16 +591,14 @@ class QuotaCreate(EventPermissionRequiredMixin, QuotaEditorMixin, CreateView):
|
||||
return ret
|
||||
|
||||
|
||||
class QuotaUpdate(EventPermissionRequiredMixin, QuotaEditorMixin, ChartContainingView, UpdateView):
|
||||
class QuotaView(ChartContainingView, DetailView):
|
||||
model = Quota
|
||||
form_class = QuotaForm
|
||||
template_name = 'pretixcontrol/items/quota.html'
|
||||
permission = 'can_change_items'
|
||||
context_object_name = 'quota'
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
ctx = super().get_context_data()
|
||||
ctx['quota_chart_data'] = json.dumps([
|
||||
data = [
|
||||
{
|
||||
'label': ugettext('Paid orders'),
|
||||
'value': self.object.count_paid_orders()
|
||||
@@ -616,12 +614,34 @@ class QuotaUpdate(EventPermissionRequiredMixin, QuotaEditorMixin, ChartContainin
|
||||
{
|
||||
'label': ugettext('Current user\'s carts'),
|
||||
'value': self.object.count_in_cart()
|
||||
},
|
||||
{
|
||||
}
|
||||
]
|
||||
if self.object.size is not None:
|
||||
data.append({
|
||||
'label': ugettext('Current availability'),
|
||||
'value': self.object.availability()[1]
|
||||
}
|
||||
])
|
||||
})
|
||||
ctx['quota_chart_data'] = json.dumps(data)
|
||||
return ctx
|
||||
|
||||
def get_object(self, queryset=None) -> Quota:
|
||||
try:
|
||||
return self.request.event.quotas.get(
|
||||
id=self.kwargs['quota']
|
||||
)
|
||||
except Quota.DoesNotExist:
|
||||
raise Http404(_("The requested quota does not exist."))
|
||||
|
||||
|
||||
class QuotaUpdate(EventPermissionRequiredMixin, QuotaEditorMixin, UpdateView):
|
||||
model = Quota
|
||||
form_class = QuotaForm
|
||||
template_name = 'pretixcontrol/items/quota_edit.html'
|
||||
permission = 'can_change_items'
|
||||
context_object_name = 'quota'
|
||||
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
ctx = super().get_context_data()
|
||||
return ctx
|
||||
|
||||
def get_object(self, queryset=None) -> Quota:
|
||||
|
||||
Reference in New Issue
Block a user