Skip to content

Commit

Permalink
initial commit, override
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Gupta committed Jun 4, 2014
0 parents commit c809f30
Show file tree
Hide file tree
Showing 217 changed files with 101,864 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Created by http://www.gitignore.io

### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml

## File-based project format
*.ipr
*.iws
*.iml

## Additional for IntelliJ
out/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/

# generated by JIRA plugin
atlassian-ide-plugin.xml

# generated by Crashlytics plugin (for Android Studio and Intellij)
com_crashlytics_export_strings.xml
50 changes: 50 additions & 0 deletions auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from django.contrib.auth.models import User
from openid.consumer.consumer import SUCCESS
from django.core.mail import mail_admins
from coursereview.models import UserProfile

class GoogleBackend:
def authenticate(self, openid_response):
allow = ['[email protected]', '[email protected]']
if openid_response is None:
return None
if openid_response.status != SUCCESS:
return None

google_email = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.email')
google_firstname = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.firstname')
google_lastname = openid_response.getSigned('http://openid.net/srv/ax/1.0', 'value.lastname')

if ("@iiitd.ac.in" not in google_email and google_email not in allow):
return None

try:
#user = User.objects.get(username=google_email)
# Make sure that the e-mail is unique.
user = User.objects.get(email=google_email)
except User.DoesNotExist:
user = User.objects.create_user(google_email, google_email, 'password')
user.save()
user = User.objects.get(username=google_email)

p = UserProfile.objects.get_or_create(user= user,
email= google_email,
defaults= {'name': google_firstname + " " + google_lastname})[0]

if p.email.split("@")[0][-1] in "0123456789": #Most likely a student
print p.email.split("@")[0][-1]
print p.email, p.email.split("@")[0]
p.type = "S"
print p.type
print p.__dict__
else:
p.type = "P"
p.save()
return user


def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
Empty file added coursereview/__init__.py
Empty file.
Binary file added coursereview/__init__.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions coursereview/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django import forms
from django.forms import ModelForm
from models import Course, Review
from django_select2.widgets import Select2Widget


class CourseForm(forms.Form):
all = Course.objects.all().values()
idList = []
idList = [('', '')] + [(course['courseID'], course['courseID'] + ' - ' + course['name']) for course in all]
id = forms.ChoiceField(label=u'', choices=idList, required=True,
error_messages={'required': 'You forgot to choose a course !'},
widget=Select2Widget(attrs={'placeholder': 'Select a Course', 'class': 'choiceWidget'},
select2_options={
'width': '600px',
'allowClear': 'True',
}))

class reviewForm(ModelForm):
class Meta:
model = Review
exclude = {'reviewer', 'createdTime', 'upvotes'}
fields = {'course', 'anon', 'yearTaken', 'semTaken', 'creditsTaken', 'faculty',
'easeOfScoring', 'industryApplication', 'interesting', 'easeOfContent', 'workload', 'qualityTeaching', 'relevance',
'technicality', 'projectBurden', 'comment'}
Binary file added coursereview/forms.pyc
Binary file not shown.
94 changes: 94 additions & 0 deletions coursereview/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

import datetime

from django.contrib.auth.models import User
from django.db import models
from django import forms


class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True)
email = models.CharField(max_length=40, blank=True, null=True)
name = models.CharField(max_length=40, blank=True, null=True)
typeChoice = ((u'S', u'Student'), (u'P', u'Professor'))
type = models.CharField(max_length=1, choices=typeChoice)
genderChoice = ((u'M', u'Male'), (u'F', u'Female'))
sex = models.CharField(max_length=1, choices=genderChoice)
dob = models.DateField(blank=True, null=True)
#Foreign key to many reviews
#Foreign key to many reviews (as faculty too)
favouriteReviews = models.ManyToManyField('Review', related_name="favBy")
watchList = models.ManyToManyField('Course', related_name="watcher")
#reports
#upvoted_revs
#downvoted_revs
#review_reviewer

