<commit_before>from __future__ import division
from django.conf import settings
from django.db import models
from django.db import transaction
from django.db.models import Q
from django.template import defaultfilters
from django.utils import timezone
from datetime import datetime

from uchicagohvz.overwrite_fs import OverwriteFileSystemStorage
from uchicagohvz.users.backend import UChicagoLDAPBackend

from mptt.models import MPTTModel, TreeForeignKey
from ranking import Ranking

import hashlib
import os
import random


# Create your models here.

def gen_rules_filename(instance, fn):
	return "rules/%s%s" % (instance.name, os.path.splitext(fn)[1])

def gen_pics_filename(instance, fn):
	return "pictures/%s%s" % (instance.picture.url, os.path.splitext(fn)[1])

class GameManager(models.Manager):
	def games_in_progress(self):
		now = timezone.now()
		return self.filter(start_date__lte=now, end_date__gte=now)

class Game(models.Model):
	class Meta:
		ordering = ['-start_date']

	name = models.CharField(max_length=255)
	registration_date = models.DateTimeField()
	start_date = models.DateTimeField()
	end_date = models.DateTimeField()
	rules = models.FileField(upload_to=gen_rules_filename, storage=OverwriteFileSystemStorage())
	picture = models.FileField(upload_to=gen_pics_filename, storage=OverwriteFileSystemStorage(), null=True, blank=True)
	color = models.CharField(max_length=64, default="#FFFFFF")	
	flavor = models.TextField(max_length=6000, default="")


	objects = GameManager()

	def __unicode__(self):
		return self.name

	def get_registered_players(self):
		return self.players.all()

	def get_active_players(self):
		return self.players.filter(active=True)

	def get_humans(self):
		return self.get_active_players().filter(human=True)

	def get_zombies(self):
		return self.get_active_players().filter(human=False)

	def get_players_in_dorm(self, dorm):
		return self.get_active_players().filter(dorm=dorm)

	def get_kills(self):
		"""
		Return all Kill objects for this game
		"""
		return Kill.objects.filter(killer__game=self)

	@property
	def status(self):
		now = timezone.now()
		if self.registration_date < now < self.start_date:
			return 'registration'
		elif self.start_date < now < self.end_date:
			return 'in_progress'
		elif now > self.end_date:
			return 'finished'
		else:
			return 'future'

	@property
	def humans_listhost_address(self):
		return <EMAIL>-<EMAIL>" % defaultfilters.slugify(self.name)

	@property
	def zombies_listhost_address(self):
		return <EMAIL>" % defaultfilters.slugify(self.name)
		

	@models.permalink
	def get_absolute_url(self):
		return ('game|show', [self.pk])

OLD_DORMS = (
	("BS", "Blackstone"),
	("BR", "Breckinridge"),
	("BV", "Broadview"),
	("BJ", "Burton-Judson Courts"),
	("IH", "International House"),
	("MC", "Maclean"),
	("MAX", "<NAME>"),
	("NG", "New Graduate Residence Hall"),
	("SH", "Snell-Hitchcock"),
	("SC", "South Campus"),
	("ST", "Stony Island"),
	("OFF", "Off campus")
)

DORMS = (
	("BJ", "Burton-Judson Courts"),
	("IH", "International House"),
	("MAX", "<NAME>"),
	("NC", "North Campus"),
	("SH", "Snell-Hitchcock"),
	("SC", "South Campus"),
	("ST", "Stony Island"),
	("OFF", "Off campus")
)

DORMS_CLOSE = datetime(2016, 6, 14)

NOUNS = open(os.path.join(settings.BASE_DIR, "game/word-lists/nouns.txt")).read().split('\n')[:-1]
ADJECTIVES = open(os.path.join(settings.BASE_DIR, "game/word-lists/adjs.txt")).read().split('\n')[:-1]

def gen_bite_code():
	return random.choice(ADJECTIVES) + ' ' + random.choice(NOUNS)

class New_Squad(models.Model):
	class Meta:
		unique_together = (('game', 'name'))

	game = models.ForeignKey(Game, related_name='new_squads')
	name = models.CharField(max_length=128)

	def __unicode__(self):
		return "%s" % (self.name)

	@models.permalink
	def get_absolute_url(self):
		return ('new_squad|show', [self.pk])<commit_msg>fix timezone awareness typeerror<commit_after>from __future__ import division
from django.conf import settings
from django.db import models
from django.db import transaction
from django.db.models import Q
from django.template import defaultfilters
from django.utils import timezone
from datetime import datetime

