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

5
COUNTRIES = (
6 7
    ('BE', _('Belgium')),
    ('BG', _('Bulgaria')),
8
    ('CH', _('Switzerland')),
9 10 11 12 13 14 15 16
    ('CZ', _('Czech Republic')),
    ('DK', _('Denmark')),
    ('DE', _('Germany')),
    ('EE', _('Estonia')),
    ('IE', _('Ireland')),
    ('EL', _('Greece')),
    ('ES', _('Spain')),
    ('FR', _('France')),
17
    ('IC', _('Iceland')),
18
    ('IS', _('Iceland')),
19 20
    ('IT', _('Italy')),
    ('CY', _('Cyprus')),
21
    ('LI', _('Liechtenstein')),
22 23 24 25 26 27
    ('LV', _('Latvia')),
    ('LT', _('Lithuania')),
    ('LU', _('Luxembourg')),
    ('HU', _('Hungary')),
    ('MT', _('Malta')),
    ('NL', _('Netherlands')),
28
    ('NO', _('Norway')),
29 30 31 32 33 34 35 36
    ('AT', _('Austria')),
    ('PL', _('Poland')),
    ('PT', _('Portugal')),
    ('RO', _('Romania')),
    ('SI', _('Slovenia')),
    ('SK', _('Slovakia')),
    ('FI', _('Finland')),
    ('SE', _('Sweden')),
37
    ('UK', _('United Kingdom')),
38 39 40
    )

RESOURCES = (
stef's avatar
stef committed
41 42 43
    ('port', _('port')),
    ('protocol', _('protocol')),
    ('service', _('service')),
44
    ('site', _('website')),
stef's avatar
stef committed
45 46
    ('user', _('user')),
    ('ip', _('ip')),
47 48 49
    ('video', _('video streaming')),
    ('audio', _('audio streaming')),
    ('class', _('class of application or contraint')),
50
    ('other', _('other'))
51 52
    )
TYPES = (
53
    ('zerorating', _('Zero Rating')),
stef's avatar
stef committed
54 55
    ('blocking', _('Blocking')),
    ('throttling', _('Throttling')),
56 57 58
    ('prioritisation', _('Prioritisation')),
    ('specialised', _('Specialised Service')),
    ('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 116 117 118 119
    @models.permalink
    def get_absolute_url(self):
        return ('violation_url', (), 
            {'id': self.pk })

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

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

131 132 133 134
    class Admin:
        pass

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

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

143 144 145 146 147 148
    class Admin:
        pass

    def __unicode__(self):
        return self.name

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

154 155 156
    class Admin:
        pass

157 158 159 160 161 162 163 164
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)
165 166 167 168 169 170 171 172 173

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

    class Admin:
        pass

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