class Faculty(models.Model):
facultyID = models.CharField(max_length=6, blank="True", null="True")
name = models.CharField(max_length=40, blank="True", null="True")
email = models.CharField(max_length=40, blank="True", null="True")
genderChoice = ((u'M', u'Male'), (u'P', u'Female'))
sex = models.CharField(max_length=1, choices=genderChoice)
#Foreign key to many reviews
#Foreign key to many reviews (as faculty too)
teaches = models.ManyToManyField('Course', related_name="taughtBy")



class Review(models.Model):
reviewer = models.ForeignKey(User, related_name='reviewReviewer')
course = models.ForeignKey('Course', blank=False)
#please do not touch. DateField, not TimeField.
createdTime = models.DateField()
#Is the review anonymous?
anon = models.BooleanField()
yearChoices = tuple([(x, x) for x in range(2007, datetime.datetime.now().year + 1)])
yearTaken = models.IntegerField(choices=yearChoices)
semTaken = models.PositiveSmallIntegerField(default=1)
creditsTaken = models.PositiveSmallIntegerField(choices=[(2,2), (4,4)], default=4)

faculty = models.ForeignKey('Faculty', blank=False)
upvotes = models.SmallIntegerField(default=0)
upvoters = models.ManyToManyField(User, related_name="upvotedRevs")
downvoters = models.ManyToManyField(User, related_name="downwotedRevs")
reporter = models.ManyToManyField(User, related_name="reports")
#fav_by

easeOfScoring = models.PositiveSmallIntegerField(default=5)
industryApplication = models.PositiveSmallIntegerField(default=5)
interesting = models.PositiveSmallIntegerField(default=5)
easeOfContent = models.PositiveSmallIntegerField(default=5)
workload = models.PositiveSmallIntegerField(default=5)
qualityTeaching = models.PositiveSmallIntegerField(default=5)
relevance = models.PositiveSmallIntegerField(default=5)
technicality = models.PositiveSmallIntegerField(default=5)
projectBurden = models.PositiveSmallIntegerField(default=5)

comment = models.TextField(max_length=5000, null="True")


class Course(models.Model):
courseID = models.CharField(max_length=6, blank="True", null="True")
name = models.CharField(max_length=256, blank="True", null="True")
hasProject = models.BooleanField(default=False)
#taught_by

#Foreign key to many reviews


class CourseCombination(models.Model):
favOf = models.ForeignKey(User)
courses = models.ManyToManyField(Course)


class FeedbackForm(forms.Form):
userName = forms.TextInput
emailId = forms.TextInput
feedbackType = forms.RadioSelect
bugExpected = forms.Textarea
bugCurrent = forms.Textarea
bugSteps = forms.Textarea
message = forms.Textarea
say = forms.Textarea
attachment = forms.FileField
Binary file added coursereview/models.pyc
Binary file not shown.
35 changes: 35 additions & 0 deletions coursereview/readCourses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import re
import json
from openpyxl import load_workbook


courses = {}

basepath = os.path.dirname(__file__)
filepath = os.path.abspath(os.path.join(basepath, "..", "static", "data", "courseList.xlsx"))
jsonfilepath = os.path.abspath(os.path.join(basepath, "..", "static", "data", "courseData.json"))

wb = load_workbook(filepath)
ws = wb.get_sheet_by_name(name='Course numbers')

pattern = re.compile('^[A-Z]{3}[0-9]{3}$')

for rownum in range(1, ws.get_highest_row()):
cell_data = str(ws.cell(row=rownum, column=1).value)
if cell_data == "None":
continue
elif re.match(pattern, cell_data) is not None:
courseArea = cell_data[:-3]
courseID = cell_data[3:]
courseName = str(ws.cell(row=rownum, column=2).value)
if not courses.has_key(courseArea):
courses[courseArea] = []
courses[courseArea].append({
'ID': courseID,
'Name': courseName})

