# Path: lib/constants.py
# CURRENT_TERM = os.environ["CURRENT_TERM"]  # e.g. 16S
# 
# Path: lib/terms.py
# def numeric_value_of_term(term):
#     term_data = term_regex.match(term)
#     if term_data and term_data.group("year") and term_data.group("term"):
#         year = int(term_data.group("year"))
#         term = term_data.group("term")
#         return year * 10 + {'w': 1, 's': 2, 'x': 3, 'f': 4}[term.lower()]
#     return 0


from django.db import models
from django.db.models import Q
from course_offering import CourseOffering
from django.core.urlresolvers import reverse
from lib.constants import CURRENT_TERM
from lib.terms import numeric_value_of_term
import re
    description = models.TextField(null=True, blank=True)

    difficulty_score = models.IntegerField(default=0)
    quality_score = models.IntegerField(default=0)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        unique_together = ("department", "number", "subnumber")

    def __unicode__(self):
        return "{}: {}".format(self.short_name(), self.title)

    def get_absolute_url(self):
        return reverse('course_detail', args=[self.id])

    def short_name(self):
        if self.subnumber:
            return "{0}{1:03d}.{2:02d}".format(
                self.department, self.number, self.subnumber)
        else:
            return "{0}{1:03d}".format(self.department, self.number)

    def distribs_string(self, separator=", "):
        return separator.join([d.name for d in self.distribs.all()])

    def offered_times_string(self, term=CURRENT_TERM):
        return ", ".join(self.offered_times(term))


# Path: lib/constants.py
# CURRENT_TERM = os.environ["CURRENT_TERM"]  # e.g. 16S
# 
# Path: lib/terms.py
# def numeric_value_of_term(term):
#     term_data = term_regex.match(term)
#     if term_data and term_data.group("year") and term_data.group("term"):
#         year = int(term_data.group("year"))
#         term = term_data.group("term")
#         return year * 10 + {'w': 1, 's': 2, 'x': 3, 'f': 4}[term.lower()]
#     return 0


# Path: apps/web/models/course.py
from django.db import models
from django.db.models import Q
from course_offering import CourseOffering
from django.core.urlresolvers import reverse
from lib.constants import CURRENT_TERM
from lib.terms import numeric_value_of_term
import re

    description = models.TextField(null=True, blank=True)

    difficulty_score = models.IntegerField(default=0)
    quality_score = models.IntegerField(default=0)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        unique_together = ("department", "number", "subnumber")

    def __unicode__(self):
        return "{}: {}".format(self.short_name(), self.title)

    def get_absolute_url(self):
        return reverse('course_detail', args=[self.id])

    def short_name(self):
        if self.subnumber:
            return "{0}{1:03d}.{2:02d}".format(
                self.department, self.number, self.subnumber)
        else:
            return "{0}{1:03d}".format(self.department, self.number)

    def distribs_string(self, separator=", "):
        return separator.join([d.name for d in self.distribs.all()])

    def offered_times_string(self, term=CURRENT_TERM):
        return ", ".join(self.offered_times(term))


    def offered_times(self, term=CURRENT_TERM):