Commit b4b5639b authored by Daniel W Bond's avatar Daniel W Bond

added method to see if Student should be able to change floor

parent 8894f89e
......@@ -4,6 +4,7 @@ import hashlib
from datetime import date
# core django imports
from django.db import models
from django.utils import timezone
from model_utils.models import TimeStampedModel
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
......@@ -127,6 +128,8 @@ class Student(TimeStampedModel):
room = models.ForeignKey(Room, null=True, blank=True)
major = models.ForeignKey('Major', null=True, blank=True)
times_changed_room = models.IntegerField(default=0)
current_year = date.today().year
graduating_year = models.IntegerField(default=current_year, blank=True)
......@@ -160,6 +163,23 @@ class Student(TimeStampedModel):
else:
return "magic"
def can_change_floor(self):
# part of TimeStampedModel
now = timezone.now()
created = self.created
# could make this more formal with dateutil, but...
days = (now - created).days
half_years = days / float(30 * 6)
# we want you to be able to change your room at most
# twice in a six month period before blocking you
if (self.times_changed_room / half_years) <= 2:
return True
else:
return False
def get_floor(self):
try:
floor = self.room.floor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment