class SubmissionForm(forms.Form):
    file = forms.FileField() class StudentProfileForm(forms.ModelForm):
    class Meta:
        model = Student
        exclude = ('user', 'course')

    fields = [ 'first_name', 'last_name'] class Submission(models.Model):
    date = models.DateTimeField(editable=False, auto_now_add=True)
    course = models.ForeignKey(Course) 
    grade = models.FloatField(null = True, blank = True)
    assignment = models.ForeignKey(Assignment)
    submitter = models.ForeignKey(Student)
    docfile = models.FileField(upload_to='documents/%Y/%m/%d')
    remarks = models.TextField()
    
    def get_grade_path(self, filename):
        savename = str(self.assignment.name) + os.path.splitext(filename)[1]
        return os.path.join('uploads/submitted_files/',
                            self.course.department,
                            self.course.name,
                            self.submitter.username,
                            savename)

    def __unicode__(self):
        return (self.assignment.__unicode__() + " - " + self.submitter.user.username) class Course(models.Model):
    name = models.CharField(max_length=512, unique = True)
    department = models.CharField(max_length=4)
    description = models.TextField(max_length=512)
    instructor = models.ForeignKey(Instructor)

    def __unicode__(self):
        return unicode(self.name) class Student(models.Model):
    first_name = models.CharField(max_length=20)
    last_name = models.CharField(max_length=30)
    user = models.OneToOneField(User, unique=True)
    course = models.ManyToManyField(Course, blank=True, null=True)

    def __unicode__(self):
        return unicode(self.user) class Lecture(models.Model):
    name = models.CharField(max_length=20)
    video = EmbedVideoField()
    course = models.ForeignKey(Course)
    #for future feature of notes?
    #notes = models.CharField(max_length=512)
    
    def __unicode__(self):
        return (self.course.name + " - " + self.name) class Assignment(models.Model):
    date = models.DateTimeField(editable=False, auto_now_add=True)
    due_date = models.DateTimeField(editable=True)
    course = models.ForeignKey(Course)
    name = models.CharField(max_length=20)
    description = models.TextField(max_length=512)
    points_possible = models.IntegerField(default=100)
    QUIZ = 'Quiz'
    EXAM = 'Exam'
    HOMEWORK = 'Homework'
    PROJECT = 'Project'
    SUBMISSION_TYPE_CHOICES = (
        (QUIZ, QUIZ),
        (EXAM, EXAM),
        (HOMEWORK, HOMEWORK),
        (PROJECT, PROJECT))
    submission_type = models.CharField(max_length=8,
                                       choices=SUBMISSION_TYPE_CHOICES,
                                       default=QUIZ)    



    def __unicode__(self):
        return (self.course.name + " - " + self.name) class Homework(Submission):
    weight = .2 class Quiz(Submission):
    weight = .2 class Exam(Submission):
    weight = .4 class Project(Submission):
    weight = .2 class CourseMaterial(models.Model):
    file = models.FileField(upload_to='/fucking/dont/upload/here')
    course = models.ForeignKey(Course)
    description = models.TextField(max_length=30)
from django.shortcuts import render_to_response, render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import get_user_model
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse_lazy
from django.template import RequestContext
from django.core.context_processors import csrf
from django.conf import settings
from django.core.servers.basehttp import FileWrapper
from registration.backends.simple.views import RegistrationView
from django.views.static import serve
from django.views.generic.edit import UpdateView
from student_portal.forms import SubmissionForm, StudentProfileForm
from student_portal.models import Submission, Course, Student, Lecture, Assignment, Homework, Quiz, Exam, Project, CourseMaterial
import matplotlib.pyplot as plt
import numpy as np
import os
import mimetypes




def student_about(request):
    return render(request, 'about.html')

class StudentProfileEditView(UpdateView):

    model = Student