models.py 4.97 KB
Newer Older
1
from django.db import models
Okhin's avatar
Okhin committed
2
from django.core.urlresolvers import reverse
stef's avatar
stef committed
3
from django.utils.translation import ugettext_lazy as _
Okhin's avatar
Okhin committed
4
from django_comments.moderation import CommentModerator, moderator
5

6
COUNTRIES = (
7
8
    ('BE', _('Belgium')),
    ('BG', _('Bulgaria')),
9
    ('CH', _('Switzerland')),
10
11
12
13
14
15
16
17
    ('CZ', _('Czech Republic')),
    ('DK', _('Denmark')),
    ('DE', _('Germany')),
    ('EE', _('Estonia')),
    ('IE', _('Ireland')),
    ('EL', _('Greece')),
    ('ES', _('Spain')),
    ('FR', _('France')),
18
    ('IC', _('Iceland')),
19
    ('IS', _('Iceland')),
20
21
    ('IT', _('Italy')),
    ('CY', _('Cyprus')),
22
    ('LI', _('Liechtenstein')),
23
24
25
26
27
28
    ('LV', _('Latvia')),
    ('LT', _('Lithuania')),
    ('LU', _('Luxembourg')),
    ('HU', _('Hungary')),
    ('MT', _('Malta')),
    ('NL', _('Netherlands')),
29
    ('NO', _('Norway')),
30
31
32
33
34
35
36
37
    ('AT', _('Austria')),
    ('PL', _('Poland')),
    ('PT', _('Portugal')),
    ('RO', _('Romania')),
    ('SI', _('Slovenia')),
    ('SK', _('Slovakia')),
    ('FI', _('Finland')),
    ('SE', _('Sweden')),
38
    ('UK', _('United Kingdom')),
39
40
    )
RESOURCES = (
41
    ('other', _('other')),
stef's avatar
stef committed
42
43
44
    ('port', _('port')),
    ('protocol', _('protocol')),
    ('service', _('service')),
45
    ('site', _('website')),
stef's avatar
stef committed
46
47
    ('user', _('user')),
    ('ip', _('ip')),
48
49
50
    ('video', _('video streaming')),
    ('audio', _('audio streaming')),
    ('class', _('class of application or contraint')),
51
52
    )
TYPES = (
53
    ('zerorating', _('Zero Rating')),
54
    ('specialised', _('Specialised Service')),
stef's avatar
stef committed
55
56
    ('blocking', _('Blocking')),
    ('throttling', _('Throttling')),
57
58
    ('prioritisation', _('Prioritisation')),
    ('other', _('Other'))
59
60
    )
MEDIA = (
stef's avatar
stef committed
61
62
    ('fixed', _('Fixed')),
    ('mobile', _('Mobile')),
63
    )
64
STATUS = (
65
    ('moreinfo', _('Need more info')),
66
    ('new', _('New')),
stef's avatar
stef committed
67
    ('verified', _('Verified')),
68
    ('duplicate', _('Duplicate')),
69
    ('ooscope', _('Out of scope')),
stef's avatar
stef committed
70
    ('closed', _('Closed')),
71
    )
72

73
74
75
76
77
78
79
80
81
82
83
84
85
86
class Operator(models.Model):
    """
    Define the concept of an internet provider/network operator
    """
    name = models.CharField(max_length=256)
    logo = models.ImageField(upload_to='operator_logo', null=True, blank=True)

    def reported_violations(self):
        return self.violations.count()
    reported_violations.short_description = 'Reported Violations'

    def __unicode__(self):
        return self.name

87
class Violation(models.Model):
88
    country = models.CharField(max_length=2, choices=COUNTRIES)
89
    operator_ref = models.ForeignKey(Operator, related_name="violations")
stef's avatar
stef committed
90
91
92
93
94
    contract = models.CharField(max_length=256, blank=True)
    resource = models.CharField(max_length=20, choices=RESOURCES, blank=True)
    resource_name = models.CharField(max_length=4096, blank=True)
    type = models.CharField(max_length=20, choices=TYPES, blank=True)
    media = models.CharField( max_length=20, choices=MEDIA, blank=True)
95
96
    temporary = models.BooleanField( )
    contractual = models.BooleanField()
Okhin's avatar
Okhin committed
97
    contract_excerpt = models.TextField(null=True, blank=True)
98
    loophole = models.BooleanField()
Okhin's avatar
Okhin committed
99
    activationid= models.CharField(max_length=128, null=True, blank=True)
100
    state = models.CharField(max_length=20, choices=STATUS, default='new', blank=True)
Okhin's avatar
Okhin committed
101
102
    editorial = models.TextField(null=True, blank=True)
    old = models.BooleanField(default="False")
103
    creation_date = models.DateField(auto_now_add=True)
stef's avatar
stef committed
104

stef's avatar
stef committed
105
106
107
    def confirmations(self):
        return self.confirmation_set.filter(key='').count()

108
109
110
    class Admin:
        pass

111
112
113
114
    @property
    def operator(self):
        return self.operator_ref.name

115
    def get_absolute_url(self):
Okhin's avatar
Okhin committed
116
        return reverse('violation_url', args=(self.pk))
117

118
119
120
    def __unicode__(self):
        return "#%s %s/%s" % (self.pk, self.country, self.operator)

stef's avatar
stef committed
121
class Comment(models.Model):
122
123
    submitter_email = models.EmailField()
    submitter_name = models.CharField(max_length=20)
stef's avatar
stef committed
124
    consent = models.BooleanField( )
stef's avatar
stef committed
125
    comment = models.TextField()
126
    timestamp = models.DateTimeField()
stef's avatar
stef committed
127
128
    violation = models.ForeignKey(Violation)

129
130
131
132
    class Admin:
        pass

    def __unicode__(self):
stef's avatar
stef committed
133
        return _("Comment #%s") % (self.pk)
134

stef's avatar
stef committed
135
136
class Attachment(models.Model):
    storage = models.FileField(upload_to='static')
137
    name= models.CharField(max_length=512)
138
    type= models.CharField(max_length=512)
stef's avatar
stef committed
139
    comment = models.ForeignKey(Comment)
140

141
142
143
144
145
146
    class Admin:
        pass

    def __unicode__(self):
        return self.name

stef's avatar
stef committed
147
class Confirmation(models.Model):
148
    key=models.CharField(max_length=64, blank=True)
stef's avatar
stef committed
149
150
151
    email=models.EmailField()
    violation = models.ForeignKey(Violation)

152
153
154
    class Admin:
        pass

155
156
157
158
159
160
161
162
class ViolationModerator(CommentModerator):
    email_notification = True
    moderate_after        = 0
    def moderate(self, comment, content_object, request):
        return True

if Violation not in moderator._registry:
    moderator.register(Violation, ViolationModerator)
163
164
165
166
167
168
169
170
171

class FeaturedCase(models.Model):
    case = models.OneToOneField(Violation)

    class Admin:
        pass

    def __unicode__(self):
        return u"*%s*" % self.case