change flow for subscription
This commit is contained in:
parent
b73b96dba9
commit
bc890cc49b
|
@ -24,10 +24,6 @@
|
|||
{% trans 'Subscription' %}
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'lot:unsubscription' object.id %}" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-tag"></i>
|
||||
{% trans 'Unsubscription' %}
|
||||
</a>
|
||||
{% if donor %}
|
||||
<a href="{% url 'lot:del_donor' object.id %}" type="button" class="btn btn-green-admin">
|
||||
<i class="bi bi-tag"></i>
|
||||
|
|
21
lot/forms.py
21
lot/forms.py
|
@ -54,6 +54,14 @@ class LotSubscriptionForm(forms.Form):
|
|||
if self._user and self._user.institution != self.institution:
|
||||
txt = _("This user is from another institution")
|
||||
raise ValidationError(txt)
|
||||
slot = LotSubscription.objects.filter(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
)
|
||||
if slot:
|
||||
txt = _("This user is already subscripted")
|
||||
raise ValidationError(txt)
|
||||
|
||||
return
|
||||
|
||||
def save(self, commit=True):
|
||||
|
@ -72,7 +80,8 @@ class LotSubscriptionForm(forms.Form):
|
|||
slot = LotSubscription.objects.filter(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_circuit_manager=True
|
||||
type=LotSubscription.Type.CIRCUIT_MANAGER
|
||||
|
||||
)
|
||||
if slot:
|
||||
return
|
||||
|
@ -80,14 +89,14 @@ class LotSubscriptionForm(forms.Form):
|
|||
LotSubscription.objects.create(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_circuit_manager=True
|
||||
type=LotSubscription.Type.CIRCUIT_MANAGER
|
||||
)
|
||||
|
||||
if self._type == "shop":
|
||||
slot = LotSubscription.objects.filter(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_shop=True
|
||||
type=LotSubscription.Type.SHOP
|
||||
)
|
||||
if slot:
|
||||
return
|
||||
|
@ -95,7 +104,7 @@ class LotSubscriptionForm(forms.Form):
|
|||
LotSubscription.objects.create(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_shop=True
|
||||
type=LotSubscription.Type.SHOP
|
||||
)
|
||||
|
||||
def remove(self):
|
||||
|
@ -106,14 +115,14 @@ class LotSubscriptionForm(forms.Form):
|
|||
lot_subscription = LotSubscription.objects.filter(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_circuit_manager=True
|
||||
type=LotSubscription.Type.CIRCUIT_MANAGER
|
||||
)
|
||||
|
||||
elif self._type == "shop":
|
||||
lot_subscription = LotSubscription.objects.filter(
|
||||
user=self._user,
|
||||
lot_id=self.lot_pk,
|
||||
is_circuit_manager=True
|
||||
type=LotSubscription.Type.SHOP
|
||||
)
|
||||
|
||||
else:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 5.0.6 on 2025-03-10 16:29
|
||||
# Generated by Django 5.0.6 on 2025-03-11 10:55
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
@ -55,12 +55,11 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
),
|
||||
(
|
||||
"is_circuit_manager",
|
||||
models.BooleanField(
|
||||
default=False, verbose_name="is circuit manager"
|
||||
"type",
|
||||
models.SmallIntegerField(
|
||||
choices=[(0, "Circuit Manager"), (1, "Shop")]
|
||||
),
|
||||
),
|
||||
("is_shop", models.BooleanField(default=False, verbose_name="is shop")),
|
||||
(
|
||||
"lot",
|
||||
models.ForeignKey(
|
||||
|
|
|
@ -64,10 +64,13 @@ class LotProperty(Property):
|
|||
|
||||
|
||||
class LotSubscription(models.Model):
|
||||
class Type(models.IntegerChoices):
|
||||
CIRCUIT_MANAGER = 0, _("Circuit Manager")
|
||||
SHOP = 1, _("Shop")
|
||||
|
||||
lot = models.ForeignKey(Lot, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, null=False, blank=False)
|
||||
is_circuit_manager = models.BooleanField(_("is circuit manager"), default=False)
|
||||
is_shop = models.BooleanField(_("is shop"), default=False)
|
||||
type = models.SmallIntegerField(choices=Type.choices)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
|
@ -75,6 +78,14 @@ class LotSubscription(models.Model):
|
|||
fields=["lot", "user"], name="unique_lot_user")
|
||||
]
|
||||
|
||||
@property
|
||||
def is_circuit_manager(self):
|
||||
return self.type == self.Type.CIRCUIT_MANAGER
|
||||
|
||||
@property
|
||||
def is_shop(self):
|
||||
return self.type == self.Type.SHOP
|
||||
|
||||
|
||||
class Donor(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
|
|
|
@ -8,25 +8,64 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
{% if subscriptors %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<table class="table table-hover table-bordered align-middel">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th scope="col">Email</th>
|
||||
<th scope="col">Type</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for s in subscriptors %}
|
||||
<tr>
|
||||
<td class="font-monospace">{{ s.user.email }}</td>
|
||||
<td class="font-monospace">{{ s.get_type_display }}</td>
|
||||
<td class="font-monospace">
|
||||
<a href="{% url 'lot:unsubscription' lot.id s.id %}">
|
||||
{% trans 'Unsubscription' %}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'dashboard:lot' lot.id %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{{ action }}" />
|
||||
</div>
|
||||
|
||||
</form>
|
||||
<div class="mt-4">
|
||||
<button class="btn btn-green-admin" type="button" data-bs-toggle="collapse" data-bs-target="#subscribe">
|
||||
{% trans 'Add subscription' %}
|
||||
</button>
|
||||
|
||||
<div class="collapse mt-3" id="subscribe">
|
||||
<div class="card card-body">
|
||||
{% trans 'Add an email and select a type of subscription for add a new user' %}.
|
||||
</div>
|
||||
{% load django_bootstrap5 %}
|
||||
<form role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
|
||||
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
|
||||
<div class="message">
|
||||
{% for field, error in form.errors.items %}
|
||||
{{ error }}<br />
|
||||
{% endfor %}
|
||||
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% bootstrap_form form %}
|
||||
<div class="form-actions-no-box">
|
||||
<a class="btn btn-grey" href="{% url 'dashboard:lot' lot.id %}">{% translate "Cancel" %}</a>
|
||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{{ action }}" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -15,7 +15,7 @@ urlpatterns = [
|
|||
path("<int:pk>/property/update", views.UpdateLotPropertyView.as_view(), name="update_property"),
|
||||
path("<int:pk>/property/delete", views.DeleteLotPropertyView.as_view(), name="delete_property"),
|
||||
path("<int:pk>/subscription/", views.SubscriptLotView.as_view(), name="subscription"),
|
||||
path("<int:pk>/unsubscription/", views.UnsubscriptLotView.as_view(), name="unsubscription"),
|
||||
path("<int:pk>/unsubscription/<int:id>", views.UnsubscriptLotView.as_view(), name="unsubscription"),
|
||||
path("<int:pk>/donor/add", views.AddDonorView.as_view(), name="add_donor"),
|
||||
path("<int:pk>/donor/del", views.DelDonorView.as_view(), name="del_donor"),
|
||||
path("<int:pk>/donor/<uuid:id>", views.DonorView.as_view(), name="web_donor"),
|
||||
|
|
44
lot/views.py
44
lot/views.py
|
@ -278,20 +278,24 @@ class DeleteLotPropertyView(DashboardView, DeleteView):
|
|||
return redirect(self.success_url)
|
||||
|
||||
|
||||
class SubscriptLotMixing(DashboardView, FormView):
|
||||
class SubscriptLotView(DashboardView, FormView):
|
||||
template_name = "subscription.html"
|
||||
title = _("Subscription")
|
||||
breadcrumb = "Lot / Subscription"
|
||||
form_class = LotSubscriptionForm
|
||||
lot = None
|
||||
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
self.pk = self.kwargs.get('pk')
|
||||
context = super().get_context_data(**kwargs)
|
||||
self.get_lot()
|
||||
subscriptors = []
|
||||
if self.request.user.is_admin:
|
||||
subscriptors = LotSubscription.objects.filter(lot=self.lot)
|
||||
|
||||
context.update({
|
||||
'lot': self.lot,
|
||||
'subscriptors': subscriptors,
|
||||
"action": _("Subscribe")
|
||||
})
|
||||
return context
|
||||
|
@ -311,28 +315,32 @@ class SubscriptLotMixing(DashboardView, FormView):
|
|||
id=self.pk
|
||||
)
|
||||
|
||||
|
||||
class SubscriptLotView(SubscriptLotMixing):
|
||||
|
||||
def form_valid(self, form):
|
||||
form.save()
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
|
||||
|
||||
class UnsubscriptLotView(SubscriptLotMixing):
|
||||
title = _("Unsubscription")
|
||||
breadcrumb = "Lot / Unsubscription"
|
||||
class UnsubscriptLotView(DashboardView, TemplateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["action"] = _("Unsubscribe")
|
||||
return context
|
||||
def get(self, *args, **kwargs):
|
||||
super().get(*args, **kwargs)
|
||||
pk = self.kwargs.get('pk')
|
||||
id = self.kwargs.get('id')
|
||||
self.success_url = reverse_lazy('lot:subscription', args=[pk])
|
||||
|
||||
def form_valid(self, form):
|
||||
form.remove()
|
||||
response = super().form_valid(form)
|
||||
return response
|
||||
self.object = get_object_or_404(
|
||||
LotSubscription,
|
||||
lot_id=pk,
|
||||
id=id
|
||||
)
|
||||
|
||||
if self.object.user == self.request.user or self.request.user.is_admin:
|
||||
self.object.delete()
|
||||
# TODO
|
||||
# self.send_email()
|
||||
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
||||
class DonorMixing(DashboardView, FormView):
|
||||
|
@ -363,7 +371,7 @@ class DonorMixing(DashboardView, FormView):
|
|||
self.get_donor()
|
||||
cmanager = LotSubscription.objects.filter(
|
||||
lot=self.lot,
|
||||
is_circuit_manager=True,
|
||||
type=LotSubscription.Type.CIRCUIT_MANAGER,
|
||||
user=self.request.user
|
||||
).first()
|
||||
|
||||
|
@ -463,9 +471,9 @@ class AcceptDonorView(TemplateView):
|
|||
|
||||
def get(self, *args, **kwargs):
|
||||
super().get(*args, **kwargs)
|
||||
self.success_url = reverse_lazy('lot:web_donor', args=[pk, id])
|
||||
pk = self.kwargs.get('pk')
|
||||
id = self.kwargs.get('id')
|
||||
self.success_url = reverse_lazy('lot:web_donor', args=[pk, id])
|
||||
|
||||
self.object = get_object_or_404(
|
||||
Donor,
|
||||
|
|
Loading…
Reference in a new issue