Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
judtinzhang committed Mar 7, 2024
2 parents f973b76 + 10be4f0 commit 254c741
Show file tree
Hide file tree
Showing 80 changed files with 4,257 additions and 1,645 deletions.
2 changes: 1 addition & 1 deletion .github/cdk/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new LabsApplicationStack(app, {
djangoProjectName: 'pennmobile',
dockerImageBaseName: 'penn-mobile',
djangoCheckProps: {
pythonVersion: "3.9.14-buster",
pythonVersion: "3.11-bookworm",
}
});

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cdkactions_build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: codecov-umbrella
verbose: true
container:
image: python:3.9.14-buster
image: python:3.11-bookworm
env:
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
services:
Expand Down
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ repos:
- repo: https://github.com/pennlabs/pre-commit-hooks
rev: stable
hooks:
- id: black
- id: isort
- id: flake8
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This repository is the Django-based successor to `labs-api-server`, containing A
- `git clone https://github.com/pennlabs/penn-mobile.git`
- `cd penn-mobile/backend`
- `brew install postgres`
- `pipenv install --dev --python 3.9`
- `pipenv install --dev --python 3.11`

Note that the above command will likely throw some ugly errors at you with regards to the `psycopg2` packages. If that is the case, just manually install them:
- `pipenv install psycopg2`
Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pennlabs/django-base:4a5feb154cbce223ab108e775ca60af0f604f479-3.9.14
FROM pennlabs/django-base:b269ea1613686b1ac6370154debbb741b012de1a-3.11

LABEL maintainer="Penn Labs"

Expand Down
16 changes: 9 additions & 7 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ verify_ssl = true
[dev-packages]
black = "==19.10b0"
unittest-xml-reporting = "*"
flake8 = "*"
flake8-isort = "*"
flake8-quotes = "*"
flake8 = "==6.1.0"
flake8-isort = "==6.1.0"
flake8-quotes = "==3.3.2"
django-extensions = "*"
flake8-absolute-import = "*"
rope = "*"
Expand All @@ -24,16 +24,17 @@ pandas = "*"
html5lib = "*"
psycopg2 = "*"
sentry-sdk = "*"
django = "*"
django = "==5.0.2"
django-cors-headers = "*"
pyyaml = "*"
uritemplate = "*"
uwsgi = "*"
uwsgi = {version = "*", markers = "sys_platform== 'linux'"}
django-filter = "*"
django-labs-accounts = "*"
django-labs-accounts = "==0.9.5"
django-debug-toolbar = "*"
django-runtime-options = "*"
django-storages = "*"
django-phonenumber-field = {extras = ["phonenumberslite"],version = "*"}
pillow = "*"
boto3 = "*"
apns2 = "*"
Expand All @@ -43,6 +44,7 @@ celery = "*"
django-redis = "*"
redis = "*"
python-dateutil = "*"
selenium = "*"

[requires]
python_version = "3.9.14"
python_version = "3.11"
1,449 changes: 730 additions & 719 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions backend/dining/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.urls import path
from django.views.decorators.cache import cache_page

from dining.views import Menus, Preferences, Venues
from utils.cache import Cache


urlpatterns = [
path("venues/", Venues.as_view(), name="venues"),
path("menus/", Menus.as_view(), name="menus"),
path("menus/<date>/", Menus.as_view(), name="menus-with-date"),
path("venues/", cache_page(12 * Cache.HOUR)(Venues.as_view()), name="venues"),
path("menus/", cache_page(3 * Cache.HOUR)(Menus.as_view()), name="menus"),
path("menus/<date>/", cache_page(3 * Cache.HOUR)(Menus.as_view()), name="menus-with-date"),
path("preferences/", Preferences.as_view(), name="dining-preferences"),
]
33 changes: 18 additions & 15 deletions backend/dining/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime

from django.core.cache import cache
from django.db.models import Count
from django.shortcuts import get_object_or_404
from django.utils import timezone
Expand All @@ -13,6 +14,7 @@
from dining.api_wrapper import DiningAPIWrapper
from dining.models import DiningMenu, Venue
from dining.serializers import DiningMenuSerializer
from utils.cache import Cache


d = DiningAPIWrapper()
Expand Down Expand Up @@ -58,30 +60,31 @@ class Preferences(APIView):
"""

permission_classes = [IsAuthenticated]
key = "dining_preferences:{user_id}"

def get(self, request):

preferences = request.user.profile.dining_preferences

# aggregates venues and puts it in form {"venue_id": x, "count": x}
return Response(
{"preferences": preferences.values("venue_id").annotate(count=Count("venue_id"))}
)
key = self.key.format(user_id=request.user.id)
cached_preferences = cache.get(key)
if cached_preferences is None:
preferences = request.user.profile.dining_preferences
# aggregates venues and puts it in form {"venue_id": x, "count": x}
cached_preferences = preferences.values("venue_id").annotate(count=Count("venue_id"))
cache.set(key, cached_preferences, Cache.MONTH)
return Response({"preferences": cached_preferences})

def post(self, request):

key = self.key.format(user_id=request.user.id)
profile = request.user.profile

preferences = profile.dining_preferences

venue_ids = set(request.data["venues"])
venues = [get_object_or_404(Venue, venue_id=int(venue_id)) for venue_id in venue_ids]

# clears all previous preferences associated with the profile
preferences.clear()
preferences.add(*venues)

venue_ids = request.data["venues"]

for venue_id in venue_ids:
venue = get_object_or_404(Venue, venue_id=int(venue_id))
# adds all of the preferences given by the request
preferences.add(venue)
# clear cache
cache.delete(key)

return Response({"success": True, "error": None})
11 changes: 10 additions & 1 deletion backend/gsr_booking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ class GroupMembershipAdmin(admin.ModelAdmin):
search_fields = ["user__username__icontains", "group__name__icontains"]


class GSRAdmin(admin.ModelAdmin):
def get_queryset(self, request):
return GSR.all_objects.all()

list_display = ["name", "kind", "lid", "gid", "in_use"]
search_fields = ["name", "lid", "gid"]
ordering = ["-in_use"]


admin.site.register(Group)
admin.site.register(GroupMembership, GroupMembershipAdmin)
admin.site.register(GSR)
admin.site.register(GSR, GSRAdmin)
admin.site.register(GSRBooking)
admin.site.register(Reservation)
Loading

0 comments on commit 254c741

Please sign in to comment.