This repository has been archived by the owner on Jul 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ban_submission.py
93 lines (81 loc) · 2.23 KB
/
ban_submission.py
1
2
3
4
5
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
'''
:copyright: (c) 2012 by the dot2code Team, see AUTHORS.txt for more details.
:license: GPL, see LICENSE.txt for more details.
'''
from __future__ import absolute_import
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.utils.translation import ugettext_lazy as _
from varnish_bans_manager.core.models import User
from varnish_bans_manager.core.models.base import Model
class BanSubmission(Model):
BASIC_TYPE = 1
ADVANCED_TYPE = 2
EXPERT_TYPE = 3
BAN_TYPE_CHOICES = (
(BASIC_TYPE, _('basic')),
(ADVANCED_TYPE, _('advanced')),
(EXPERT_TYPE, _('expert')),
)
user = models.ForeignKey(
User,
related_name='ban_submissions',
null=False
)
launched_at = models.DateTimeField(
null=False
)
ban_type = models.PositiveSmallIntegerField(
null=False,
choices=BAN_TYPE_CHOICES
)
expression = models.CharField(
max_length=2048,
null=False
)
target_content_type = models.ForeignKey(ContentType)
target_id = models.PositiveIntegerField()
target = generic.GenericForeignKey('target_content_type', 'target_id')
created_at = models.DateTimeField(
auto_now_add=True,
null=False
)
updated_at = models.DateTimeField(
auto_now=True,
null=False
)
def _human_ban_type_name(self):
return dict(self.BAN_TYPE_CHOICES)[self.ban_type]
human_ban_type_name = property(_human_ban_type_name)
class Meta:
app_label = 'core'
class BanSubmissionItem(Model):
ban_submission = models.ForeignKey(
BanSubmission,
related_name='items',
null=False
)
node = models.ForeignKey(
'core.Node',
related_name='ban_submission_items',
null=False
)
success = models.BooleanField(
null=False
)
message = models.CharField(
max_length=1024,
null=True
)
created_at = models.DateTimeField(
auto_now_add=True,
null=False
)
updated_at = models.DateTimeField(
auto_now=True,
null=False
)
class Meta:
app_label = 'core'