3
3
from django.db.models import signals
4
4
from django.contrib.contenttypes.models import ContentType
5
5
from django.contrib.contenttypes import generic
6
from pytz import common_timezones
7
from django import forms
8
from django.forms import ModelForm
8
# Create your models here.
11
# - Should channels have their own models? Useful if we intend to user per channel permissions
12
# - Will need to figure out how to assign events for ops who may not have logins (like freenode staffers)
13
# - Determine how kickbans will be logged
14
# - Take a look at django's built-in comment model
11
# Make a dict of all timezones using pytz instead of maintaining a static dict here
13
for zone in common_timezones:
14
TZ_CHOICES.append((zone,zone))
16
17
class Issue(models.Model):
17
18
create_date = models.DateTimeField(auto_now_add = True,editable = False)
18
19
modify_date = models.DateTimeField(auto_now = True, editable = False)
19
20
closed_date = models.DateTimeField(null = True)
20
21
author = models.ForeignKey(User,null = True)
22
description = models.TextField()
23
log = models.ForeignKey('Log', null = True)
21
24
comments = generic.GenericRelation('Comment')
22
26
def is_closed(self):
23
27
return self.closed_date != None
29
class IssueForm(ModelForm):
32
fields = ('description',)
25
36
class Event(models.Model):
26
37
"Defines the Event base class. Every IRC event class should inherit from this."
27
38
create_date = models.DateTimeField(auto_now_add = False)
30
41
log = models.ForeignKey('Log')
31
42
operator = models.ForeignKey('Operator')
32
43
hostmask = models.CharField(max_length=255)
33
comments = generic.GenericRelation('Comment')
44
comments = generic.GenericRelation('Comment')
35
46
def __unicode__(self):
36
47
return self.hostmask
43
54
mask = models.CharField(max_length=255)
44
55
removal_date = models.DateTimeField(null = True)
45
removed_by = models.ForeignKey('Operator', null = True)
56
removed_by = models.ForeignKey('Operator', null = True, related_name = 'removed_by')
57
kick = models.OneToOneField('Kick', null = True)
48
59
def is_removed(self):
49
60
return self.removal_date != None
63
return self.mask[0] == '%'
51
65
def __unicode__(self):
78
94
class UserProfile(models.Model):
79
95
user = models.ForeignKey(User, unique = True, editable=False)
80
96
hostmask = models.CharField(max_length=255) # Will need to figure out how to lock this down, so that people cannot assign themselves *!*@*
97
timezone = models.CharField(max_length=100,choices=TZ_CHOICES)
82
99
def hostmask_pattern(self):
83
100
return re.compile(self.hostmask.replace('?','.').replace('*','.*'))