|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright 2013 Mathias WOLFF |
|
3
|
|
|
# This file is part of pyfreebilling. |
|
4
|
|
|
# |
|
5
|
|
|
# pyfreebilling is free software: you can redistribute it and/or modify |
|
6
|
|
|
# it under the terms of the GNU General Public License as published by |
|
7
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
# (at your option) any later version. |
|
9
|
|
|
# |
|
10
|
|
|
# pyfreebilling is distributed in the hope that it will be useful, |
|
11
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
# GNU General Public License for more details. |
|
14
|
|
|
# |
|
15
|
|
|
# You should have received a copy of the GNU General Public License |
|
16
|
|
|
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/> |
|
17
|
|
|
|
|
18
|
|
|
from django.db import models |
|
19
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
class NormalizationGroup(models.Model): |
|
|
|
|
|
|
23
|
|
|
"""NormalizationRuleGroup table""" |
|
24
|
|
|
name = models.CharField( |
|
25
|
|
|
_(u'Rule Group name'), |
|
26
|
|
|
max_length=30) |
|
27
|
|
|
description = models.TextField( |
|
28
|
|
|
_(u'description'), |
|
29
|
|
|
blank=True) |
|
30
|
|
|
date_added = models.DateTimeField( |
|
31
|
|
|
_(u'date added'), |
|
32
|
|
|
auto_now_add=True) |
|
33
|
|
|
date_modified = models.DateTimeField( |
|
34
|
|
|
_(u'date modified'), |
|
35
|
|
|
auto_now=True) |
|
36
|
|
|
|
|
37
|
|
|
class Meta: |
|
38
|
|
|
db_table = 'normalization_grp' |
|
39
|
|
|
app_label = 'normalizationrule' |
|
40
|
|
|
ordering = ('name',) |
|
41
|
|
|
verbose_name = _(u'Normalization Group') |
|
42
|
|
|
verbose_name_plural = _(u'Normalization Groups') |
|
43
|
|
|
|
|
44
|
|
|
def __unicode__(self): |
|
45
|
|
|
return u"%s" % (self.name) |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
class NormalizationRule(models.Model): |
|
49
|
|
|
""" Normalization rules table """ |
|
50
|
|
|
name = models.CharField( |
|
51
|
|
|
_(u'rule title'), |
|
52
|
|
|
max_length=30) |
|
53
|
|
|
DEFAULT_MATCH = ( |
|
54
|
|
|
(0, _(u'Equal')), |
|
55
|
|
|
(1, _(u'Regex')), |
|
56
|
|
|
) |
|
57
|
|
|
match_op = models.IntegerField( |
|
58
|
|
|
_(u'Type of match (equal or regex)'), |
|
59
|
|
|
choices=DEFAULT_MATCH, |
|
60
|
|
|
default=1) |
|
61
|
|
|
match_exp = models.CharField( |
|
62
|
|
|
_(u"match expression"), |
|
63
|
|
|
blank=True, |
|
64
|
|
|
default='', |
|
65
|
|
|
max_length=64, |
|
66
|
|
|
help_text=_(u"""Example : ^(33)[0-9].*""")) |
|
67
|
|
|
match_len = models.IntegerField( |
|
68
|
|
|
_(u'match length'), |
|
69
|
|
|
default=0) |
|
70
|
|
|
subst_exp = models.CharField( |
|
71
|
|
|
_(u"substitution expression"), |
|
72
|
|
|
blank=True, |
|
73
|
|
|
default='', |
|
74
|
|
|
max_length=64, |
|
75
|
|
|
help_text=_(u"""Example : ^(33)([0-9].*)""")) |
|
76
|
|
|
repl_exp = models.CharField( |
|
77
|
|
|
_(u"replacement expression"), |
|
78
|
|
|
blank=True, |
|
79
|
|
|
default='', |
|
80
|
|
|
max_length=64, |
|
81
|
|
|
help_text=_(u"""Example : 0033\1""")) |
|
82
|
|
|
DEFAULT_CALL = ( |
|
83
|
|
|
("", _(u'N/A')), |
|
84
|
|
|
) |
|
85
|
|
|
attrs = models.CharField( |
|
86
|
|
|
_(u"attributes"), |
|
87
|
|
|
blank=True, |
|
88
|
|
|
choices=DEFAULT_CALL, |
|
89
|
|
|
default='', |
|
90
|
|
|
max_length=64, |
|
91
|
|
|
help_text=_(u"""Rule to map specific route - |
|
92
|
|
|
Default set to nothing : N/A - not used""")) |
|
93
|
|
|
description = models.TextField( |
|
94
|
|
|
_(u'description'), |
|
95
|
|
|
blank=True) |
|
96
|
|
|
date_added = models.DateTimeField( |
|
97
|
|
|
_(u'date added'), |
|
98
|
|
|
auto_now_add=True) |
|
99
|
|
|
date_modified = models.DateTimeField( |
|
100
|
|
|
_(u'date modified'), |
|
101
|
|
|
auto_now=True) |
|
102
|
|
|
|
|
103
|
|
|
class Meta: |
|
104
|
|
|
db_table = 'normalization_rule' |
|
105
|
|
|
app_label = 'normalizationrule' |
|
106
|
|
|
ordering = ('name', 'match_exp') |
|
107
|
|
|
verbose_name = _(u'Normalization Rule') |
|
108
|
|
|
verbose_name_plural = _(u'Normalization Rules') |
|
109
|
|
|
|
|
110
|
|
|
def __unicode__(self): |
|
111
|
|
|
return u"%s (%s:%s)" % (self.name, self.match_op, self.match_exp) |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
View Code Duplication |
class NormalizationRuleGroup(models.Model): |
|
|
|
|
|
|
115
|
|
|
""" Customer rates Cards Model """ |
|
116
|
|
|
dpid = models.ForeignKey( |
|
117
|
|
|
NormalizationGroup, |
|
118
|
|
|
verbose_name=_(u"Normalization Group")) |
|
119
|
|
|
pr = models.IntegerField( |
|
120
|
|
|
_(u'priority'), |
|
121
|
|
|
help_text=_(u"""Rule order""")) |
|
122
|
|
|
rule = models.ForeignKey( |
|
123
|
|
|
NormalizationRule, |
|
124
|
|
|
verbose_name=_(u"Normalization Rule")) |
|
125
|
|
|
description = models.TextField( |
|
126
|
|
|
_(u'description'), |
|
127
|
|
|
blank=True) |
|
128
|
|
|
date_added = models.DateTimeField( |
|
129
|
|
|
_(u'date added'), |
|
130
|
|
|
auto_now_add=True) |
|
131
|
|
|
date_modified = models.DateTimeField( |
|
132
|
|
|
_(u'date modified'), |
|
133
|
|
|
auto_now=True) |
|
134
|
|
|
|
|
135
|
|
|
class Meta: |
|
136
|
|
|
db_table = 'normalization_rule_grp' |
|
137
|
|
|
app_label = 'normalizationrule' |
|
138
|
|
|
ordering = ('dpid', 'pr') |
|
139
|
|
|
unique_together = (("dpid", "pr"),) |
|
140
|
|
|
verbose_name = _(u'Normalization Rule-Group') |
|
141
|
|
|
verbose_name_plural = _(u'Normalization Rules-Groups') |
|
142
|
|
|
|
|
143
|
|
|
def __unicode__(self): |
|
144
|
|
|
return u"%s - Priority: %s Rule: %s" % (self.dpid, |
|
145
|
|
|
self.pr, |
|
146
|
|
|
self.rule) |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
class CallMappingRule(models.Model): |
|
150
|
|
|
""" Normalization rules table """ |
|
151
|
|
|
name = models.CharField( |
|
152
|
|
|
_(u'rule title'), |
|
153
|
|
|
max_length=30) |
|
154
|
|
|
dpid = models.IntegerField( |
|
155
|
|
|
_(u'Dialplan id'), |
|
156
|
|
|
default=0, |
|
157
|
|
|
help_text=_(u"""Need to be 0, instead of the rule |
|
158
|
|
|
will not be used""")) |
|
159
|
|
|
pr = models.IntegerField( |
|
160
|
|
|
_(u'Priority rule'), |
|
161
|
|
|
unique=True, |
|
162
|
|
|
help_text=_(u"""Priority of rule""")) |
|
163
|
|
|
|
|
164
|
|
|
DEFAULT_MATCH = ( |
|
165
|
|
|
(0, _(u'Equal')), |
|
166
|
|
|
(1, _(u'Regex')), |
|
167
|
|
|
) |
|
168
|
|
|
match_op = models.IntegerField( |
|
169
|
|
|
_(u'Type of match (equal or regex)'), |
|
170
|
|
|
choices=DEFAULT_MATCH, |
|
171
|
|
|
default=1) |
|
172
|
|
|
match_exp = models.CharField( |
|
173
|
|
|
_(u"match expression"), |
|
174
|
|
|
blank=True, |
|
175
|
|
|
default='', |
|
176
|
|
|
max_length=64, |
|
177
|
|
|
help_text=_(u"""Example : ^(33)[0-9].*""")) |
|
178
|
|
|
match_len = models.IntegerField( |
|
179
|
|
|
_(u'match length'), |
|
180
|
|
|
default=0) |
|
181
|
|
|
subst_exp = models.CharField( |
|
182
|
|
|
_(u"subst prefix"), |
|
183
|
|
|
blank=True, |
|
184
|
|
|
default='', |
|
185
|
|
|
max_length=64, |
|
186
|
|
|
help_text=_(u"""Example : ^(33)([0-9].*)""")) |
|
187
|
|
|
repl_exp = models.CharField( |
|
188
|
|
|
_(u"replacement prefix"), |
|
189
|
|
|
blank=True, |
|
190
|
|
|
default='', |
|
191
|
|
|
max_length=64, |
|
192
|
|
|
help_text=_(u"""Example : 0033\1""")) |
|
193
|
|
|
DEFAULT_CALL = ( |
|
194
|
|
|
("", _(u'N/A')), |
|
195
|
|
|
("PSTN", _(u'PSTN')), |
|
196
|
|
|
("EMERGENCY", _(u'EMERGENCY NUMBER')), |
|
197
|
|
|
("OWN", _(u'OWN NUMBERS')), |
|
198
|
|
|
("SPEEDDIAL", _(u'SPEED DIAL')), |
|
199
|
|
|
("DROP", _(u'DROP NUMBERS')), |
|
200
|
|
|
) |
|
201
|
|
|
attrs = models.CharField( |
|
202
|
|
|
_(u"attributes"), |
|
203
|
|
|
blank=True, |
|
204
|
|
|
choices=DEFAULT_CALL, |
|
205
|
|
|
default='', |
|
206
|
|
|
max_length=64, |
|
207
|
|
|
help_text=_(u"""Rule to map specific route - |
|
208
|
|
|
Default set to nothing : N/A""")) |
|
209
|
|
|
description = models.TextField( |
|
210
|
|
|
_(u'description'), |
|
211
|
|
|
blank=True) |
|
212
|
|
|
date_added = models.DateTimeField( |
|
213
|
|
|
_(u'date added'), |
|
214
|
|
|
auto_now_add=True) |
|
215
|
|
|
date_modified = models.DateTimeField( |
|
216
|
|
|
_(u'date modified'), |
|
217
|
|
|
auto_now=True) |
|
218
|
|
|
|
|
219
|
|
|
class Meta: |
|
220
|
|
|
db_table = 'call_mapping_rule' |
|
221
|
|
|
app_label = 'normalizationrule' |
|
222
|
|
|
ordering = ('pr',) |
|
223
|
|
|
unique_together = (("dpid", "pr"),) |
|
224
|
|
|
verbose_name = _(u'Call Mapping Rule') |
|
225
|
|
|
verbose_name_plural = _(u'Call Mapping Rules') |
|
226
|
|
|
|
|
227
|
|
|
def __unicode__(self): |
|
228
|
|
|
return u"%s- %s %s (%s/%s) %s" % ( |
|
229
|
|
|
self.id, |
|
230
|
|
|
self.name, |
|
231
|
|
|
self.pr, |
|
232
|
|
|
self.match_op, |
|
233
|
|
|
self.match_exp, |
|
234
|
|
|
self.attrs) |
|
235
|
|
|
|