models.py 3.36 KB
Newer Older
1
from django.db import models
2
from django.utils.translation import ugettext as _
3
from django.contrib.comments.moderation import CommentModerator, moderator
4

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

RESOURCES = (
stef's avatar
stef committed
37
38
39
40
41
42
    ('port', _('port')),
    ('protocol', _('protocol')),
    ('service', _('service')),
    ('site', _('site')),
    ('user', _('user')),
    ('ip', _('ip')),
43
44
    )
TYPES = (
stef's avatar
stef committed
45
46
    ('blocking', _('Blocking')),
    ('throttling', _('Throttling')),
47
48
    )
MEDIA = (
stef's avatar
stef committed
49
50
    ('fixed', _('Fixed')),
    ('mobile', _('Mobile')),
51
    )
52
53

class Violation(models.Model):
54
55
    country = models.CharField(max_length=2, choices=COUNTRIES)
    operator = models.CharField(max_length=256)
stef's avatar
stef committed
56
57
58
59
60
    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)
61
62
    temporary = models.BooleanField( )
    contractual = models.BooleanField()
stef's avatar
stef committed
63
    contract_excerpt = models.TextField(blank=True)
64
    loophole = models.BooleanField()
stef's avatar
stef committed
65
    activationid= models.CharField(max_length=128, blank=True)
stef's avatar
stef committed
66

stef's avatar
stef committed
67
68
69
    def confirmations(self):
        return self.confirmation_set.filter(key='').count()

70
71
72
73
74
75
76
    class Admin:
        pass

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


stef's avatar
stef committed
77
class Comment(models.Model):
78
79
    submitter_email = models.EmailField()
    submitter_name = models.CharField(max_length=20)
stef's avatar
stef committed
80
    comment = models.TextField()
81
    timestamp = models.DateTimeField()
stef's avatar
stef committed
82
83
    violation = models.ForeignKey(Violation)

84
85
86
87
    class Admin:
        pass

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

stef's avatar
stef committed
90
91
class Attachment(models.Model):
    storage = models.FileField(upload_to='static')
92
    name= models.CharField(max_length=512)
stef's avatar
stef committed
93
    comment = models.ForeignKey(Comment)
94

95
96
97
98
99
100
    class Admin:
        pass

    def __unicode__(self):
        return self.name

stef's avatar
stef committed
101
class Confirmation(models.Model):
102
    key=models.CharField(max_length=64, blank=True)
stef's avatar
stef committed
103
104
105
    email=models.EmailField()
    violation = models.ForeignKey(Violation)

106
107
108
    class Admin:
        pass

109
110
111
112
113
114
115
116
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)
117
118
119
120
121
122
123
124
125

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

    class Admin:
        pass

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