Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WC Admin application cycle edit/create table #590

Merged
merged 15 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
rohangpta marked this conversation as resolved.
Show resolved Hide resolved
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"]
rohangpta marked this conversation as resolved.
Show resolved Hide resolved

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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need put, patch, and delete?

Docstring only specifies update and list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update the docstring, thanks for the catch! Default behavior for post and delete are used in ModelForm to let the user create delete cycles I believe, and patch is used for update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant more of:

  • do we want to allow deleting?
  • we should consider picking one of put/patch, they are generally considered to have similar semantics ("put" is idempotent, whereas "patch" is not always)

serializer_class = ApplicationCycleSerializer

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

def list(self, request, *args, **kwargs):
rohangpta marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Member

@rohangpta rohangpta Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to pass lint but looks a bit awkward? Definitely a nit though

rohangpta marked this conversation as resolved.
Show resolved Hide resolved
app.save()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't affect prod performance but it would be good practice to use bulk_update!

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
Loading