-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Free events with simplified registration
- Loading branch information
Showing
4 changed files
with
129 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
dds_registration/migrations/0007_event_free_alter_registration_option.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 5.0.3 on 2024-04-30 12:58 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dds_registration', '0006_message_subject'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='event', | ||
name='free', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name='registration', | ||
name='option', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='registrations', to='dds_registration.registrationoption'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
from django.http import Http404, HttpRequest | ||
from django.shortcuts import redirect, render | ||
|
||
from ..forms import RegistrationForm | ||
from ..forms import RegistrationForm, FreeRegistrationForm | ||
from ..models import Event, Payment, Registration, RegistrationOption | ||
|
||
# from .event_registration_cancel import ( | ||
|
@@ -39,82 +39,112 @@ def event_registration(request: HttpRequest, event_code: str): | |
return redirect("profile") | ||
|
||
if request.method == "POST": | ||
form = RegistrationForm( | ||
data=request.POST, | ||
option_choices=[(obj.id, obj.form_label) for obj in event.options.all()], | ||
) | ||
|
||
if form.is_valid(): | ||
option = RegistrationOption.objects.get(id=form.cleaned_data["option"]) | ||
if registration: | ||
# Set up new payment | ||
if registration.payment: | ||
registration.payment.mark_obsolete() | ||
registration.option = option | ||
registration.send_update_emails = form.cleaned_data["send_update_emails"] | ||
registration.status = "SUBMITTED" | ||
else: | ||
registration = Registration( | ||
event=event, | ||
status="SUBMITTED", | ||
user=request.user, | ||
send_update_emails=form.cleaned_data["send_update_emails"], | ||
option=option, | ||
) | ||
registration.save() | ||
|
||
if not registration.option.price: | ||
if event.free: | ||
form = FreeRegistrationForm( | ||
data=request.POST, | ||
) | ||
if form.is_valid(): | ||
if registration: | ||
# Set up new payment | ||
registration.send_update_emails = form.cleaned_data["send_update_emails"] | ||
registration.status = "SUBMITTED" | ||
else: | ||
registration = Registration( | ||
event=event, | ||
status="SUBMITTED", | ||
user=request.user, | ||
send_update_emails=form.cleaned_data["send_update_emails"], | ||
) | ||
registration.save() | ||
registration.complete_registration() | ||
messages.success(request, f"You have successfully registered for {event.title}.") | ||
return redirect("profile") | ||
else: | ||
form = RegistrationForm( | ||
data=request.POST, | ||
option_choices=[(obj.id, obj.form_label) for obj in event.options.all()], | ||
) | ||
|
||
registration.complete_registration() | ||
|
||
payment = Payment( | ||
status="CREATED", | ||
data={ | ||
"user": { | ||
"id": request.user.id, | ||
"name": form.cleaned_data["name"], | ||
"address": form.cleaned_data["address"], | ||
}, | ||
"extra": form.cleaned_data["extra"], | ||
"kind": "event", | ||
"method": form.cleaned_data["payment_method"], | ||
"event": { | ||
"id": event.id, | ||
"title": event.title, | ||
}, | ||
"registration": { | ||
"id": registration.id, | ||
}, | ||
"option": { | ||
"id": option.id, | ||
"item": option.item, | ||
if form.is_valid(): | ||
option = RegistrationOption.objects.get(id=form.cleaned_data["option"]) | ||
if registration: | ||
# Set up new payment | ||
if registration.payment: | ||
registration.payment.mark_obsolete() | ||
registration.option = option | ||
registration.send_update_emails = form.cleaned_data["send_update_emails"] | ||
registration.status = "SUBMITTED" | ||
else: | ||
registration = Registration( | ||
event=event, | ||
status="SUBMITTED", | ||
user=request.user, | ||
send_update_emails=form.cleaned_data["send_update_emails"], | ||
option=option, | ||
) | ||
registration.save() | ||
|
||
if not registration.option.price: | ||
messages.success(request, f"You have successfully registered for {event.title}.") | ||
return redirect("profile") | ||
|
||
registration.complete_registration() | ||
|
||
payment = Payment( | ||
status="CREATED", | ||
data={ | ||
"user": { | ||
"id": request.user.id, | ||
"name": form.cleaned_data["name"], | ||
"address": form.cleaned_data["address"], | ||
}, | ||
"extra": form.cleaned_data["extra"], | ||
"kind": "event", | ||
"method": form.cleaned_data["payment_method"], | ||
"event": { | ||
"id": event.id, | ||
"title": event.title, | ||
}, | ||
"registration": { | ||
"id": registration.id, | ||
}, | ||
"option": { | ||
"id": option.id, | ||
"item": option.item, | ||
}, | ||
"price": option.price, | ||
"currency": option.currency, | ||
}, | ||
"price": option.price, | ||
"currency": option.currency, | ||
) | ||
payment.save() | ||
|
||
registration.payment = payment | ||
registration.save() | ||
|
||
if payment.data["method"] == "INVOICE": | ||
payment.email_invoice() | ||
payment.status = "ISSUED" | ||
payment.save() | ||
messages.success( | ||
request, | ||
f"Your registration for {event.title} has been created! An invoice has been sent to {request.user.email} from [email protected]. The invoice can also be downloaded from your profile. Please note your registration is not in force until the invoice is paid.", | ||
) | ||
return redirect("profile") | ||
elif payment.data["method"] == "STRIPE": | ||
return redirect("payment_stripe", payment_id=payment.id) | ||
elif event.free: | ||
if registration: | ||
form = FreeRegistrationForm( | ||
initial={ | ||
"send_update_emails": registration.send_update_emails, | ||
}, | ||
) | ||
payment.save() | ||
|
||
registration.payment = payment | ||
registration.save() | ||
|
||
if payment.data["method"] == "INVOICE": | ||
payment.email_invoice() | ||
payment.status = "ISSUED" | ||
payment.save() | ||
messages.success( | ||
request, | ||
f"Your registration for {event.title} has been created! An invoice has been sent to {request.user.email} from [email protected]. The invoice can also be downloaded from your profile. Please note your registration is not in force until the invoice is paid.", | ||
) | ||
return redirect("profile") | ||
elif payment.data["method"] == "STRIPE": | ||
return redirect("payment_stripe", payment_id=payment.id) | ||
else: | ||
form = FreeRegistrationForm() | ||
else: | ||
# TODO: Populate template with existing choices instead of defaults | ||
if registration: | ||
# TODO: What to do if there no payment property in the registration object (as a result of a incosistency)? | ||
# TODO: What to do if there no payment property in the registration object (as a result of a inconsistency)? | ||
messages.success( | ||
request, | ||
"You are now editing an existing registration application. Please be careful not to make unwanted changes.", | ||
|