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

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

RESOURCES = (
stef's avatar
stef committed
38
39
40
41
42
43
    ('port', _('port')),
    ('protocol', _('protocol')),
    ('service', _('service')),
    ('site', _('site')),
    ('user', _('user')),
    ('ip', _('ip')),
44
45
    )
TYPES = (
stef's avatar
stef committed
46
47
    ('blocking', _('Blocking')),
    ('throttling', _('Throttling')),
48
49
    )
MEDIA = (
stef's avatar
stef committed
50
51
    ('fixed', _('Fixed')),
    ('mobile', _('Mobile')),
52
    )
53
STATUS = (
54
    ('moreinfo', _('Need more info')),
55
    ('new', _('New')),
stef's avatar
stef committed
56
    ('verified', _('Verified')),
57
    ('duplicate', _('Duplicate')),
58
    ('ooscope', _('Out of scope')),
stef's avatar
stef committed
59
    ('closed', _('Closed')),
60
    )
61
62

class Violation(models.Model):
63
64
    country = models.CharField(max_length=2, choices=COUNTRIES)
    operator = models.CharField(max_length=256)
stef's avatar
stef committed
65
66
67
68
69
    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)
70
71
    temporary = models.BooleanField( )
    contractual = models.BooleanField()
stef's avatar
stef committed
72
    contract_excerpt = models.TextField(blank=True)
73
    loophole = models.BooleanField()
stef's avatar
stef committed
74
    activationid= models.CharField(max_length=128, blank=True)
75
76
    state = models.CharField(max_length=20, choices=STATUS, default='new', blank=True)
    editorial = models.TextField(blank=True)
stef's avatar
stef committed
77

stef's avatar
stef committed
78
79
80
    def confirmations(self):
        return self.confirmation_set.filter(key='').count()

81
82
83
    class Admin:
        pass

84
85
86
87
88
    @models.permalink
    def get_absolute_url(self):
        return ('violation_url', (), 
            {'id': self.pk })

89
90
91
92
    def __unicode__(self):
        return "#%s %s/%s" % (self.pk, self.country, self.operator)


stef's avatar
stef committed
93
class Comment(models.Model):
94
95
    submitter_email = models.EmailField()
    submitter_name = models.CharField(max_length=20)
stef's avatar
stef committed
96
    consent = models.BooleanField( )
stef's avatar
stef committed
97
    comment = models.TextField()
98
    timestamp = models.DateTimeField()
stef's avatar
stef committed
99
100
    violation = models.ForeignKey(Violation)

101
102
103
104
    class Admin:
        pass

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

stef's avatar
stef committed
107
108
class Attachment(models.Model):
    storage = models.FileField(upload_to='static')
109
    name= models.CharField(max_length=512)
110
    type= models.CharField(max_length=512)
stef's avatar
stef committed
111
    comment = models.ForeignKey(Comment)
112

113
114
115
116
117
118
    class Admin:
        pass

    def __unicode__(self):
        return self.name

stef's avatar
stef committed
119
class Confirmation(models.Model):
120
    key=models.CharField(max_length=64, blank=True)
stef's avatar
stef committed
121
122
123
    email=models.EmailField()
    violation = models.ForeignKey(Violation)

124
125
126
    class Admin:
        pass

127
128
129
130
131
132
133
134
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)
135
136
137
138
139
140
141
142
143

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

    class Admin:
        pass

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