Enforce capitalization of class / session status
This commit is contained in:
parent
202dc1f999
commit
18e7c6c77d
|
@ -242,12 +242,12 @@ class CardSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class TrainingSerializer(serializers.ModelSerializer):
|
class TrainingSerializer(serializers.ModelSerializer):
|
||||||
attendance_status = serializers.ChoiceField([
|
attendance_status = serializers.ChoiceField([
|
||||||
'waiting for payment',
|
'Waiting for payment',
|
||||||
'withdrawn',
|
'Withdrawn',
|
||||||
'rescheduled',
|
'Rescheduled',
|
||||||
'no-show',
|
'No-show',
|
||||||
'attended',
|
'Attended',
|
||||||
'confirmed'
|
'Confirmed'
|
||||||
])
|
])
|
||||||
session = serializers.PrimaryKeyRelatedField(queryset=models.Session.objects.all())
|
session = serializers.PrimaryKeyRelatedField(queryset=models.Session.objects.all())
|
||||||
student_name = serializers.SerializerMethodField()
|
student_name = serializers.SerializerMethodField()
|
||||||
|
@ -266,7 +266,7 @@ class TrainingSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class StudentTrainingSerializer(TrainingSerializer):
|
class StudentTrainingSerializer(TrainingSerializer):
|
||||||
attendance_status = serializers.ChoiceField(['waiting for payment', 'withdrawn'])
|
attendance_status = serializers.ChoiceField(['Waiting for payment', 'Withdrawn'])
|
||||||
|
|
||||||
|
|
||||||
class SessionSerializer(serializers.ModelSerializer):
|
class SessionSerializer(serializers.ModelSerializer):
|
||||||
|
@ -283,7 +283,7 @@ class SessionSerializer(serializers.ModelSerializer):
|
||||||
read_only_fields = ['old_instructor', 'instructor']
|
read_only_fields = ['old_instructor', 'instructor']
|
||||||
|
|
||||||
def get_student_count(self, obj):
|
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):
|
def get_course_name(self, obj):
|
||||||
return obj.course.name
|
return obj.course.name
|
||||||
|
|
|
@ -183,6 +183,7 @@ class TrainingViewSet(Base, Retrieve, Create, Update):
|
||||||
return serializers.StudentTrainingSerializer
|
return serializers.StudentTrainingSerializer
|
||||||
|
|
||||||
# TODO: turn these into @actions
|
# TODO: turn these into @actions
|
||||||
|
# TODO: check if full
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
session_id = self.request.data['session']
|
session_id = self.request.data['session']
|
||||||
status = self.request.data['attendance_status']
|
status = self.request.data['attendance_status']
|
||||||
|
@ -192,16 +193,16 @@ class TrainingViewSet(Base, Retrieve, Create, Update):
|
||||||
raise exceptions.ValidationError('You have already registered')
|
raise exceptions.ValidationError('You have already registered')
|
||||||
if self.request.user == session.instructor:
|
if self.request.user == session.instructor:
|
||||||
raise exceptions.ValidationError('You are teaching this session')
|
raise exceptions.ValidationError('You are teaching this session')
|
||||||
if status == 'waiting for payment' and session.cost == 0:
|
if status == 'Waiting for payment' and session.cost == 0:
|
||||||
status = 'confirmed'
|
status = 'Confirmed'
|
||||||
serializer.save(user=self.request.user, attendance_status=status)
|
serializer.save(user=self.request.user, attendance_status=status)
|
||||||
|
|
||||||
def perform_update(self, serializer):
|
def perform_update(self, serializer):
|
||||||
session_id = self.request.data['session']
|
session_id = self.request.data['session']
|
||||||
status = self.request.data['attendance_status']
|
status = self.request.data['attendance_status']
|
||||||
session = get_object_or_404(models.Session, id=session_id)
|
session = get_object_or_404(models.Session, id=session_id)
|
||||||
if status == 'waiting for payment' and session.cost == 0:
|
if status == 'Waiting for payment' and session.cost == 0:
|
||||||
status = 'confirmed'
|
status = 'Confirmed'
|
||||||
serializer.save(attendance_status=status)
|
serializer.save(attendance_status=status)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ Full User
|
||||||
"instructor": null
|
"instructor": null
|
||||||
},
|
},
|
||||||
"member_id": 1685,
|
"member_id": 1685,
|
||||||
"attendance_status": "confirmed",
|
"attendance_status": "Confirmed",
|
||||||
"sign_up_date": null,
|
"sign_up_date": null,
|
||||||
"paid_date": null
|
"paid_date": null
|
||||||
}
|
}
|
||||||
|
@ -530,7 +530,7 @@ Reported Transactions
|
||||||
Create Transaction
|
Create Transaction
|
||||||
++++++++++++++++++
|
++++++++++++++++++
|
||||||
|
|
||||||
.. http:post:: /transaction/
|
.. http:post:: /transactions/
|
||||||
|
|
||||||
Add a transaction to a member. Admins only.
|
Add a transaction to a member. Admins only.
|
||||||
|
|
||||||
|
@ -764,7 +764,7 @@ Training
|
||||||
|
|
||||||
{
|
{
|
||||||
"id": 971,
|
"id": 971,
|
||||||
"attendance_status": "confirmed",
|
"attendance_status": "Confirmed",
|
||||||
"session": 11073,
|
"session": 11073,
|
||||||
"student_name": "Tanner Collin",
|
"student_name": "Tanner Collin",
|
||||||
"member_id": 1685,
|
"member_id": 1685,
|
||||||
|
@ -779,13 +779,13 @@ Training
|
||||||
|
|
||||||
**Users**
|
**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.
|
:json int session: The session (class) to register for.
|
||||||
|
|
||||||
**Instructors and Admins**
|
**Instructors and Admins**
|
||||||
|
|
||||||
:json attendance_status: One of: ``waiting for payment``, ``withdrawn``,
|
:json attendance_status: One of: ``Waiting for payment``, ``Withdrawn``,
|
||||||
``rescheduled``, ``no-show``, ``attended``, ``confirmed``
|
``Rescheduled``, ``No-show``, ``Attended``, ``Confirmed``
|
||||||
:json int session: The session (class) to register for.
|
:json int session: The session (class) to register for.
|
||||||
|
|
||||||
:requestheader Authorization: ``Token <token>``
|
:requestheader Authorization: ``Token <token>``
|
||||||
|
|
|
@ -70,7 +70,7 @@ TRAINING_FIELDS = [
|
||||||
'id',
|
'id',
|
||||||
# class_session_id -> session
|
# class_session_id -> session
|
||||||
'member_id',
|
'member_id',
|
||||||
'attendance_status',
|
# attendance_status -> capitalize
|
||||||
'sign_up_date',
|
'sign_up_date',
|
||||||
'paid_date',
|
'paid_date',
|
||||||
]
|
]
|
||||||
|
@ -239,6 +239,7 @@ for o in old:
|
||||||
for f in TRAINING_FIELDS:
|
for f in TRAINING_FIELDS:
|
||||||
new[f] = o.__dict__.get(f, None)
|
new[f] = o.__dict__.get(f, None)
|
||||||
new['session'] = models.Session.objects.get(id=o.class_session_id)
|
new['session'] = models.Session.objects.get(id=o.class_session_id)
|
||||||
|
new['attendance_status'] = o.attendance_status.capitalize()
|
||||||
|
|
||||||
models.Training.objects.create(**new)
|
models.Training.objects.create(**new)
|
||||||
print('Imported training #{} - {} {}'.format(
|
print('Imported training #{} - {} {}'.format(
|
||||||
|
|
|
@ -90,7 +90,7 @@ export function ClassDetail(props) {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const { token, user, refreshUser } = props;
|
const { token, user, refreshUser } = props;
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const userTraining = user.training.find(x => x.session.id == id);
|
const userTraining = clazz && clazz.students.find(x => x.user == user.id);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
requester('/sessions/'+id+'/', 'GET', token)
|
requester('/sessions/'+id+'/', 'GET', token)
|
||||||
|
@ -104,7 +104,7 @@ export function ClassDetail(props) {
|
||||||
}, [refreshCount]);
|
}, [refreshCount]);
|
||||||
|
|
||||||
const handleSignup = () => {
|
const handleSignup = () => {
|
||||||
const data = { attendance_status: 'waiting for payment', session: id };
|
const data = { attendance_status: 'Waiting for payment', session: id };
|
||||||
requester('/training/', 'POST', token, data)
|
requester('/training/', 'POST', token, data)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
refreshClass();
|
refreshClass();
|
||||||
|
@ -190,12 +190,12 @@ export function ClassDetail(props) {
|
||||||
(userTraining ?
|
(userTraining ?
|
||||||
<div>
|
<div>
|
||||||
<p>Status: {userTraining.attendance_status}</p>
|
<p>Status: {userTraining.attendance_status}</p>
|
||||||
{userTraining.attendance_status === 'withdrawn' ?
|
{userTraining.attendance_status === 'Withdrawn' ?
|
||||||
<Button onClick={() => handleToggle('waiting for payment')}>
|
<Button onClick={() => handleToggle('Waiting for payment')}>
|
||||||
Sign back up
|
Sign back up
|
||||||
</Button>
|
</Button>
|
||||||
:
|
:
|
||||||
<Button onClick={() => handleToggle('withdrawn')}>
|
<Button onClick={() => handleToggle('Withdrawn')}>
|
||||||
Withdraw from Class
|
Withdraw from Class
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,12 @@ import { BasicTable, staticUrl, requester } from './utils.js';
|
||||||
|
|
||||||
function AttendanceRow(props) {
|
function AttendanceRow(props) {
|
||||||
const { student, token, refreshClass } = props;
|
const { student, token, refreshClass } = props;
|
||||||
const [training, setTraining] = useState(student);
|
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const handleMark = (newStatus) => {
|
const handleMark = (newStatus) => {
|
||||||
const data = { attendance_status: newStatus };
|
const data = { ...student, attendance_status: newStatus };
|
||||||
requester('/training/'+training.id+'/', 'PATCH', token, data)
|
requester('/training/'+student.id+'/', 'PATCH', token, data)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setTraining(res);
|
|
||||||
refreshClass();
|
refreshClass();
|
||||||
setError(false);
|
setError(false);
|
||||||
})
|
})
|
||||||
|
@ -26,35 +24,33 @@ function AttendanceRow(props) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 'withdrawn', 'rescheduled', 'no-show', 'attended', 'confirmed'
|
|
||||||
|
|
||||||
const makeProps = (name) => ({
|
const makeProps = (name) => ({
|
||||||
onClick: () => handleMark(name),
|
onClick: () => handleMark(name),
|
||||||
toggle: true,
|
toggle: true,
|
||||||
active: training.attendance_status === name,
|
active: student.attendance_status === name,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='attendance-row'>
|
<div className='attendance-row'>
|
||||||
<p>{training.student_name}:</p>
|
<p>{student.student_name}:</p>
|
||||||
|
|
||||||
<Button {...makeProps('withdrawn')}>
|
<Button {...makeProps('Withdrawn')}>
|
||||||
Withdrawn
|
Withdrawn
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button {...makeProps('confirmed')}>
|
<Button {...makeProps('Confirmed')}>
|
||||||
Confirmed
|
Confirmed
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button {...makeProps('rescheduled')}>
|
<Button {...makeProps('Rescheduled')}>
|
||||||
Rescheduled
|
Rescheduled
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button {...makeProps('no-show')}>
|
<Button {...makeProps('No-show')}>
|
||||||
No-show
|
No-show
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button {...makeProps('attended')}>
|
<Button {...makeProps('Attended')}>
|
||||||
Attended
|
Attended
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
@ -104,7 +100,7 @@ function InstructorClassEditor(props) {
|
||||||
return (
|
return (
|
||||||
<div className='class-editor'>
|
<div className='class-editor'>
|
||||||
<Form.Input
|
<Form.Input
|
||||||
label='Cost ($)'
|
label='Cost ($) — 0 for free'
|
||||||
{...makeProps('cost')}
|
{...makeProps('cost')}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user