@@ -0,0 +1,2339 @@
+from django.conf import settings%0Afrom django.core.exceptions import ObjectDoesNotExist%0Afrom datetime import datetime%0Afrom models import Term%0Afrom restclients.sws_client import SWSClient%0Aimport logging%0Aimport urllib%0Aimport re%0Aimport json%0A%0A# quarter class definition%0A%0Aclass Quarter:%0A    __logger = logging.getLogger('quartermanager')%0A    __sws_client = SWSClient()%0A%0A    def __init__(self):%0A        pass%0A%0A    def get_cur_quarter(self):%0A        # see if we have local data%0A        try:%0A            self.local = Term.objects.get(%0A                first_day_quarter__lte=datetime.today(),%0A                last_final_exam_date__gte=datetime.today()%0A                )%0A        except ObjectDoesNotExist:%0A            __mock()%0A        return self.local%0A%0A    def get_next_quarter(self):%0A        pass%0A%0A    def get_cur_quarter_from_sws(self):%0A        url = '...'; # mock SWS URL base%0A        self.sws_result = __sws_client.get_current_term(url)%0A        %0A    def get_next_quarter_from_sws(self):%0A        url = '...'%0A        self.sws_result = __sws_client.get_next_term(url)%0A        %0A    def get_prev_quarter_from_sws(self):%0A        url = '...'%0A        self.sws_result = __sws_client.get_previous_term(url)%0A%0A    def refresh_sws(self):%0A        get_cur_quarter_from_sws()%0A        self.local = Term (%0A            year = self.sws_result.year,%0A            quarter = self.sws_result.quarter,%0A            first_day_quarter = self.sws_result.first_day,%0A            last_day_instruction = self.sws_result.last_day_of_classes, %0A            aterm_last_date = self.sws_result.last_add_day_a_term,%0A            bterm_first_date = self.sws_result.b_term_first_day,%0A            last_final_exam_date = self.sws_result.last_final_exam_day,%0A            last_verified =  datetime.now()%0A            )%0A        __save()%0A%0A    def __mock(self):%0A        # mock data%0A        self.local = Term (%0A            year = '2012',%0A            quarter = '3',%0A            first_day_quarter = datetime.date(2012, 6, 18),%0A            last_day_instruction = datetime.date(2012, 8, 10),%0A            aterm_last_date = datetime.date(2012, 7, 18),%0A            bterm_first_date = datetime.date(2012, 6, 19),%0A            last_final_exam_date = datetime.date(2012, 8, 17),%0A            last_verified =  datetime.now()%0A            )%0A        __save()%0A%0A    def __save(self):%0A        self.local.save()%0A     %0A%0A

Create the class that maintain the term cache.