mirror of https://gitlab.crans.org/bde/nk20
Merge branch 'explicit>implicit' into 'master'
Explicit>implicit See merge request bde/nk20!75
This commit is contained in:
commit
161d2ceed7
|
@ -104,6 +104,12 @@ class Activity(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Entry(models.Model):
|
class Entry(models.Model):
|
||||||
|
"""
|
||||||
|
Register the entry of someone:
|
||||||
|
- a member with a :model:`note.NoteUser`
|
||||||
|
- or a :model:`activity.Guest`
|
||||||
|
In the case of a Guest Entry, the inviter note is also save.
|
||||||
|
"""
|
||||||
activity = models.ForeignKey(
|
activity = models.ForeignKey(
|
||||||
Activity,
|
Activity,
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
|
@ -133,8 +139,7 @@ class Entry(models.Model):
|
||||||
verbose_name = _("entry")
|
verbose_name = _("entry")
|
||||||
verbose_name_plural = _("entries")
|
verbose_name_plural = _("entries")
|
||||||
|
|
||||||
def save(self, force_insert=False, force_update=False, using=None,
|
def save(self, *args,**kwargs):
|
||||||
update_fields=None):
|
|
||||||
|
|
||||||
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)
|
qs = Entry.objects.filter(~Q(pk=self.pk), activity=self.activity, note=self.note, guest=self.guest)
|
||||||
if qs.exists():
|
if qs.exists():
|
||||||
|
@ -148,7 +153,7 @@ class Entry(models.Model):
|
||||||
if self.note.balance < 0:
|
if self.note.balance < 0:
|
||||||
raise ValidationError(_("The balance is negative."))
|
raise ValidationError(_("The balance is negative."))
|
||||||
|
|
||||||
ret = super().save(force_insert, force_update, using, update_fields)
|
ret = super().save(*args,**kwargs)
|
||||||
|
|
||||||
if insert and self.guest:
|
if insert and self.guest:
|
||||||
GuestTransaction.objects.create(
|
GuestTransaction.objects.create(
|
||||||
|
|
|
@ -40,15 +40,15 @@ class ActivityListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView
|
||||||
return super().get_queryset().reverse()
|
return super().get_queryset().reverse()
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
ctx['title'] = _("Activities")
|
context['title'] = _("Activities")
|
||||||
|
|
||||||
upcoming_activities = Activity.objects.filter(date_end__gt=datetime.now())
|
upcoming_activities = Activity.objects.filter(date_end__gt=datetime.now())
|
||||||
ctx['upcoming'] = ActivityTable(data=upcoming_activities
|
context['upcoming'] = ActivityTable(data=upcoming_activities
|
||||||
.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view")))
|
.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view")))
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class ActivityDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
class ActivityDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||||
|
@ -56,15 +56,15 @@ class ActivityDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||||
context_object_name = "activity"
|
context_object_name = "activity"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data()
|
context = super().get_context_data()
|
||||||
|
|
||||||
table = GuestTable(data=Guest.objects.filter(activity=self.object)
|
table = GuestTable(data=Guest.objects.filter(activity=self.object)
|
||||||
.filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view")))
|
.filter(PermissionBackend.filter_queryset(self.request.user, Guest, "view")))
|
||||||
ctx["guests"] = table
|
context["guests"] = table
|
||||||
|
|
||||||
ctx["activity_started"] = datetime.now(timezone.utc) > self.object.date_start
|
context["activity_started"] = datetime.now(timezone.utc) > self.object.date_start
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class ActivityUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
class ActivityUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
@ -99,11 +99,11 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
||||||
template_name = "activity/activity_entry.html"
|
template_name = "activity/activity_entry.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
activity = Activity.objects.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view"))\
|
activity = Activity.objects.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view"))\
|
||||||
.get(pk=self.kwargs["pk"])
|
.get(pk=self.kwargs["pk"])
|
||||||
ctx["activity"] = activity
|
context["activity"] = activity
|
||||||
|
|
||||||
matched = []
|
matched = []
|
||||||
|
|
||||||
|
@ -146,16 +146,16 @@ class ActivityEntryView(LoginRequiredMixin, TemplateView):
|
||||||
matched.append(note)
|
matched.append(note)
|
||||||
|
|
||||||
table = EntryTable(data=matched)
|
table = EntryTable(data=matched)
|
||||||
ctx["table"] = table
|
context["table"] = table
|
||||||
|
|
||||||
ctx["entries"] = Entry.objects.filter(activity=activity)
|
context["entries"] = Entry.objects.filter(activity=activity)
|
||||||
|
|
||||||
ctx["title"] = _('Entry for activity "{}"').format(activity.name)
|
context["title"] = _('Entry for activity "{}"').format(activity.name)
|
||||||
ctx["noteuser_ctype"] = ContentType.objects.get_for_model(NoteUser).pk
|
context["noteuser_ctype"] = ContentType.objects.get_for_model(NoteUser).pk
|
||||||
ctx["notespecial_ctype"] = ContentType.objects.get_for_model(NoteSpecial).pk
|
context["notespecial_ctype"] = ContentType.objects.get_for_model(NoteSpecial).pk
|
||||||
|
|
||||||
ctx["activities_open"] = Activity.objects.filter(open=True).filter(
|
context["activities_open"] = Activity.objects.filter(open=True).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Activity, "view")).filter(
|
PermissionBackend.filter_queryset(self.request.user, Activity, "view")).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Activity, "change")).all()
|
PermissionBackend.filter_queryset(self.request.user, Activity, "change")).all()
|
||||||
|
|
||||||
return ctx
|
return context
|
|
@ -201,14 +201,14 @@ class RemittanceCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView)
|
||||||
return reverse_lazy('treasury:remittance_list')
|
return reverse_lazy('treasury:remittance_list')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
ctx["table"] = RemittanceTable(data=Remittance.objects
|
context["table"] = RemittanceTable(data=Remittance.objects
|
||||||
.filter(PermissionBackend.filter_queryset(self.request.user, Remittance, "view"))
|
.filter(PermissionBackend.filter_queryset(self.request.user, Remittance, "view"))
|
||||||
.all())
|
.all())
|
||||||
ctx["special_transactions"] = SpecialTransactionTable(data=SpecialTransaction.objects.none())
|
context["special_transactions"] = SpecialTransactionTable(data=SpecialTransaction.objects.none())
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class RemittanceListView(LoginRequiredMixin, TemplateView):
|
class RemittanceListView(LoginRequiredMixin, TemplateView):
|
||||||
|
@ -218,27 +218,27 @@ class RemittanceListView(LoginRequiredMixin, TemplateView):
|
||||||
template_name = "treasury/remittance_list.html"
|
template_name = "treasury/remittance_list.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
ctx["opened_remittances"] = RemittanceTable(
|
context["opened_remittances"] = RemittanceTable(
|
||||||
data=Remittance.objects.filter(closed=False).filter(
|
data=Remittance.objects.filter(closed=False).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
|
||||||
ctx["closed_remittances"] = RemittanceTable(
|
context["closed_remittances"] = RemittanceTable(
|
||||||
data=Remittance.objects.filter(closed=True).filter(
|
data=Remittance.objects.filter(closed=True).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).reverse().all())
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).reverse().all())
|
||||||
|
|
||||||
ctx["special_transactions_no_remittance"] = SpecialTransactionTable(
|
context["special_transactions_no_remittance"] = SpecialTransactionTable(
|
||||||
data=SpecialTransaction.objects.filter(source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
|
data=SpecialTransaction.objects.filter(source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
|
||||||
specialtransactionproxy__remittance=None).filter(
|
specialtransactionproxy__remittance=None).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
|
||||||
exclude=('remittance_remove', ))
|
exclude=('remittance_remove', ))
|
||||||
ctx["special_transactions_with_remittance"] = SpecialTransactionTable(
|
context["special_transactions_with_remittance"] = SpecialTransactionTable(
|
||||||
data=SpecialTransaction.objects.filter(source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
|
data=SpecialTransaction.objects.filter(source__in=NoteSpecial.objects.filter(~Q(remittancetype=None)),
|
||||||
specialtransactionproxy__remittance__closed=False).filter(
|
specialtransactionproxy__remittance__closed=False).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
|
||||||
exclude=('remittance_add', ))
|
exclude=('remittance_add', ))
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class RemittanceUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
class RemittanceUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
@ -252,17 +252,17 @@ class RemittanceUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView)
|
||||||
return reverse_lazy('treasury:remittance_list')
|
return reverse_lazy('treasury:remittance_list')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
ctx["table"] = RemittanceTable(data=Remittance.objects.filter(
|
context["table"] = RemittanceTable(data=Remittance.objects.filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
|
||||||
data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).filter(
|
data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).filter(
|
||||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all()
|
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all()
|
||||||
ctx["special_transactions"] = SpecialTransactionTable(
|
context["special_transactions"] = SpecialTransactionTable(
|
||||||
data=data,
|
data=data,
|
||||||
exclude=('remittance_add', 'remittance_remove', ) if self.object.closed else ('remittance_add', ))
|
exclude=('remittance_add', 'remittance_remove', ) if self.object.closed else ('remittance_add', ))
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class LinkTransactionToRemittanceView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
class LinkTransactionToRemittanceView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
@ -277,9 +277,9 @@ class LinkTransactionToRemittanceView(ProtectQuerysetMixin, LoginRequiredMixin,
|
||||||
return reverse_lazy('treasury:remittance_list')
|
return reverse_lazy('treasury:remittance_list')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
form = ctx["form"]
|
form = context["form"]
|
||||||
form.fields["last_name"].initial = self.object.transaction.last_name
|
form.fields["last_name"].initial = self.object.transaction.last_name
|
||||||
form.fields["first_name"].initial = self.object.transaction.first_name
|
form.fields["first_name"].initial = self.object.transaction.first_name
|
||||||
form.fields["bank"].initial = self.object.transaction.bank
|
form.fields["bank"].initial = self.object.transaction.bank
|
||||||
|
@ -287,7 +287,7 @@ class LinkTransactionToRemittanceView(ProtectQuerysetMixin, LoginRequiredMixin,
|
||||||
form.fields["remittance"].queryset = form.fields["remittance"] \
|
form.fields["remittance"].queryset = form.fields["remittance"] \
|
||||||
.queryset.filter(remittance_type__note=self.object.transaction.source)
|
.queryset.filter(remittance_type__note=self.object.transaction.source)
|
||||||
|
|
||||||
return ctx
|
return context
|
||||||
|
|
||||||
|
|
||||||
class UnlinkTransactionToRemittanceView(LoginRequiredMixin, View):
|
class UnlinkTransactionToRemittanceView(LoginRequiredMixin, View):
|
||||||
|
|
Loading…
Reference in New Issue