Enforce capitalization of class / session status
This commit is contained in:
@@ -242,12 +242,12 @@ class CardSerializer(serializers.ModelSerializer):
|
||||
|
||||
class TrainingSerializer(serializers.ModelSerializer):
|
||||
attendance_status = serializers.ChoiceField([
|
||||
'waiting for payment',
|
||||
'withdrawn',
|
||||
'rescheduled',
|
||||
'no-show',
|
||||
'attended',
|
||||
'confirmed'
|
||||
'Waiting for payment',
|
||||
'Withdrawn',
|
||||
'Rescheduled',
|
||||
'No-show',
|
||||
'Attended',
|
||||
'Confirmed'
|
||||
])
|
||||
session = serializers.PrimaryKeyRelatedField(queryset=models.Session.objects.all())
|
||||
student_name = serializers.SerializerMethodField()
|
||||
@@ -266,7 +266,7 @@ class TrainingSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class StudentTrainingSerializer(TrainingSerializer):
|
||||
attendance_status = serializers.ChoiceField(['waiting for payment', 'withdrawn'])
|
||||
attendance_status = serializers.ChoiceField(['Waiting for payment', 'Withdrawn'])
|
||||
|
||||
|
||||
class SessionSerializer(serializers.ModelSerializer):
|
||||
@@ -283,7 +283,7 @@ class SessionSerializer(serializers.ModelSerializer):
|
||||
read_only_fields = ['old_instructor', 'instructor']
|
||||
|
||||
def get_student_count(self, obj):
|
||||
return len([x for x in obj.students.all() if x.attendance_status != 'withdrawn'])
|
||||
return len([x for x in obj.students.all() if x.attendance_status != 'Withdrawn'])
|
||||
|
||||
def get_course_name(self, obj):
|
||||
return obj.course.name
|
||||
|
@@ -183,6 +183,7 @@ class TrainingViewSet(Base, Retrieve, Create, Update):
|
||||
return serializers.StudentTrainingSerializer
|
||||
|
||||
# TODO: turn these into @actions
|
||||
# TODO: check if full
|
||||
def perform_create(self, serializer):
|
||||
session_id = self.request.data['session']
|
||||
status = self.request.data['attendance_status']
|
||||
@@ -192,16 +193,16 @@ class TrainingViewSet(Base, Retrieve, Create, Update):
|
||||
raise exceptions.ValidationError('You have already registered')
|
||||
if self.request.user == session.instructor:
|
||||
raise exceptions.ValidationError('You are teaching this session')
|
||||
if status == 'waiting for payment' and session.cost == 0:
|
||||
status = 'confirmed'
|
||||
if status == 'Waiting for payment' and session.cost == 0:
|
||||
status = 'Confirmed'
|
||||
serializer.save(user=self.request.user, attendance_status=status)
|
||||
|
||||
def perform_update(self, serializer):
|
||||
session_id = self.request.data['session']
|
||||
status = self.request.data['attendance_status']
|
||||
session = get_object_or_404(models.Session, id=session_id)
|
||||
if status == 'waiting for payment' and session.cost == 0:
|
||||
status = 'confirmed'
|
||||
if status == 'Waiting for payment' and session.cost == 0:
|
||||
status = 'Confirmed'
|
||||
serializer.save(attendance_status=status)
|
||||
|
||||
|
||||
|
@@ -160,7 +160,7 @@ Full User
|
||||
"instructor": null
|
||||
},
|
||||
"member_id": 1685,
|
||||
"attendance_status": "confirmed",
|
||||
"attendance_status": "Confirmed",
|
||||
"sign_up_date": null,
|
||||
"paid_date": null
|
||||
}
|
||||
@@ -530,7 +530,7 @@ Reported Transactions
|
||||
Create Transaction
|
||||
++++++++++++++++++
|
||||
|
||||
.. http:post:: /transaction/
|
||||
.. http:post:: /transactions/
|
||||
|
||||
Add a transaction to a member. Admins only.
|
||||
|
||||
@@ -764,7 +764,7 @@ Training
|
||||
|
||||
{
|
||||
"id": 971,
|
||||
"attendance_status": "confirmed",
|
||||
"attendance_status": "Confirmed",
|
||||
"session": 11073,
|
||||
"student_name": "Tanner Collin",
|
||||
"member_id": 1685,
|
||||
@@ -779,13 +779,13 @@ Training
|
||||
|
||||
**Users**
|
||||
|
||||
:json attendance_status: One of: ``waiting for payment``, ``withdrawn``
|
||||
:json attendance_status: One of: ``Waiting for payment``, ``Withdrawn``
|
||||
:json int session: The session (class) to register for.
|
||||
|
||||
**Instructors and Admins**
|
||||
|
||||
:json attendance_status: One of: ``waiting for payment``, ``withdrawn``,
|
||||
``rescheduled``, ``no-show``, ``attended``, ``confirmed``
|
||||
:json attendance_status: One of: ``Waiting for payment``, ``Withdrawn``,
|
||||
``Rescheduled``, ``No-show``, ``Attended``, ``Confirmed``
|
||||
:json int session: The session (class) to register for.
|
||||
|
||||
:requestheader Authorization: ``Token <token>``
|
||||
|
@@ -70,7 +70,7 @@ TRAINING_FIELDS = [
|
||||
'id',
|
||||
# class_session_id -> session
|
||||
'member_id',
|
||||
'attendance_status',
|
||||
# attendance_status -> capitalize
|
||||
'sign_up_date',
|
||||
'paid_date',
|
||||
]
|
||||
@@ -239,6 +239,7 @@ for o in old:
|
||||
for f in TRAINING_FIELDS:
|
||||
new[f] = o.__dict__.get(f, None)
|
||||
new['session'] = models.Session.objects.get(id=o.class_session_id)
|
||||
new['attendance_status'] = o.attendance_status.capitalize()
|
||||
|
||||
models.Training.objects.create(**new)
|
||||
print('Imported training #{} - {} {}'.format(
|
||||
|
Reference in New Issue
Block a user