Commit 4915771315021267e1d9175143272633f5c9302e

Authored by Andrew Buss
1 parent cbcaace7a1
Exists in master

Class -> section. Set up API for sections, for real this time

Showing 9 changed files with 116 additions and 27 deletions Side-by-side Diff

flashcards/admin.py View file @ 4915771
1 1 from django.contrib import admin
2   -from flashcards.models import Flashcard, UserFlashcard, Class, FlashcardMask, \
  2 +from flashcards.models import Flashcard, UserFlashcard, Section, FlashcardMask, \
3 3 UserFlashcardReview
4 4  
5 5 admin.site.register([
... ... @@ -7,6 +7,6 @@
7 7 FlashcardMask,
8 8 UserFlashcard,
9 9 UserFlashcardReview,
10   - Class
  10 + Section
11 11 ])
flashcards/migrations/0004_auto_20150429_0827.py View file @ 4915771
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.db import models, migrations
  5 +
  6 +
  7 +class Migration(migrations.Migration):
  8 +
  9 + dependencies = [
  10 + ('flashcards', '0003_auto_20150429_0344'),
  11 + ]
  12 +
  13 + operations = [
  14 + migrations.CreateModel(
  15 + name='LecturePeriod',
  16 + fields=[
  17 + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
  18 + ('week_day', models.IntegerField(help_text=b'0-indexed day of week, starting at Monday')),
  19 + ('start_time', models.TimeField()),
  20 + ('end_time', models.TimeField()),
  21 + ],
  22 + ),
  23 + migrations.RenameModel(
  24 + old_name='Class',
  25 + new_name='Section',
  26 + ),
  27 + migrations.RemoveField(
  28 + model_name='flashcard',
  29 + name='associated_class',
  30 + ),
  31 + migrations.AddField(
  32 + model_name='flashcard',
  33 + name='section',
  34 + field=models.ForeignKey(default=None, to='flashcards.Section', help_text=b'The section with which the card is associated'),
  35 + preserve_default=False,
  36 + ),
  37 + migrations.AddField(
  38 + model_name='lectureperiod',
  39 + name='section',
  40 + field=models.ForeignKey(to='flashcards.Section'),
  41 + ),
  42 + ]
flashcards/models.py View file @ 4915771
... ... @@ -46,7 +46,7 @@
46 46  
47 47 class Flashcard(Model):
48 48 text = CharField(max_length=255, help_text='The text on the card')
49   - associated_class = ForeignKey('Class', help_text='The class with which the card is associated')
  49 + section = ForeignKey('Section', help_text='The section with which the card is associated')
