models.py 3.08 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
24
25
26
27
28
29
30
31
32
33
34
35
    ('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')),
    ('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
36
37
38
39
40
41
    ('port', _('port')),
    ('protocol', _('protocol')),
    ('service', _('service')),
    ('site', _('site')),
    ('user', _('user')),
    ('ip', _('ip')),
42
43
    )
TYPES = (
stef's avatar
stef committed
44
45
    ('blocking', _('Blocking')),
    ('throttling', _('Throttling')),
46
47
    )
MEDIA = (
stef's avatar
stef committed
48
49
    ('fixed', _('Fixed')),
    ('mobile', _('Mobile')),
50
    )
51
52

class Violation(models.Model):
53
54
55
    country = models.CharField(max_length=2, choices=COUNTRIES)
    operator = models.CharField(max_length=256)
    contract = models.CharField(max_length=256)
stef's avatar
stef committed
56
    resource = models.CharField(max_length=20, choices=RESOURCES)
57
    resource_name = models.CharField(max_length=4096)
stef's avatar
stef committed
58
59
    type = models.CharField(max_length=20, choices=TYPES)
    media = models.CharField( max_length=20, choices=MEDIA)
60
61
62
63
    temporary = models.BooleanField( )
    contractual = models.BooleanField()
    contract_excerpt = models.TextField()
    loophole = models.BooleanField()
64
    activationid= models.CharField(max_length=128)
stef's avatar
stef committed
65

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

69
70
71
72
73
74
75
    class Admin:
        pass

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


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

83
84
85
86
87
88
    class Admin:
        pass

    def __unicode__(self):
        return "Comment #%s" % (self.pk)

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

94
95
96
97
98
99
    class Admin:
        pass

    def __unicode__(self):
        return self.name

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

105
106
107
    class Admin:
        pass

108
109
110
111
112
113
114
115
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)