Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
eyingxuan committed Oct 19, 2019
2 parents c2799af + 9f275d9 commit 2f9d2b3
Show file tree
Hide file tree
Showing 30 changed files with 403 additions and 121 deletions.
2 changes: 2 additions & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/heroku/heroku-buildpack-python.git
https://github.com/heroku/heroku-buildpack-nodejs.git
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ yarn-error.log*
frontend/*/build/
*.sqlite3
*-test.json
celerybeat-schedule
celerybeat-schedule
pcr-backup
12 changes: 11 additions & 1 deletion PennCourses/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@

ROOT_URLCONF = 'PennCourses.urls.base'

FRONTEND_DIR = os.path.abspath(
os.path.join(BASE_DIR, '..', 'frontend'))

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
FRONTEND_DIR
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -86,6 +91,8 @@
},
]

STATICFILES_DIRS = [os.path.join(FRONTEND_DIR, 'plan', 'build', 'static')]

WSGI_APPLICATION = 'PennCourses.wsgi.application'


Expand Down Expand Up @@ -157,6 +164,9 @@
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_TOKEN', '')
TWILIO_NUMBER = os.environ.get('TWILIO_NUMBER', '+12153984277')

# Penn Course Review API
PCR_TOKEN = os.environ.get('PCR_TOKEN', '')

# Redis
REDIS_URL = os.environ.get('REDIS_URL', 'redis://localhost')

Expand Down
2 changes: 1 addition & 1 deletion PennCourses/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SENTRY_KEY = ''

'''
Custom Switchboard Middleware
Custom Switchboard Middleware (docker should fix this)
This is the app that you want to run locally. While all Penn Courses apps run off the same django backend,
they operate with different URL schemes since they have different APIs. The app value should correspond to a file
Expand Down
4 changes: 2 additions & 2 deletions PennCourses/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

'penncourseplan.com': 'pcp',
'www.penncourseplan.com': 'pcp',
'penncoursesearch.com': 'pcp',
'www.penncoursesearch.com': 'pcp',
'penncoursesearch.com': 'pcp-construction',
'www.penncoursesearch.com': 'pcp-construction',

'penncoursereview.com': 'pcr',
'www.penncoursereview.com': 'pcr'
Expand Down
9 changes: 9 additions & 0 deletions PennCourses/urls/pcp-construction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from django.views.generic import TemplateView

from PennCourses.urls.base import urlpatterns


urlpatterns = [
path('', TemplateView.as_view(template_name='plan_construction/index.html')),
] + urlpatterns
32 changes: 11 additions & 21 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"dokku": {
"predeploy": "python manage.py migrate --noinput"
"predeploy": "python manage.py migrate --noinput && cd frontend/plan && npm install && npm run build && cd ../.. && python manage.py collectstatic"
}
}
}
10 changes: 8 additions & 2 deletions courses/management/commands/loadcourses.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import logging

from django.core.management.base import BaseCommand

from courses.tasks import load_courses
from courses.tasks import load_courses, load_requirements


class Command(BaseCommand):
help = 'Load in courses, sections and associated models from the Penn registrar.'
help = 'Load in courses, sections and associated models from the Penn registrar and requirements data sources.'

def add_arguments(self, parser):
parser.add_argument('--semester', nargs='?', type=str)
parser.add_argument('--query', nargs='?', default='')

def handle(self, *args, **kwargs):
root_logger = logging.getLogger('')
root_logger.setLevel(logging.DEBUG)
load_courses(query=kwargs['query'], semester=kwargs['semester'])
load_requirements(school='SEAS', semester=kwargs['semester'])
load_requirements(school='WH', semester=kwargs['semester'])
40 changes: 39 additions & 1 deletion courses/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db.models import Prefetch, Q
from rest_framework import serializers

from courses.models import Course, Meeting, Requirement, Section
Expand Down Expand Up @@ -30,10 +31,30 @@ def to_representation(self, value):
}


class MiniSectionSerializer(serializers.ModelSerializer):

class Meta:
model = Section
fields = [
'id',
'status',
'activity',
]

@staticmethod
def get_semester(obj):
return obj.course.semester

@staticmethod
def setup_eager_loading(queryset):
return queryset


class SectionSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField(source='normalized')
semester = serializers.SerializerMethodField()
meetings = MeetingSerializer(many=True)
instructors = serializers.StringRelatedField(many=True)

@staticmethod
def get_semester(obj):
Expand All @@ -54,7 +75,8 @@ class Meta:
'activity',
'credits',
'semester',
'meetings'
'meetings',
'instructors',
]


Expand All @@ -70,6 +92,7 @@ class Meta:
'credits',
'semester',
'meetings',
'instructors',
] + [
'associated_sections',
]
Expand Down Expand Up @@ -118,11 +141,20 @@ class Meta:

class CourseListSerializer(serializers.ModelSerializer):
id = serializers.ReadOnlyField(source='course_id')
num_sections = serializers.SerializerMethodField()

def get_num_sections(self, obj):
return obj.sections.count()

@staticmethod
def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('primary_listing__listing_set__department',
'department',
Prefetch('sections',
Section.objects
.filter(meetings__isnull=False)
.filter(credits__isnull=False)
.filter(Q(status='O') | Q(status='C')).distinct()),
'sections__review_set__reviewbit_set'
)
return queryset
Expand All @@ -134,6 +166,7 @@ class Meta:
'title',
'description',
'semester',
'num_sections',
]


Expand All @@ -146,6 +179,11 @@ class CourseDetailSerializer(CourseListSerializer):
def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('primary_listing__listing_set__department',
'department',
Prefetch('sections',
Section.objects
.filter(meetings__isnull=False)
.filter(credits__isnull=False)
.filter(Q(status='O') | Q(status='C')).distinct()),
'sections__course__department',
'sections__meetings__room__building',
'sections__associated_sections__course__department',
Expand Down
19 changes: 17 additions & 2 deletions courses/tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from celery import shared_task

from courses import registrar
from courses.models import Course, Department, Requirement
from courses.util import upsert_course_from_opendata
Expand All @@ -9,16 +11,22 @@
logger = logging.getLogger(__name__)


# @shared_task(name='courses.tasks.load_courses')
@shared_task(name='courses.tasks.load_courses')
def load_courses(query='', semester=None):
if semester is None:
semester = get_value('SEMESTER')

logger.info('load in courses with prefix %s from %s' % (query, semester))
logger.setLevel(logging.DEBUG)
print('load in courses with prefix %s from %s' % (query, semester))
results = registrar.get_courses(query, semester)

num_courses = len(results)
i = 0
for course in results:
if i % 100 == 0:
print(f'loading in course {i} / {num_courses}')
upsert_course_from_opendata(course, semester)
i += 1

return {'result': 'succeeded', 'name': 'courses.tasks.load_courses'}

Expand Down Expand Up @@ -80,3 +88,10 @@ def load_requirements(school=None, semester=None, requirements=None):
requirement.courses.add(course)
else:
requirement.overrides.add(course)


@shared_task(name='courses.tasks.semester_sync')
def semester_sync(query='', semester=None):
load_courses(query=query, semester=semester)
load_requirements(school='SEAS', semester=semester)
load_requirements(school='WH', semester=semester)

0 comments on commit 2f9d2b3

Please sign in to comment.