50 50 pushed = DateTimeField(auto_now_add=True, help_text="When the card was first pushed")
51 51 material_date = DateTimeField(help_text="The date with which the card is associated")
52 52 previous = ForeignKey('Flashcard', null=True, blank=True,
53 53  
... ... @@ -104,11 +104,11 @@
104 104 if self.response: return "answered"
105 105 return "viewed"
106 106  
107   -
108   -class Class(Model):
  107 +class Section(Model):
109 108 """
110 109 A UCSD course taught by an instructor during a quarter.
111   - Different sections taught by the same instructor in the same quarter are considered identical.s
  110 + Different sections taught by the same instructor in the same quarter are considered identical.
  111 + We use the term "section" to avoid collision with the builtin keyword "class"
112 112 """
113 113 department = CharField(max_length=50)
114 114 course_num = IntegerField()
... ... @@ -120,4 +120,14 @@
120 120 class Meta:
121 121 unique_together = (('department', 'course_num', 'quarter', 'instructor'),)
122 122 ordering = ['-quarter']
  123 +
  124 +
  125 +class LecturePeriod(Model):
  126 + """
  127 + A lecture period for a section
  128 + """
  129 + section = ForeignKey(Section)
  130 + week_day = IntegerField(help_text="0-indexed day of week, starting at Monday")
  131 + start_time = TimeField()
  132 + end_time = TimeField()
flashcards/serializers.py View file @ 4915771
1   -__author__ = 'andrew'
  1 +from flashcards.models import Section, LecturePeriod
  2 +from rest_framework.relations import HyperlinkedRelatedField
  3 +from rest_framework.serializers import HyperlinkedModelSerializer
  4 +
  5 +
  6 +class SectionSerializer(HyperlinkedModelSerializer):
  7 + lectureperiod_set = HyperlinkedRelatedField(many=True, view_name='lectureperiod-detail', read_only=True)
  8 + class Meta:
  9 + model = Section
  10 + exclude = ('members',)
  11 +
  12 +
  13 +class LecturePeriodSerializer(HyperlinkedModelSerializer):
  14 + class Meta:
  15 + model = LecturePeriod
flashcards/views.py View file @ 4915771
1   -from django.shortcuts import render
  1 +from flashcards.models import Section, LecturePeriod
  2 +from flashcards.serializers import SectionSerializer, LecturePeriodSerializer
  3 +from rest_framework.permissions import IsAuthenticatedOrReadOnly
  4 +from rest_framework.viewsets import ModelViewSet
2 5  
3   -# Create your views here.
  6 +
  7 +class SectionViewSet(ModelViewSet):
  8 + queryset = Section.objects.all()
  9 + serializer_class = SectionSerializer
  10 + permission_classes = (IsAuthenticatedOrReadOnly,)
  11 +
  12 +class LecturePeriodViewSet(ModelViewSet):
  13 + queryset = LecturePeriod.objects.all()
  14 + serializer_class = LecturePeriodSerializer
  15 + permission_classes = (IsAuthenticatedOrReadOnly,)
flashy/settings.py View file @ 4915771
... ... @@ -58,7 +58,7 @@
58 58 TEMPLATES = [
59 59 {
60 60 'BACKEND': 'django.template.backends.django.DjangoTemplates',
61   - 'DIRS': [],
  61 + 'DIRS': ['templates/'],
62 62 'APP_DIRS': True,
63 63 'OPTIONS': {
64 64 'context_processors': [
flashy/urls.py View file @ 4915771
1 1 from django.conf.urls import include, url
2 2 from django.contrib import admin
  3 +from flashcards.views import SectionViewSet, LecturePeriodViewSet
  4 +from rest_framework.routers import DefaultRouter
3 5  
  6 +router = DefaultRouter()
  7 +router.register(r'sections', SectionViewSet)
  8 +router.register(r'lectureperiods', LecturePeriodViewSet)
  9 +
4 10 urlpatterns = [
  11 + url(r'^api/', include(router.urls)),
5 12 url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
6 13 url(r'^admin/', include(admin.site.urls)),
7 14 url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
schedule-scraper/scrape_schedule.js View file @ 4915771
1 1 var page = require('webpage').create();
2 2 var fs = require('fs');
3   -page.open('file:///home/andrew/Downloads/Student Class Info.html', function(status) {
  3 +page.open('Student Class Info.html', function (status) {
4 4 if (status !== 'success') {
5   - console.log('load failed');
  5 + console.log('load failed');
6 6 } else {
7   - console.log("loaded");
8   - page.injectJs("jquery.min.js");
9   - console.log("got jquery");
10   - page.includeJs("http://www.kunalbabre.com/projects/table2CSV.js", function() {
11   - console.log("got script");
12   - page.evaluate(function() {
13   - console.log("parsing");
14   - try {
15   - fs.write("schedule.csv", $('table.tbrdr').table2CSV({'delivery':'value'}), 'w');
16   - } catch(e) {
17   - console.log(e);
18   - }
19   - });
20   - });
  7 + console.log("loaded");
  8 + page.injectJs("jquery.min.js");
  9 + console.log("got jquery");
  10 + page.includeJs("http://www.kunalbabre.com/projects/table2CSV.js", function () {
  11 + console.log("got script");
  12 + page.evaluate(function () {
  13 + console.log("parsing");
  14 + try {
  15 + fs.write("schedule.csv", $('table.tbrdr').table2CSV({'delivery': 'value'}), 'w');
  16 + } catch (e) {
  17 + console.log(e);
  18 + }
  19 + });
  20 + });
21 21 }
22 22 phantom.exit();
23 23 });
templates/rest_framework/api.html View file @ 4915771
  1 +{% extends "rest_framework/base.html" %}
  2 +{% block bootstrap_theme %}
  3 + <link rel="stylesheet" href="https://bootswatch.com/darkly/bootstrap.css" type="text/css">
  4 +{% endblock %}