with open(jsonfilepath, 'w') as outfile:
json.dump(courses, outfile)

print "\nCourses successfully written to ", jsonfilepath, "\n"
56 changes: 56 additions & 0 deletions coursereview/readJSON.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
import os
import sys


basepath = os.path.dirname(__file__)

""" settings parh """
settingPath = os.path.abspath(os.path.join(basepath, ".."))

""" file path for SERVER """
#jsonfilepath = os.path.abspath(os.path.join(basepath, "..", "..", "..", "staticfiles", "data", "courseData.json"))

""" file path for LOCALHOST """
jsonfilepath = os.path.abspath(os.path.join(basepath, "..", "static", "data", "courseData.json"))

sys.path.append(settingPath)
os.environ['DJANGO_SETTINGS_MODULE'] = 'coursereview.settings'
from coursereview.models import Course

jFile = open(jsonfilepath)
data = json.load(jFile)
jFile.close()

""" area = [CSE, MTH, PHY] etc """
areaWiseDict = []

""" truncate all data from course table """
Course.objects.all().delete()

""" excluded courses """
exclude = "Special Topics", "MTech", "PhD"
addCount = 0
skipCount = 0

for courseArea in data:
areaWiseDict = data[courseArea]
if str(courseArea) == "MSC":
print "Skipping:", len(areaWiseDict), courseArea, "courses"
skipCount += len(areaWiseDict)
continue

for course in range(0, len(areaWiseDict)):
cID = courseArea + areaWiseDict[course]['ID']
cName = areaWiseDict[course]['Name']
for x in exclude:
if str(cName).find(x) != -1:
print "Skipping:", cID, cName
skipCount += 1
break
else:
Course(courseID=cID, name=cName).save()
addCount += 1

print addCount, "courses added!"
print skipCount, "courses skipped!"
37 changes: 37 additions & 0 deletions coursereview/readProfCSV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import csv
import os
import sys


basepath = os.path.dirname(__file__)

""" settings parh """
settingPath = os.path.abspath(os.path.join(basepath, ".."))

""" file path for SERVER """
#csvfilepath = os.path.abspath(os.path.join(basepath, "..", "..", "..", "staticfiles", "data", "courseData.json"))

""" file path for LOCALHOST """
csvfilepath = os.path.abspath(os.path.join(basepath, "..", "static", "data", "profs_pruned.csv"))

sys.path.append(settingPath)
os.environ['DJANGO_SETTINGS_MODULE'] = 'coursereview.settings'
from coursereview.models import Faculty

csvFile = open(csvfilepath, 'r')
reader = csv.reader(csvFile)

""" truncate all data from course table """
Faculty.objects.all().delete()

addCount = 0
facultyID = 1
for row in reader:
row = sorted(row, key=str.lower)
print row
for prof in row:
Faculty(facultyID = facultyID, name=prof).save()
facultyID += 1
addCount += 1

print addCount, "professors added!"
Empty file.
Binary file added coursereview/scripts/__init__.pyc
Binary file not shown.
30 changes: 30 additions & 0 deletions coursereview/scripts/combo_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def check_clash(d, tt):
can = []
for x in d:
can += [tuple(y) for y in tt[x[1]][1]]
if len(can) > len(set(can)):
return False
return True


def find_clash(myl, i, timetable):
combos = []
combo = []
s = range(len(myl)/i)
myl.sort()
myl = myl[::-1]
print myl
print s
for a in s:
for b in s[a+1:]:
for c in s[b+1:]:
for d in s[c+1:]:
for e in s[d+1:]:
combo = [myl[a], myl[b], myl[c], myl[d], myl[e]]
if check_clash(combo, timetable):
#print "inside"
print combo
combos += [combo]
if len(combos) >= 5:
return combos
return combos
Binary file added coursereview/scripts/combo_finder.pyc
Binary file not shown.
Loading

0 comments on commit c809f30

Please sign in to comment.