From dab4a237910ee521e5889c31925957e5660033f6 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 8 Jan 2014 00:30:39 -0500 Subject: [PATCH] Reverting half-merged commits b6f336c6a13b2a41b2c29b35884277aea9daca50 and 3d4edeb1565e41f692d0c45f064ce3df13e5f211 --- .../management/commands/fetch_usde_csv.py | 2 +- .../management/commands/import_usde_csv.py | 2 +- .../commands/sanitize_usde_schools.py | 2 +- karmaworld/apps/courses/models.py | 59 +++++++++++++++- karmaworld/apps/courses/views.py | 2 +- karmaworld/apps/document_upload/tests.py | 2 +- karmaworld/apps/notes/tests.py | 2 +- karmaworld/apps/schools/__init__.py | 0 karmaworld/apps/schools/admin.py | 12 ---- .../apps/schools/management/__init__.py | 1 - .../schools/management/commands/__init__.py | 0 karmaworld/apps/schools/models.py | 70 ------------------- karmaworld/settings/common.py | 1 - 13 files changed, 62 insertions(+), 93 deletions(-) rename karmaworld/apps/{schools => courses}/management/commands/fetch_usde_csv.py (97%) rename karmaworld/apps/{schools => courses}/management/commands/import_usde_csv.py (97%) rename karmaworld/apps/{schools => courses}/management/commands/sanitize_usde_schools.py (98%) delete mode 100644 karmaworld/apps/schools/__init__.py delete mode 100644 karmaworld/apps/schools/admin.py delete mode 100644 karmaworld/apps/schools/management/__init__.py delete mode 100644 karmaworld/apps/schools/management/commands/__init__.py delete mode 100644 karmaworld/apps/schools/models.py diff --git a/karmaworld/apps/schools/management/commands/fetch_usde_csv.py b/karmaworld/apps/courses/management/commands/fetch_usde_csv.py similarity index 97% rename from karmaworld/apps/schools/management/commands/fetch_usde_csv.py rename to karmaworld/apps/courses/management/commands/fetch_usde_csv.py index 6d627f8..57f6415 100644 --- a/karmaworld/apps/schools/management/commands/fetch_usde_csv.py +++ b/karmaworld/apps/courses/management/commands/fetch_usde_csv.py @@ -7,7 +7,7 @@ from urlparse import urljoin from subprocess import call from django.core.management.base import BaseCommand -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School class Command(BaseCommand): args = '' diff --git a/karmaworld/apps/schools/management/commands/import_usde_csv.py b/karmaworld/apps/courses/management/commands/import_usde_csv.py similarity index 97% rename from karmaworld/apps/schools/management/commands/import_usde_csv.py rename to karmaworld/apps/courses/management/commands/import_usde_csv.py index 87f398c..8422624 100644 --- a/karmaworld/apps/schools/management/commands/import_usde_csv.py +++ b/karmaworld/apps/courses/management/commands/import_usde_csv.py @@ -2,7 +2,7 @@ import csv from itertools import izip from django.core.management.base import BaseCommand -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School class Command(BaseCommand): diff --git a/karmaworld/apps/schools/management/commands/sanitize_usde_schools.py b/karmaworld/apps/courses/management/commands/sanitize_usde_schools.py similarity index 98% rename from karmaworld/apps/schools/management/commands/sanitize_usde_schools.py rename to karmaworld/apps/courses/management/commands/sanitize_usde_schools.py index 8639832..119e420 100644 --- a/karmaworld/apps/schools/management/commands/sanitize_usde_schools.py +++ b/karmaworld/apps/courses/management/commands/sanitize_usde_schools.py @@ -8,7 +8,7 @@ from django.core.management.base import BaseCommand from django.db.models import Q -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School RESTRICTED_WORDS = [ 'internship', diff --git a/karmaworld/apps/courses/models.py b/karmaworld/apps/courses/models.py index 60ceec1..3fdabfd 100644 --- a/karmaworld/apps/courses/models.py +++ b/karmaworld/apps/courses/models.py @@ -14,9 +14,62 @@ from django.db import models from django.template import defaultfilters from karmaworld.settings.manual_unique_together import auto_add_check_unique_together -from karmaworld.apps.schools.models import School -from karmaworld.apps.schools.models import Department -from karmaworld.apps.professors.models import Professor + +class School(models.Model): + """ A grouping that contains many courses """ + name = models.CharField(max_length=255) + slug = models.SlugField(max_length=150, null=True) + location = models.CharField(max_length=255, blank=True, null=True) + url = models.URLField(max_length=511, blank=True) + # Facebook keeps a unique identifier for all schools + facebook_id = models.BigIntegerField(blank=True, null=True) + # United States Department of Education institution_id + usde_id = models.BigIntegerField(blank=True, null=True) + file_count = models.IntegerField(default=0) + priority = models.BooleanField(default=0) + alias = models.CharField(max_length=255, null=True, blank=True) + hashtag = models.CharField(max_length=16, null=True, blank=True, unique=True, help_text='School abbreviation without #') + + class Meta: + """ Sort School by file_count descending, name abc=> """ + ordering = ['-file_count','-priority', 'name'] + + def __unicode__(self): + return self.name + + def save(self, *args, **kwargs): + """ Save school and generate a slug if one doesn't exist """ + if not self.slug: + self.slug = defaultfilters.slugify(self.name) + super(School, self).save(*args, **kwargs) + + @staticmethod + def autocomplete_search_fields(): + return ("name__icontains",) + + def update_note_count(self): + """ Update the School.file_count by summing the + contained course.file_count + """ + self.file_count = sum([course.file_count for course in self.course_set.all()]) + self.save() + + +class Department(models.Model): + """ Department within a School. """ + name = models.CharField(max_length=255) + school = models.ForeignKey(School) # Should this be optional ever? + slug = models.SlugField(max_length=150, null=True) + url = models.URLField(max_length=511, blank=True, null=True) + + def __unicode__(self): + return self.name + + def save(self, *args, **kwargs): + """ Save department and generate a slug if one doesn't exist """ + if not self.slug: + self.slug = defaultfilters.slugify(self.name) + super(Department, self).save(*args, **kwargs) class Professor(models.Model): diff --git a/karmaworld/apps/courses/views.py b/karmaworld/apps/courses/views.py index 2023dec..657d756 100644 --- a/karmaworld/apps/courses/views.py +++ b/karmaworld/apps/courses/views.py @@ -17,7 +17,7 @@ from django.views.generic.list import ListView from karmaworld.apps.courses.forms import CourseForm from karmaworld.apps.courses.models import Course -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School from karmaworld.apps.notes.models import Note diff --git a/karmaworld/apps/document_upload/tests.py b/karmaworld/apps/document_upload/tests.py index 2097f59..843aa99 100644 --- a/karmaworld/apps/document_upload/tests.py +++ b/karmaworld/apps/document_upload/tests.py @@ -7,7 +7,7 @@ Replace this with more appropriate tests for your application. from django.test import TestCase, Client from karmaworld.apps.courses.models import Course -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School from karmaworld.apps.document_upload.forms import RawDocumentForm from karmaworld.apps.notes.gdrive import * from karmaworld.apps.notes.models import Note diff --git a/karmaworld/apps/notes/tests.py b/karmaworld/apps/notes/tests.py index 8949fb6..8e6646d 100644 --- a/karmaworld/apps/notes/tests.py +++ b/karmaworld/apps/notes/tests.py @@ -17,7 +17,7 @@ from karmaworld.apps.notes.search import SearchIndex from karmaworld.apps.notes.models import Note from karmaworld.apps.courses.models import Course -from karmaworld.apps.schools.models import School +from karmaworld.apps.courses.models import School import indextank.client as itc class TestNoes(TestCase): diff --git a/karmaworld/apps/schools/__init__.py b/karmaworld/apps/schools/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/karmaworld/apps/schools/admin.py b/karmaworld/apps/schools/admin.py deleted file mode 100644 index 70271b5..0000000 --- a/karmaworld/apps/schools/admin.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# Copyright (C) 2012 FinalsClub Foundation -""" Administration configuration for notes """ - -from django.contrib import admin - -from karmaworld.apps.schools.models import School -from karmaworld.apps.schools.models import Department - -admin.site.register(School) -admin.site.register(Department) diff --git a/karmaworld/apps/schools/management/__init__.py b/karmaworld/apps/schools/management/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/karmaworld/apps/schools/management/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/karmaworld/apps/schools/management/commands/__init__.py b/karmaworld/apps/schools/management/commands/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/karmaworld/apps/schools/models.py b/karmaworld/apps/schools/models.py deleted file mode 100644 index c7b13af..0000000 --- a/karmaworld/apps/schools/models.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# Copyright (C) 2012 FinalsClub Foundation - -""" - Models for schools. - Handles schools and departments. -""" -import datetime - -from django.db import models -from django.template import defaultfilters - - -class School(models.Model): - """ A grouping that contains many courses """ - name = models.CharField(max_length=255) - slug = models.SlugField(max_length=150, null=True) - location = models.CharField(max_length=255, blank=True, null=True) - url = models.URLField(max_length=511, blank=True) - # Facebook keeps a unique identifier for all schools - facebook_id = models.BigIntegerField(blank=True, null=True) - # United States Department of Education institution_id - usde_id = models.BigIntegerField(blank=True, null=True) - file_count = models.IntegerField(default=0) - priority = models.BooleanField(default=0) - alias = models.CharField(max_length=255, null=True, blank=True) - hashtag = models.CharField(max_length=16, null=True, blank=True, unique=True, help_text='School abbreviation without #') - - class Meta: - """ Sort School by file_count descending, name abc=> """ - ordering = ['-file_count','-priority', 'name'] - - - def __unicode__(self): - return self.name - - def save(self, *args, **kwargs): - """ Save school and generate a slug if one doesn't exist """ - if not self.slug: - self.slug = defaultfilters.slugify(self.name) - super(School, self).save(*args, **kwargs) - - @staticmethod - def autocomplete_search_fields(): - return ("name__icontains",) - - def update_note_count(self): - """ Update the School.file_count by summing the - contained course.file_count - """ - self.file_count = sum([course.file_count for course in self.course_set.all()]) - self.save() - - -class Department(models.Model): - """ Department within a School. """ - name = models.CharField(max_length=255) - school = models.ForeignKey(School) # Should this be optional ever? - slug = models.SlugField(max_length=150, null=True) - url = models.URLField(max_length=511, blank=True, null=True) - - def __unicode__(self): - return self.name - - def save(self, *args, **kwargs): - """ Save department and generate a slug if one doesn't exist """ - if not self.slug: - self.slug = defaultfilters.slugify(self.name) - super(Department, self).save(*args, **kwargs) diff --git a/karmaworld/settings/common.py b/karmaworld/settings/common.py index 963506f..bfc6fb1 100644 --- a/karmaworld/settings/common.py +++ b/karmaworld/settings/common.py @@ -216,7 +216,6 @@ LOCAL_APPS = ( 'karmaworld.apps.users', 'karmaworld.apps.moderation', 'karmaworld.apps.licenses', - 'karmaworld.apps.schools', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps -- 2.25.1