models.py 3.38 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
    ('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
34
35
36
37
    ('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
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
54

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

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

71
72
73
74
75
76
77
    class Admin:
        pass

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


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

85
86
87
88
    class Admin:
        pass

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

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

96
97
98
99
100
101
    class Admin:
        pass

    def __unicode__(self):
        return self.name

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

107
108
109
    class Admin:
        pass

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

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

    class Admin:
        pass

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