Skip to content

Commit

Permalink
Added view for Wharton cycles (enforces times on applications)
Browse files Browse the repository at this point in the history
Implemented ModelForm for Wharton admin
  • Loading branch information
julianweng committed Sep 25, 2023
1 parent 8c61ff5 commit 4e11b64
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Python files
__pycache__/
*.pyc
.python-version

# Distribution
/frontend/public/storybook/
Expand All @@ -27,6 +28,8 @@ db.sqlite3

# React
node_modules/
.yarn
.yarnrc.yml
.next/

# Development Enviroment
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
args: [--config, backend/setup.cfg]
- id: frontend
name: Yarn Linter
entry: yarn --cwd frontend lint
entry: bash -c "cd frontend && yarn lint"
language: system
files: ^frontend/
require_serial: false
Expand Down
19 changes: 19 additions & 0 deletions backend/clubs/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
AdminNote,
Advisor,
ApplicationCommittee,
ApplicationCycle,
ApplicationMultipleChoice,
ApplicationQuestion,
ApplicationQuestionResponse,
Expand Down Expand Up @@ -96,6 +97,24 @@ def save(self):
return super().save()


class ApplicationCycleSerializer(serializers.ModelSerializer):
class Meta:
model = ApplicationCycle
fields = ["id", "name", "start_date", "end_date"]

def validate(self, data):
"""
Check that start_date is before end_date.
"""
start_date = data.get("start_date")
end_date = data.get("end_date")

if start_date and end_date and start_date >= end_date:
raise serializers.ValidationError("Start must be before end.")

return data


class TagSerializer(serializers.ModelSerializer):
clubs = serializers.IntegerField(read_only=True)

Expand Down
4 changes: 4 additions & 0 deletions backend/clubs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
UserZoomAPIView,
WhartonApplicationAPIView,
WhartonApplicationStatusAPIView,
WhartonCyclesView,
YearViewSet,
email_preview,
)
Expand Down Expand Up @@ -77,6 +78,9 @@
router.register(
r"external/members/(?P<code>.+)", ExternalMemberListViewSet, basename="external"
)
router.register(
r"cycles", WhartonCyclesView, basename="wharton-applications-create",
)
router.register(r"submissions", ApplicationSubmissionUserViewSet, basename="submission")

clubs_router = routers.NestedSimpleRouter(router, r"clubs", lookup="club")
Expand Down
35 changes: 35 additions & 0 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
from clubs.models import (
AdminNote,
Advisor,
ApplicationCycle,
ApplicationMultipleChoice,
ApplicationQuestion,
ApplicationQuestionResponse,
Expand Down Expand Up @@ -125,6 +126,7 @@
from clubs.serializers import (
AdminNoteSerializer,
AdvisorSerializer,
ApplicationCycleSerializer,
ApplicationQuestionResponseSerializer,
ApplicationQuestionSerializer,
ApplicationSubmissionCSVSerializer,
Expand Down Expand Up @@ -4861,6 +4863,39 @@ def get_queryset(self):
)


class WhartonCyclesView(viewsets.ModelViewSet):
"""
update: Update application cycle
list: Get list of all application cycles
"""

permission_classes = [WhartonApplicationPermission | IsSuperuser]
http_method_names = ["get", "post", "put", "patch", "delete"]
serializer_class = ApplicationCycleSerializer

def get_queryset(self):
return ApplicationCycle.objects.all().order_by("end_date")

def list(self, request, *args, **kwargs):
return super().list(request, *args, **kwargs)

def update(self, *args, **kwargs):
"""
Updates times for all applications with cycle
"""
applications = ClubApplication.objects.filter(
application_cycle=self.get_object()
)
for app in applications:
app.application_start_time = self.get_object().start_date
app.application_end_time = self.get_object().end_date
if app.result_release_time < app.application_end_time:
app.result_release_time = app.application_end_time
+datetime.timedelta(days=10)
app.save()
return super().update(*args, **kwargs)


class WhartonApplicationAPIView(generics.ListAPIView):
"""
get: Return information about all Wharton Council club applications which are
Expand Down
32 changes: 32 additions & 0 deletions frontend/components/Settings/WhartonApplicationCycles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Field } from 'formik'
import React, { ReactElement } from 'react'

import { DateTimeField, TextField } from '../FormComponents'
import ModelForm from '../ModelForm'

const fields = (
<>
<Field name="name" as={TextField} />
<Field name="start_date" as={DateTimeField} />
<Field name="end_date" as={DateTimeField} />
</>
)

const WhartonApplicationCycles = (): ReactElement => {
return (
<>
<ModelForm
baseUrl={`/cycles/`}
noun="Cycle"
fields={fields}
tableFields={[
{ name: 'name' },
{ name: 'start_date' },
{ name: 'end_date' },
]}
/>
</>
)
}

export default WhartonApplicationCycles
6 changes: 6 additions & 0 deletions frontend/pages/wharton/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import renderPage from 'renderPage'
import { Application, ApplicationStatus } from 'types'
import { doBulkLookup } from 'utils'

import WhartonApplicationCycles from '~/components/Settings/WhartonApplicationCycles'
import WhartonApplicationStatus from '~/components/Settings/WhartonApplicationStatus'
import WhartonApplicationTab from '~/components/Settings/WhartonApplicationTab'
import { BG_GRADIENT, WHARTON_ROUTE, WHITE } from '~/constants'
Expand Down Expand Up @@ -36,6 +37,11 @@ function WhartonDashboard({
label: 'Status',
content: () => <WhartonApplicationStatus statuses={statuses} />,
},
{
name: 'cycle',
label: 'Cycles',
content: () => <WhartonApplicationCycles />,
},
]

const tab = router.query.slug?.[0]
Expand Down

0 comments on commit 4e11b64

Please sign in to comment.