from uchicagohvz.overwrite_fs import OverwriteFileSystemStorage
from uchicagohvz.users.backend import UChicagoLDAPBackend

from mptt.models import MPTTModel, TreeForeignKey
from ranking import Ranking

import hashlib
import os
import random


# Create your models here.

def gen_rules_filename(instance, fn):
	return "rules/%s%s" % (instance.name, os.path.splitext(fn)[1])

def gen_pics_filename(instance, fn):
	return "pictures/%s%s" % (instance.picture.url, os.path.splitext(fn)[1])

class GameManager(models.Manager):
	def games_in_progress(self):
		now = timezone.now()
		return self.filter(start_date__lte=now, end_date__gte=now)

class Game(models.Model):
	class Meta:
		ordering = ['-start_date']

	name = models.CharField(max_length=255)
	registration_date = models.DateTimeField()
	start_date = models.DateTimeField()
	end_date = models.DateTimeField()
	rules = models.FileField(upload_to=gen_rules_filename, storage=OverwriteFileSystemStorage())
	picture = models.FileField(upload_to=gen_pics_filename, storage=OverwriteFileSystemStorage(), null=True, blank=True)
	color = models.CharField(max_length=64, default="#FFFFFF")	
	flavor = models.TextField(max_length=6000, default="")


	objects = GameManager()

	def __unicode__(self):
		return self.name

	def get_registered_players(self):
		return self.players.all()

	def get_active_players(self):
		return self.players.filter(active=True)

	def get_humans(self):
		return self.get_active_players().filter(human=True)

	def get_zombies(self):
		return self.get_active_players().filter(human=False)

	def get_players_in_dorm(self, dorm):
		return self.get_active_players().filter(dorm=dorm)

	def get_kills(self):
		"""
		Return all Kill objects for this game
		"""
		return Kill.objects.filter(killer__game=self)

	@property
	def status(self):
		now = timezone.now()
		if self.registration_date < now < self.start_date:
			return 'registration'
		elif self.start_date < now < self.end_date:
			return 'in_progress'
		elif now > self.end_date:
			return 'finished'
		else:
			return 'future'

	@property
	def humans_listhost_address(self):
		return <EMAIL>" % defaultfilters.slugify(self.name)

	@property
	def zombies_listhost_address(self):
		return <EMAIL>" % defaultfilters.slugify(self.name)
		

	@models.permalink
	def get_absolute_url(self):
		return ('game|show', [self.pk])

OLD_DORMS = (
	("BS", "Blackstone"),
	("BR", "Breckinridge"),
	("BV", "Broadview"),
	("BJ", "Burton-Judson Courts"),
	("IH", "International House"),
	("MC", "Maclean"),
	("MAX", "<NAME>"),
	("NG", "New Graduate Residence Hall"),
	("SH", "Snell-Hitchcock"),
	("SC", "South Campus"),
	("ST", "Stony Island"),
	("OFF", "Off campus")
)

DORMS = (
	("BJ", "Burton-Judson Courts"),
	("IH", "International House"),
	("MAX", "<NAME>"),
	("NC", "North Campus"),
	("SH", "Snell-Hitchcock"),
	("SC", "South Campus"),
	("ST", "Stony Island"),
	("OFF", "Off campus")
)

DORMS_CLOSE = timezone.make_aware(datetime(2016, 6, 14), timezone.get_default_timezone())

NOUNS = open(os.path.join(settings.BASE_DIR, "game/word-lists/nouns.txt")).read().split('\n')[:-1]
ADJECTIVES = open(os.path.join(settings.BASE_DIR, "game/word-lists/adjs.txt")).read().split('\n')[:-1]

def gen_bite_code():
	return random.choice(ADJECTIVES) + ' ' + random.choice(NOUNS)

class New_Squad(models.Model):
	class Meta:
		unique_together = (('game', 'name'))

	game = models.ForeignKey(Game, related_name='new_squads')
	name = models.CharField(max_length=128)

	def __unicode__(self):
		return "%s" % (self.name)

	@models.permalink
	def get_absolute_url(self):
		return ('new_squad|show', [self.pk])
{'fraction_non_alphanumeric': 0.14986481266898416, 'fraction_numerical': 0.0059224925968842535, 'mean_word_length': 5.778359511343805, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2821563', 'n_tokens_mistral': 2914, 'n_tokens_neox': 2730, 'n_words': 573}