|
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.contrib import admin |
|
19
|
|
|
from django.contrib import messages |
|
20
|
|
|
from django.contrib.contenttypes import generic |
|
21
|
|
|
# from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION |
|
22
|
|
|
from django.utils.html import escape |
|
23
|
|
|
from django.core.urlresolvers import reverse |
|
24
|
|
|
from django.contrib.admin.views.main import ChangeList |
|
25
|
|
|
from django.forms.models import BaseInlineFormSet |
|
26
|
|
|
from django.template import Context, loader |
|
27
|
|
|
from django.utils.safestring import mark_safe |
|
28
|
|
|
from django.conf import settings |
|
29
|
|
|
from django.utils.translation import ugettext_lazy as _ |
|
30
|
|
|
|
|
31
|
|
|
from datetime import date |
|
32
|
|
|
import datetime |
|
33
|
|
|
|
|
34
|
|
|
from yawdadmin import admin_site |
|
35
|
|
|
from yawdadmin.admin import SortableModelAdmin |
|
36
|
|
|
|
|
37
|
|
|
from import_export.admin import ImportExportMixin, ExportMixin, ImportMixin |
|
38
|
|
|
from import_export.formats import base_formats |
|
39
|
|
|
|
|
40
|
|
|
from switch import esl |
|
41
|
|
|
|
|
42
|
|
|
from pyfreebill.models import * |
|
43
|
|
|
from pyfreebill.forms import CustomerRateCardsAdminForm, CompanyAdminForm, CustomerRatesAdminForm, ProviderRatesAdminForm, ProviderTariffAdminForm, RateCardAdminForm, CustomerDirectoryAdminForm |
|
44
|
|
|
from pyfreebill.resources import CDRResourceExtra, CalleridPrefixResource |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
APP_LABEL = _(u'CDR report') |
|
48
|
|
|
|
|
49
|
|
|
DEFAULT_FORMATS = (base_formats.CSV, ) |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
def sofiaupdate(modeladmin, request, queryset): |
|
53
|
|
View Code Duplication |
""" generate new sofia xml config file """ |
|
|
|
|
|
|
54
|
|
|
try: |
|
55
|
|
|
t = loader.get_template('xml/sofia.conf.xml') |
|
56
|
|
|
except IOError: |
|
57
|
|
|
messages.error(request, |
|
58
|
|
|
_(u"""sofia config xml file update failed. Can not load |
|
59
|
|
|
template file !""")) |
|
60
|
|
|
sipprofiles = SipProfile.objects.all() |
|
61
|
|
|
accounts = Company.objects.filter(supplier_enabled=True) |
|
62
|
|
|
c = Context({"sipprofiles": sipprofiles, "accounts": accounts}) |
|
63
|
|
|
try: |
|
64
|
|
|
f = open('/usr/local/freeswitch/conf/autoload_configs/sofia.conf.xml', |
|
65
|
|
|
'w') |
|
66
|
|
|
try: |
|
67
|
|
|
f.write(t.render(c)) |
|
68
|
|
|
f.close() |
|
69
|
|
|
try: |
|
70
|
|
|
fs = esl.getReloadGateway() |
|
71
|
|
|
messages.success(request, _(u"FS successfully reload")) |
|
72
|
|
|
except IOError: |
|
73
|
|
|
messages.error(request, _(u"""customer sip config xml file update |
|
74
|
|
|
failed. FS ACL update failed ! Try manually -- %s""" % fs)) |
|
75
|
|
|
finally: |
|
76
|
|
|
#f.close() |
|
77
|
|
|
messages.success(request, _(u"sofia config xml file update success")) |
|
78
|
|
|
except IOError: |
|
79
|
|
|
messages.error(request, _(u"""sofia config xml file update failed. Can |
|
80
|
|
|
not create file !""")) |
|
81
|
|
|
sofiaupdate.short_description = _(u"update sofia config xml file") |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
def directoryupdate(modeladmin, request, queryset): |
|
85
|
|
View Code Duplication |
""" generate new directory xml config file """ |
|
|
|
|
|
|
86
|
|
|
try: |
|
87
|
|
|
t = loader.get_template('xml/directory.conf.xml') |
|
88
|
|
|
except IOError: |
|
89
|
|
|
messages.error(request, _(u"""customer sip config xml file update failed. |
|
90
|
|
|
Can not load template file !""")) |
|
91
|
|
|
customerdirectorys = CustomerDirectory.objects.filter(company__customer_enabled__exact=True, enabled=True) |
|
92
|
|
|
accounts = Company.objects.filter(customer_enabled=True) |
|
93
|
|
|
c = Context({"customerdirectorys": customerdirectorys, |
|
94
|
|
|
"accounts": accounts}) |
|
95
|
|
|
try: |
|
96
|
|
|
f = open('/usr/local/freeswitch/conf/directory/default.xml', 'w') |
|
97
|
|
|
try: |
|
98
|
|
|
f.write(t.render(c)) |
|
99
|
|
|
f.close() |
|
100
|
|
|
try: |
|
101
|
|
|
fs = esl.getReloadACL() |
|
102
|
|
|
messages.success(request, _(u"FS successfully reload")) |
|
103
|
|
|
except IOError: |
|
104
|
|
|
messages.error(request, _(u"""customer sip config xml file update |
|
105
|
|
|
failed. FS ACL update failed ! Try manually - %s""" % fs)) |
|
106
|
|
|
finally: |
|
107
|
|
|
#f.close() |
|
108
|
|
|
messages.success(request, _(u"""customer sip config xml file update |
|
109
|
|
|
success""")) |
|
110
|
|
|
except IOError: |
|
111
|
|
|
messages.error(request, _(u"""customer sip config xml file update failed. |
|
112
|
|
|
Can not create file !""")) |
|
113
|
|
|
directoryupdate.short_description = _(u"update customer sip config xml file") |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
def aclupdate(modeladmin, request, queryset): |
|
117
|
|
View Code Duplication |
""" generate new ACL xml config file """ |
|
|
|
|
|
|
118
|
|
|
try: |
|
119
|
|
|
t = loader.get_template('xml/acl.conf.xml') |
|
120
|
|
|
except IOError: |
|
121
|
|
|
messages.error(request, _(u"""ACL config xml file update failed. Can |
|
122
|
|
|
not load template file !""")) |
|
123
|
|
|
acllists = AclLists.objects.all() |
|
124
|
|
|
aclnodes = AclNodes.objects.all() |
|
125
|
|
|
c = Context({"acllists": acllists, "aclnodes": aclnodes}) |
|
126
|
|
|
try: |
|
127
|
|
|
f = open('/usr/local/freeswitch/conf/autoload_configs/acl.conf.xml', |
|
128
|
|
|
'w') |
|
129
|
|
|
try: |
|
130
|
|
|
f.write(t.render(c)) |
|
131
|
|
|
f.close() |
|
132
|
|
|
try: |
|
133
|
|
|
fs = esl.getReloadACL() |
|
134
|
|
|
messages.success(request, _(u"FS successfully reload")) |
|
135
|
|
|
except IOError: |
|
136
|
|
|
messages.error(request, _(u"""ACL config xml file update failed. |
|
137
|
|
|
FS ACL update failed ! Try manually--- %s""" % fs)) |
|
138
|
|
|
finally: |
|
139
|
|
|
messages.success(request, _(u"ACL config xml file update success")) |
|
140
|
|
|
except IOError: |
|
141
|
|
|
messages.error(request, _(u"""ACL xml file update failed. Can not |
|
142
|
|
|
create file !""")) |
|
143
|
|
|
aclupdate.short_description = _(u"update ACL config xml file") |
|
144
|
|
|
|
|
145
|
|
|
admin.site.add_action(directoryupdate, _(u"""generate customer sip |
|
146
|
|
|
configuration file""")) |
|
147
|
|
|
admin.site.add_action(sofiaupdate, _(u"generate sofia configuration file")) |
|
148
|
|
|
admin.site.add_action(aclupdate, _(u"generate acl configuration file")) |
|
149
|
|
|
|
|
150
|
|
|
# Company - Contatcs |
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
class EmailAddressInline(generic.GenericTabularInline): |
|
154
|
|
|
model = EmailAddress |
|
155
|
|
|
extra = 0 |
|
156
|
|
|
collapse = True |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
class PhoneNumberInline(generic.GenericTabularInline): |
|
160
|
|
|
model = PhoneNumber |
|
161
|
|
|
extra = 0 |
|
162
|
|
|
collapse = True |
|
163
|
|
|
title_icon = 'fa-phone-square' |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
class WebSiteInline(generic.GenericTabularInline): |
|
167
|
|
|
model = WebSite |
|
168
|
|
|
extra = 0 |
|
169
|
|
|
collapse = True |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
class StreetAddressInline(generic.GenericStackedInline): |
|
173
|
|
|
model = StreetAddress |
|
174
|
|
|
extra = 0 |
|
175
|
|
|
collapse = True |
|
176
|
|
|
modal = True |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
class CustomerRateCardsInline(admin.StackedInline): |
|
180
|
|
|
model = CustomerRateCards |
|
181
|
|
|
description = _(u'select the Ratecards affected to customer account. Order is important !') |
|
182
|
|
|
form = CustomerRateCardsAdminForm |
|
183
|
|
|
max_num = 3 |
|
184
|
|
|
extra = 0 |
|
185
|
|
|
modal = True |
|
186
|
|
|
# sortable = True |
|
187
|
|
|
# sortable_order_field = 'priority' |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
class CompanyAdmin(admin.ModelAdmin): |
|
191
|
|
|
inlines = [ |
|
192
|
|
|
CustomerRateCardsInline, |
|
193
|
|
|
PhoneNumberInline, |
|
194
|
|
|
EmailAddressInline, |
|
195
|
|
|
WebSiteInline, |
|
196
|
|
|
StreetAddressInline, |
|
197
|
|
|
] |
|
198
|
|
|
form = CompanyAdminForm |
|
199
|
|
|
affix = True |
|
200
|
|
|
save_on_top = True |
|
201
|
|
|
title_icon = 'fa-group' |
|
202
|
|
|
|
|
203
|
|
|
search_fields = ['^name', ] |
|
204
|
|
|
prepopulated_fields = {'slug': ('name',)} |
|
205
|
|
|
readonly_fields = ('customer_balance', 'supplier_balance', 'vat_number_validated') |
|
206
|
|
|
fieldsets = ( |
|
207
|
|
|
(_(u'General'), { |
|
208
|
|
|
'fields': (('name', 'nickname'), |
|
209
|
|
|
('slug', 'about'), |
|
210
|
|
|
'account_number', |
|
211
|
|
|
('vat', 'vat_number'), |
|
212
|
|
|
'vat_number_validated'), |
|
213
|
|
|
'description': _(u'General company informations') |
|
214
|
|
|
}), |
|
215
|
|
|
(_(u'Customer settings'), { |
|
216
|
|
|
'fields': ('customer_enabled', |
|
217
|
|
|
('max_calls', 'calls_per_second'), |
|
218
|
|
|
'billing_cycle', |
|
219
|
|
|
('prepaid', 'credit_limit'), |
|
220
|
|
|
('customer_balance', 'cb_currency')), |
|
221
|
|
|
}), |
|
222
|
|
|
(_(u'Customer alerts'), { |
|
223
|
|
|
'fields': ('low_credit_alert', |
|
224
|
|
|
'email_alert', |
|
225
|
|
|
'low_credit_alert_sent', |
|
226
|
|
|
'account_blocked_alert_sent'), |
|
227
|
|
|
'classes': ('collapsed',), |
|
228
|
|
|
'description': _(u'All the customer alert parameters') |
|
229
|
|
|
}), |
|
230
|
|
|
(_(u'Provider settings'), { |
|
231
|
|
|
'fields': ('supplier_enabled', |
|
232
|
|
|
'supplier_balance'), |
|
233
|
|
|
'classes': ('collapsed',), |
|
234
|
|
|
'description': _(u'If this company is your provider, this is right place to manage its parameters') |
|
235
|
|
|
}), |
|
236
|
|
|
) |
|
237
|
|
|
|
|
238
|
|
|
def get_customer_enabled_display(self, obj): |
|
239
|
|
|
if obj.customer_enabled: |
|
240
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
241
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
242
|
|
|
get_customer_enabled_display.short_description = _(u'Customer') |
|
243
|
|
|
get_customer_enabled_display.admin_order_field = _(u'customer_enabled') |
|
244
|
|
|
|
|
245
|
|
|
def get_supplier_enabled_display(self, obj): |
|
246
|
|
|
if obj.supplier_enabled: |
|
247
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
248
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
249
|
|
|
get_supplier_enabled_display.short_description = _(u'Provider') |
|
250
|
|
|
get_supplier_enabled_display.admin_order_field = _(u'provider_enabled') |
|
251
|
|
|
|
|
252
|
|
|
def get_prepaid_display(self, obj): |
|
253
|
|
|
if obj.prepaid: |
|
254
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
255
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
256
|
|
|
get_prepaid_display.short_description = _(u'Prepaid') |
|
257
|
|
|
get_prepaid_display.admin_order_field = _(u'prepaid') |
|
258
|
|
|
|
|
259
|
|
|
def get_vat_display(self, obj): |
|
260
|
|
|
if obj.vat: |
|
261
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-thumbs-up"></i> YES</span>') |
|
262
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
263
|
|
|
get_vat_display.short_description = _(u'VAT') |
|
264
|
|
|
get_vat_display.admin_order_field = _(u'vat') |
|
265
|
|
|
|
|
266
|
|
|
def get_vat_number_validated_display(self, obj): |
|
267
|
|
|
if obj.vat_number_validated: |
|
268
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-thumbs-up"></i> YES</span>') |
|
269
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
270
|
|
|
get_vat_number_validated_display.short_description = _(u'VIES') |
|
271
|
|
|
get_vat_number_validated_display.admin_order_field = _(u'vies') |
|
272
|
|
|
|
|
273
|
|
|
def has_add_permission(self, request, obj=None): |
|
274
|
|
|
if request.user.is_superuser: |
|
275
|
|
|
return True |
|
276
|
|
|
else: |
|
277
|
|
|
return False |
|
278
|
|
|
|
|
279
|
|
|
def has_delete_permission(self, request, obj=None): |
|
280
|
|
|
if request.user.is_superuser: |
|
281
|
|
|
return True |
|
282
|
|
|
else: |
|
283
|
|
|
return False |
|
284
|
|
|
|
|
285
|
|
|
def get_actions(self, request): |
|
286
|
|
|
if request.user.is_superuser: |
|
287
|
|
|
actions = super(CompanyAdmin, self).get_actions(request) |
|
288
|
|
|
if 'delete_selected' in actions: |
|
289
|
|
|
del actions['delete_selected'] |
|
290
|
|
|
return actions |
|
291
|
|
|
return |
|
292
|
|
|
|
|
293
|
|
|
def changelist_view(self, request, extra_context=None): |
|
294
|
|
|
if request.user.is_superuser: |
|
295
|
|
|
self.list_display_links = ['name', ] |
|
296
|
|
|
return super(CompanyAdmin, self).changelist_view(request, extra_context=None) |
|
297
|
|
|
else: |
|
298
|
|
|
self.list_display_links = ['None', ] |
|
299
|
|
|
return super(CompanyAdmin, self).changelist_view(request, extra_context=None) |
|
300
|
|
|
|
|
301
|
|
|
def get_list_display(self, request): |
|
302
|
|
|
if request.user.is_superuser: |
|
303
|
|
|
return ('name', |
|
304
|
|
|
'get_prepaid_display', |
|
305
|
|
|
'get_vat_display', |
|
306
|
|
|
'get_vat_number_validated_display', |
|
307
|
|
|
'get_customer_enabled_display', |
|
308
|
|
|
'customer_balance', |
|
309
|
|
|
'cb_currency', |
|
310
|
|
|
'get_supplier_enabled_display', |
|
311
|
|
|
'supplier_balance', |
|
312
|
|
|
'balance_history') |
|
313
|
|
|
else: |
|
314
|
|
|
return ('name', |
|
315
|
|
|
'get_prepaid_display', |
|
316
|
|
|
'get_customer_enabled_display', |
|
317
|
|
|
'customer_balance') |
|
318
|
|
|
|
|
319
|
|
|
# def get_list_filter(self, request): |
|
320
|
|
|
# if request.user.is_superuser: |
|
321
|
|
|
# #return ('name',) |
|
322
|
|
|
# return ['prepaid', 'customer_enabled', 'supplier_enabled'] |
|
323
|
|
|
# else: |
|
324
|
|
|
# return [] |
|
325
|
|
|
|
|
326
|
|
|
def get_readonly_fields(self, request, obj=None): |
|
327
|
|
|
if request.user.is_superuser: |
|
328
|
|
|
return ['customer_balance', |
|
329
|
|
|
'supplier_balance', |
|
330
|
|
|
'low_credit_alert_sent', |
|
331
|
|
|
'account_blocked_alert_sent'] |
|
332
|
|
|
else: |
|
333
|
|
|
return ['name', |
|
334
|
|
|
'prepaid', |
|
335
|
|
|
'customer_enabled', |
|
336
|
|
|
'customer_balance', |
|
337
|
|
|
'vat_number', |
|
338
|
|
|
'max_calls', |
|
339
|
|
|
'billing_cycle'] |
|
340
|
|
|
|
|
341
|
|
|
def get_form(self, request, obj=None, **kwargs): |
|
342
|
|
|
self.exclude = [] |
|
343
|
|
|
if not request.user.is_superuser: |
|
344
|
|
|
self.exclude.append('supplier_enabled') |
|
345
|
|
|
self.exclude.append('supplier_balance') |
|
346
|
|
|
self.exclude.append('vat') |
|
347
|
|
|
self.exclude.append('nickname') |
|
348
|
|
|
self.exclude.append('slug') |
|
349
|
|
|
self.exclude.append('about') |
|
350
|
|
|
|
|
351
|
|
|
return super(CompanyAdmin, self).get_form(request, obj, **kwargs) |
|
352
|
|
|
|
|
353
|
|
|
def queryset(self, request): |
|
354
|
|
|
user = getattr(request, 'user', None) |
|
355
|
|
|
qs = super(CompanyAdmin, self).queryset(request) |
|
356
|
|
|
if user.is_superuser: |
|
357
|
|
|
return qs |
|
358
|
|
|
else: |
|
359
|
|
|
usercompany = Person.objects.get(user=user) |
|
360
|
|
|
return qs.filter(name=usercompany.company) |
|
361
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
class PersonAdmin(admin.ModelAdmin): |
|
364
|
|
|
inlines = [ |
|
365
|
|
|
PhoneNumberInline, |
|
366
|
|
|
] |
|
367
|
|
|
|
|
368
|
|
|
list_display_links = ('first_name', |
|
369
|
|
|
'last_name') |
|
370
|
|
|
list_display = ('first_name', |
|
371
|
|
|
'last_name', |
|
372
|
|
|
'company') |
|
373
|
|
|
list_filter = ('company', ) |
|
374
|
|
|
ordering = ('last_name', |
|
375
|
|
|
'first_name') |
|
376
|
|
|
search_fields = ['^first_name', |
|
377
|
|
|
'^last_name', |
|
378
|
|
|
'^company__name'] |
|
379
|
|
|
prepopulated_fields = {'slug': ('first_name', 'last_name')} |
|
380
|
|
|
|
|
381
|
|
|
def has_change_permission(self, request, obj=None): |
|
382
|
|
|
if request.user.is_superuser: |
|
383
|
|
|
return True |
|
384
|
|
|
else: |
|
385
|
|
|
return False |
|
386
|
|
|
|
|
387
|
|
|
|
|
388
|
|
|
class GroupAdmin(admin.ModelAdmin): |
|
389
|
|
|
list_display_links = ('name', ) |
|
390
|
|
|
list_display = ('name', |
|
391
|
|
|
'date_modified') |
|
392
|
|
|
ordering = ('-date_modified', |
|
393
|
|
|
'name') |
|
394
|
|
|
search_fields = ['^name', |
|
395
|
|
|
'^about'] |
|
396
|
|
|
prepopulated_fields = {'slug': ('name',)} |
|
397
|
|
|
|
|
398
|
|
|
def has_change_permission(self, request, obj=None): |
|
399
|
|
|
if request.user.is_superuser: |
|
400
|
|
|
return True |
|
401
|
|
|
else: |
|
402
|
|
|
return False |
|
403
|
|
|
|
|
404
|
|
|
|
|
405
|
|
|
class CompanyBalanceHistoryAdmin(admin.ModelAdmin): |
|
406
|
|
|
list_display_links = ('company', ) |
|
407
|
|
|
list_display = ('company', |
|
408
|
|
|
'amount_debited', |
|
409
|
|
|
'amount_refund', |
|
410
|
|
|
'customer_balance', |
|
411
|
|
|
'supplier_balance', |
|
412
|
|
|
'operation_type', |
|
413
|
|
|
'reference', |
|
414
|
|
|
'date_modified') |
|
415
|
|
|
ordering = ('-date_modified', |
|
416
|
|
|
'company') |
|
417
|
|
|
search_fields = ['^company__name', |
|
418
|
|
|
'^reference'] |
|
419
|
|
|
|
|
420
|
|
|
def save_model(self, request, obj, form, change): |
|
421
|
|
|
if change: |
|
422
|
|
|
messages.info(request, _(u"No need to update balance")) |
|
423
|
|
|
else: |
|
424
|
|
|
company = form.cleaned_data['company'] |
|
425
|
|
|
amount_debited = form.cleaned_data['amount_debited'] |
|
426
|
|
|
amount_refund = form.cleaned_data['amount_refund'] |
|
427
|
|
|
if form.cleaned_data['operation_type'] == "customer": |
|
428
|
|
|
balance = Company.objects.get(pk=company.id) |
|
429
|
|
|
balance.customer_balance = balance.customer_balance - amount_debited + amount_refund |
|
430
|
|
|
balance.save() |
|
431
|
|
|
obj.customer_balance = balance.customer_balance |
|
432
|
|
|
elif form.cleaned_data['operation_type'] == "supplier": |
|
433
|
|
|
balance = Company.objects.get(pk=company.id) |
|
434
|
|
|
balance.supplier_balance = balance.supplier_balance - amount_debited + amount_refund |
|
435
|
|
|
balance.save() |
|
436
|
|
|
obj.supplier_balance = balance.supplier_balance |
|
437
|
|
|
else: |
|
438
|
|
|
pass |
|
439
|
|
|
messages.success(request, _(u"balance updated")) |
|
440
|
|
|
obj.save() |
|
441
|
|
|
|
|
442
|
|
|
fieldsets = ( |
|
443
|
|
|
(_(u'General'), { |
|
444
|
|
|
'fields': ('company', |
|
445
|
|
|
'operation_type', |
|
446
|
|
|
'reference', |
|
447
|
|
|
'description')}), |
|
448
|
|
|
(_(u'Amount'), { |
|
449
|
|
|
'fields': ('amount_debited', |
|
450
|
|
|
'amount_refund')}), |
|
451
|
|
|
(_(u'Balances'), { |
|
452
|
|
|
'fields': ('customer_balance', |
|
453
|
|
|
'supplier_balance')}), |
|
454
|
|
|
) |
|
455
|
|
|
|
|
456
|
|
|
def get_list_filter(self, request): |
|
457
|
|
|
if request.user.is_superuser: |
|
458
|
|
|
return ['company', 'operation_type'] |
|
459
|
|
|
else: |
|
460
|
|
|
return [] |
|
461
|
|
|
|
|
462
|
|
|
def has_change_permission(self, request, obj=None): |
|
463
|
|
|
if request.user.is_superuser: |
|
464
|
|
|
return True |
|
465
|
|
|
else: |
|
466
|
|
|
return False |
|
467
|
|
|
|
|
468
|
|
|
def has_delete_permission(self, request, obj=None): |
|
469
|
|
|
return False |
|
470
|
|
|
|
|
471
|
|
|
def get_actions(self, request): |
|
472
|
|
|
if request.user.is_superuser: |
|
473
|
|
|
return |
|
474
|
|
|
else: |
|
475
|
|
|
return |
|
476
|
|
|
|
|
477
|
|
|
def get_readonly_fields(self, request, obj=None): |
|
478
|
|
|
if obj: # This is the case when obj is already created. it's an edit |
|
479
|
|
|
return ['company', |
|
480
|
|
|
'amount_debited', |
|
481
|
|
|
'amount_refund', |
|
482
|
|
|
'customer_balance', |
|
483
|
|
|
'supplier_balance', |
|
484
|
|
|
'operation_type'] |
|
485
|
|
|
else: |
|
486
|
|
|
return ['customer_balance', 'supplier_balance'] |
|
487
|
|
|
|
|
488
|
|
|
# CallerID prefix list |
|
489
|
|
|
|
|
490
|
|
|
|
|
491
|
|
|
class CalleridPrefixAdmin(ImportMixin, admin.ModelAdmin): |
|
492
|
|
|
list_display = ['calleridprefixlist', |
|
493
|
|
|
'prefix', |
|
494
|
|
|
'date_added', |
|
495
|
|
|
'date_modified'] |
|
496
|
|
|
ordering = ('calleridprefixlist', |
|
497
|
|
|
'prefix') |
|
498
|
|
|
list_filter = ('calleridprefixlist', ) |
|
499
|
|
|
search_fields = ('^prefix', ) |
|
500
|
|
|
resource_class = CalleridPrefixResource |
|
501
|
|
|
|
|
502
|
|
|
def has_change_permission(self, request, obj=None): |
|
503
|
|
|
if request.user.is_superuser: |
|
504
|
|
|
return True |
|
505
|
|
|
else: |
|
506
|
|
|
return False |
|
507
|
|
|
|
|
508
|
|
|
def get_import_formats(self): |
|
509
|
|
|
format_csv = DEFAULT_FORMATS |
|
510
|
|
|
return [f for f in format_csv if f().can_import()] |
|
511
|
|
|
|
|
512
|
|
|
|
|
513
|
|
|
class CalleridPrefixListAdmin(admin.ModelAdmin): |
|
514
|
|
|
list_display = ['name', |
|
515
|
|
|
'description', |
|
516
|
|
|
'prefix', |
|
517
|
|
|
'date_added', |
|
518
|
|
|
'date_modified'] |
|
519
|
|
|
ordering = ('name', ) |
|
520
|
|
|
list_filter = ['name', ] |
|
521
|
|
|
search_fields = ('^name', |
|
522
|
|
|
'description') |
|
523
|
|
|
|
|
524
|
|
|
def has_change_permission(self, request, obj=None): |
|
525
|
|
|
if request.user.is_superuser: |
|
526
|
|
|
return True |
|
527
|
|
|
else: |
|
528
|
|
|
return False |
|
529
|
|
|
|
|
530
|
|
|
# Provider Rates |
|
531
|
|
|
|
|
532
|
|
|
|
|
533
|
|
|
class ProviderRatesFormSet(BaseInlineFormSet): |
|
534
|
|
|
|
|
535
|
|
|
def get_queryset(self): |
|
536
|
|
|
qs = super(ProviderRatesFormSet, self).get_queryset() |
|
537
|
|
|
return qs[:40] |
|
538
|
|
|
|
|
539
|
|
|
|
|
540
|
|
|
class ProviderRatesInline(admin.TabularInline): |
|
541
|
|
|
model = ProviderRates |
|
542
|
|
|
formset = ProviderRatesFormSet |
|
543
|
|
|
max_count = 40 |
|
544
|
|
|
extra = 1 |
|
545
|
|
|
|
|
546
|
|
|
|
|
547
|
|
|
class ProviderTariffAdmin(admin.ModelAdmin): |
|
548
|
|
|
list_display = ['id', |
|
549
|
|
|
'name', |
|
550
|
|
|
'carrier', |
|
551
|
|
|
'currency', |
|
552
|
|
|
'prefix', |
|
553
|
|
|
'quality', |
|
554
|
|
|
'reliability', |
|
555
|
|
|
'date_start', |
|
556
|
|
|
'date_end', |
|
557
|
|
|
'get_boolean_display', |
|
558
|
|
|
'rates'] |
|
559
|
|
|
ordering = ['name', ] |
|
560
|
|
|
readonly_fields = ['id', ] |
|
561
|
|
|
form = ProviderTariffAdminForm |
|
562
|
|
|
|
|
563
|
|
|
def get_boolean_display(self, obj): |
|
564
|
|
|
if obj.enabled: |
|
565
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
566
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-down"></i> NO</span>') |
|
567
|
|
|
get_boolean_display.short_description = _(u'Enabled') |
|
568
|
|
|
get_boolean_display.admin_order_field = _(u'enabled') |
|
569
|
|
|
|
|
570
|
|
|
def has_change_permission(self, request, obj=None): |
|
571
|
|
|
if request.user.is_superuser: |
|
572
|
|
|
return True |
|
573
|
|
|
else: |
|
574
|
|
|
return False |
|
575
|
|
|
|
|
576
|
|
|
|
|
577
|
|
View Code Duplication |
class ProviderRatesAdmin(ImportExportMixin, admin.ModelAdmin): |
|
|
|
|
|
|
578
|
|
|
list_display = ['id', |
|
579
|
|
|
'provider_tariff', |
|
580
|
|
|
'destination', |
|
581
|
|
|
'digits', |
|
582
|
|
|
'cost_rate', |
|
583
|
|
|
'block_min_duration', |
|
584
|
|
|
'init_block', |
|
585
|
|
|
'date_start', |
|
586
|
|
|
'date_end', |
|
587
|
|
|
'get_boolean_display', |
|
588
|
|
|
'date_added', |
|
589
|
|
|
'date_modified'] |
|
590
|
|
|
ordering = ['provider_tariff', |
|
591
|
|
|
'digits'] |
|
592
|
|
|
list_filter = ['provider_tariff', |
|
593
|
|
|
'enabled', |
|
594
|
|
|
'destination'] |
|
595
|
|
|
search_fields = ['^digits', |
|
596
|
|
|
'date_start', |
|
597
|
|
|
'date_end', |
|
598
|
|
|
'^destination'] |
|
599
|
|
|
actions = ['make_enabled', |
|
600
|
|
|
'make_disabled'] |
|
601
|
|
|
form = ProviderRatesAdminForm |
|
602
|
|
|
|
|
603
|
|
|
def get_boolean_display(self, obj): |
|
604
|
|
|
if obj.enabled: |
|
605
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
606
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-down"></i> NO</span>') |
|
607
|
|
View Code Duplication |
get_boolean_display.short_description = _(u'Enabled') |
|
|
|
|
|
|
608
|
|
|
get_boolean_display.admin_order_field = _(u'enabled') |
|
609
|
|
|
|
|
610
|
|
|
def has_change_permission(self, request, obj=None): |
|
611
|
|
|
if request.user.is_superuser: |
|
612
|
|
|
return True |
|
613
|
|
|
else: |
|
614
|
|
|
return False |
|
615
|
|
|
|
|
616
|
|
|
def make_enabled(self, request, queryset): |
|
617
|
|
|
rows_updated = queryset.update(enabled=True) |
|
618
|
|
|
if rows_updated == 1: |
|
619
|
|
|
message_bit = _(u"1 item was") |
|
620
|
|
|
else: |
|
621
|
|
|
message_bit = _(u"%s items were") % rows_updated |
|
622
|
|
|
self.message_user(request, _(u"%s successfully marked as enabled.") % message_bit) |
|
623
|
|
|
make_enabled.short_description = _(u"mark selected items as enabled") |
|
624
|
|
|
|
|
625
|
|
|
def make_disabled(self, request, queryset): |
|
626
|
|
|
rows_updated = queryset.update(enabled=False) |
|
627
|
|
|
if rows_updated == 1: |
|
628
|
|
|
message_bit = _(u"1 item was") |
|
629
|
|
|
else: |
|
630
|
|
|
message_bit = _(u"%s items were") % rows_updated |
|
631
|
|
|
self.message_user(request, _(u"%s successfully marked as disabled.") % message_bit) |
|
632
|
|
|
make_disabled.short_description = _(u"mark selected items as disabled") |
|
633
|
|
|
|
|
634
|
|
|
def get_import_formats(self): |
|
635
|
|
|
format_csv = DEFAULT_FORMATS |
|
636
|
|
|
return [f for f in format_csv if f().can_import()] |
|
637
|
|
|
|
|
638
|
|
|
def get_export_formats(self): |
|
639
|
|
|
format_csv = DEFAULT_FORMATS |
|
640
|
|
|
return [f for f in format_csv if f().can_export()] |
|
641
|
|
|
|
|
642
|
|
|
# LCR |
|
643
|
|
|
|
|
644
|
|
|
|
|
645
|
|
|
class LCRProvidersInline(admin.TabularInline): |
|
646
|
|
|
model = LCRProviders |
|
647
|
|
|
# formset = LCRProvidersFormSet |
|
648
|
|
|
# fields = ('rates',) |
|
649
|
|
|
extra = 0 |
|
650
|
|
|
|
|
651
|
|
|
|
|
652
|
|
|
class LCRGroupAdmin(admin.ModelAdmin): |
|
653
|
|
|
list_display = ['name', 'description', 'lcrtype'] |
|
654
|
|
|
ordering = ('name', 'lcrtype') |
|
655
|
|
|
list_filter = ('lcrtype',) |
|
656
|
|
|
inlines = [ |
|
657
|
|
|
LCRProvidersInline, |
|
658
|
|
|
] |
|
659
|
|
|
|
|
660
|
|
|
def has_change_permission(self, request, obj=None): |
|
661
|
|
|
if request.user.is_superuser: |
|
662
|
|
|
return True |
|
663
|
|
|
else: |
|
664
|
|
|
return False |
|
665
|
|
|
|
|
666
|
|
|
|
|
667
|
|
|
class LCRProvidersAdmin(admin.ModelAdmin): |
|
668
|
|
|
list_display = ['lcr', 'provider_tariff', 'rates'] |
|
669
|
|
|
list_filter = ('lcr',) |
|
670
|
|
|
|
|
671
|
|
|
def has_change_permission(self, request, obj=None): |
|
672
|
|
|
if request.user.is_superuser: |
|
673
|
|
|
return True |
|
674
|
|
|
else: |
|
675
|
|
|
return False |
|
676
|
|
|
|
|
677
|
|
|
# Customer Rates |
|
678
|
|
|
|
|
679
|
|
|
|
|
680
|
|
|
class CustomerRatesFormSet(BaseInlineFormSet): |
|
681
|
|
|
def get_queryset(self): |
|
682
|
|
|
qs = super(CustomerRatesFormSet, self).get_queryset() |
|
683
|
|
|
return qs[:40] |
|
684
|
|
|
|
|
685
|
|
|
|
|
686
|
|
|
class CustomerRatesInline(admin.TabularInline): |
|
687
|
|
|
model = CustomerRates |
|
688
|
|
|
#formset = CustomerRatesFormSet |
|
689
|
|
|
max_num = 40 |
|
690
|
|
|
extra = 1 |
|
691
|
|
|
|
|
692
|
|
|
|
|
693
|
|
|
class CustomerRatesAdmin(ImportExportMixin, admin.ModelAdmin): |
|
694
|
|
|
list_display = ['id', |
|
695
|
|
|
'ratecard', |
|
696
|
|
|
'destination', |
|
697
|
|
|
'prefix', |
|
698
|
|
|
'rate', |
|
699
|
|
|
'init_block', |
|
700
|
|
|
'block_min_duration', |
|
701
|
|
|
'minimal_time', |
|
702
|
|
|
'date_start', |
|
703
|
|
|
'date_end', |
|
704
|
|
|
'get_boolean_display', |
|
705
|
|
|
'date_added', |
|
706
|
|
|
'date_modified'] |
|
707
|
|
|
ordering = ['ratecard', |
|
708
|
|
|
'prefix'] |
|
709
|
|
|
list_filter = ['ratecard', |
|
710
|
|
|
'enabled', |
|
711
|
|
|
'destination'] |
|
712
|
|
|
search_fields = ['^prefix', |
|
713
|
|
|
'date_start', |
|
714
|
|
|
'date_end', |
|
715
|
|
|
'^destination'] |
|
716
|
|
|
actions = ['make_enabled', 'make_disabled'] |
|
717
|
|
|
readonly_fields = ['id', ] |
|
718
|
|
|
form = CustomerRatesAdminForm |
|
719
|
|
|
|
|
720
|
|
|
def get_boolean_display(self, obj): |
|
721
|
|
|
if obj.enabled: |
|
722
|
|
View Code Duplication |
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
|
|
|
|
|
723
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-down"></i> NO</span>') |
|
724
|
|
|
get_boolean_display.short_description = _(u'Enabled') |
|
725
|
|
|
get_boolean_display.admin_order_field = _(u'enabled') |
|
726
|
|
|
|
|
727
|
|
|
def has_change_permission(self, request, obj=None): |
|
728
|
|
|
if request.user.is_superuser: |
|
729
|
|
|
return True |
|
730
|
|
|
else: |
|
731
|
|
|
return False |
|
732
|
|
|
|
|
733
|
|
|
def make_enabled(self, request, queryset): |
|
734
|
|
|
rows_updated = queryset.update(enabled=True) |
|
735
|
|
|
if rows_updated == 1: |
|
736
|
|
|
message_bit = _(u"1 item was") |
|
737
|
|
|
else: |
|
738
|
|
|
message_bit = _(u"%s items were") % rows_updated |
|
739
|
|
|
self.message_user(request, |
|
740
|
|
|
_(u"%s successfully marked as enabled.") % message_bit) |
|
741
|
|
|
make_enabled.short_description = _(u"mark selected items as enabled") |
|
742
|
|
|
|
|
743
|
|
|
def make_disabled(self, request, queryset): |
|
744
|
|
|
rows_updated = queryset.update(enabled=False) |
|
745
|
|
|
if rows_updated == 1: |
|
746
|
|
|
message_bit = _(u"1 item was") |
|
747
|
|
|
else: |
|
748
|
|
|
message_bit = _(u"%s items were") % rows_updated |
|
749
|
|
|
self.message_user(request, |
|
750
|
|
|
_(u"%s successfully marked as disabled.") % message_bit) |
|
751
|
|
|
make_disabled.short_description = _(u"mark selected items as disabled") |
|
752
|
|
|
|
|
753
|
|
|
def get_import_formats(self): |
|
754
|
|
|
format_csv = DEFAULT_FORMATS |
|
755
|
|
|
return [f for f in format_csv if f().can_import()] |
|
756
|
|
|
|
|
757
|
|
|
def get_export_formats(self): |
|
758
|
|
|
format_csv = DEFAULT_FORMATS |
|
759
|
|
|
return [f for f in format_csv if f().can_export()] |
|
760
|
|
|
|
|
761
|
|
|
|
|
762
|
|
|
class RateCardAdmin(admin.ModelAdmin): |
|
763
|
|
|
list_display = ['id', |
|
764
|
|
|
'name', |
|
765
|
|
|
'currency', |
|
766
|
|
|
'lcrgroup', |
|
767
|
|
|
'lcr', |
|
768
|
|
|
'get_boolean_display', |
|
769
|
|
|
'rates', |
|
770
|
|
|
'callerid_filter', |
|
771
|
|
|
'callerid_list'] |
|
772
|
|
|
ordering = ['name', 'enabled', 'lcrgroup'] |
|
773
|
|
|
list_filter = ['enabled', 'lcrgroup'] |
|
774
|
|
|
search_fields = ['description', '^name'] |
|
775
|
|
|
form = RateCardAdminForm |
|
776
|
|
|
# inlines = [ |
|
777
|
|
|
# CustomerRatesInline, |
|
778
|
|
|
# ] |
|
779
|
|
|
|
|
780
|
|
|
def has_change_permission(self, request, obj=None): |
|
781
|
|
|
if request.user.is_superuser: |
|
782
|
|
|
return True |
|
783
|
|
|
else: |
|
784
|
|
|
return False |
|
785
|
|
|
|
|
786
|
|
|
def get_boolean_display(self, obj): |
|
787
|
|
|
if obj.enabled: |
|
788
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
789
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-down"></i> NO</span>') |
|
790
|
|
View Code Duplication |
get_boolean_display.short_description = _(u'Enabled') |
|
|
|
|
|
|
791
|
|
|
get_boolean_display.admin_order_field = _(u'enabled') |
|
792
|
|
|
|
|
793
|
|
|
|
|
794
|
|
|
class CustomerRateCardsAdmin(SortableModelAdmin): |
|
795
|
|
|
list_display = ['company', |
|
796
|
|
|
'ratecard', |
|
797
|
|
|
'tech_prefix', |
|
798
|
|
|
'priority', |
|
799
|
|
|
'description'] |
|
800
|
|
|
ordering = ['company', ] |
|
801
|
|
|
raw_id_fields = ('ratecard',) |
|
802
|
|
|
list_filter = ['ratecard', 'company'] |
|
803
|
|
|
search_fields = ['^company__company', ] |
|
804
|
|
|
form = form = CustomerRateCardsAdminForm |
|
805
|
|
|
|
|
806
|
|
|
def has_change_permission(self, request, obj=None): |
|
807
|
|
|
if request.user.is_superuser: |
|
808
|
|
|
return True |
|
809
|
|
|
else: |
|
810
|
|
|
return False |
|
811
|
|
|
|
|
812
|
|
|
# CustomerDirectory |
|
813
|
|
|
|
|
814
|
|
|
|
|
815
|
|
|
class CustomerDirectoryAdmin(admin.ModelAdmin): |
|
816
|
|
|
list_display = ['company', |
|
817
|
|
|
'get_registration_display', |
|
818
|
|
|
'name', |
|
819
|
|
|
'sip_ip', |
|
820
|
|
|
'max_calls', |
|
821
|
|
|
'calls_per_second', |
|
822
|
|
|
'get_enabled_display', |
|
823
|
|
|
'get_fake_ring_display', |
|
824
|
|
|
'get_cli_debug_display'] |
|
825
|
|
|
ordering = ['company', 'enabled'] |
|
826
|
|
|
list_filter = ['enabled', ] |
|
827
|
|
|
#list_editable = ['max_calls', 'calls_per_second'] |
|
828
|
|
|
search_filter = ['^sip_ip', '^company', '^name'] |
|
829
|
|
|
exclude = ['vmd', ] |
|
830
|
|
|
form = CustomerDirectoryAdminForm |
|
831
|
|
|
actions = [directoryupdate] |
|
832
|
|
|
save_on_top = True |
|
833
|
|
|
affix = True |
|
834
|
|
|
fieldsets = ( |
|
835
|
|
|
(_(u'General'), { |
|
836
|
|
|
'fields': (('company', |
|
837
|
|
|
'enabled'), |
|
838
|
|
|
('name', |
|
839
|
|
|
'registration'), |
|
840
|
|
|
'max_calls', |
|
841
|
|
|
'calls_per_second', |
|
842
|
|
|
'codecs'), |
|
843
|
|
|
'description': _(u'General sip account informations') |
|
844
|
|
|
}), |
|
845
|
|
|
(_(u'Registration settings'), { |
|
846
|
|
|
'fields': (('password', |
|
847
|
|
|
'multiple_registrations'), |
|
848
|
|
|
'log_auth_failures'), |
|
849
|
|
|
'classes': ('collapsed',), |
|
850
|
|
|
'description': _(u'If registration, you must set a password') |
|
851
|
|
|
}), |
|
852
|
|
|
(_(u'IP Settings'), { |
|
853
|
|
|
'fields': (('sip_ip', |
|
854
|
|
|
'sip_port'), |
|
855
|
|
|
'rtp_ip'), |
|
856
|
|
|
'classes': ('collapsed',), |
|
857
|
|
|
'description': _(u'If no registration, SIP IP CIDR is needed') |
|
858
|
|
|
}), |
|
859
|
|
|
(_(u'Description'), { |
|
860
|
|
|
'fields': ('description',), |
|
861
|
|
|
'classes': ('collapsed',), |
|
862
|
|
|
'description': _(u'description informations') |
|
863
|
|
|
}), |
|
864
|
|
|
(_(u'Advanced settings'), { |
|
865
|
|
|
'fields': (('outbound_caller_id_name', |
|
866
|
|
|
'outbound_caller_id_number'), |
|
867
|
|
|
'ignore_early_media', |
|
868
|
|
|
'fake_ring', |
|
869
|
|
|
'cli_debug'), |
|
870
|
|
|
'classes': ('collapsed',), |
|
871
|
|
|
'description': _(u'Advanced parameters') |
|
872
|
|
|
}), |
|
873
|
|
|
) |
|
874
|
|
|
|
|
875
|
|
|
def get_registration_display(self, obj): |
|
876
|
|
|
if obj.registration: |
|
877
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-ok-sign"></i> Registration</span>') |
|
878
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-minus-sign"></i> IP Auth</span>') |
|
879
|
|
|
get_registration_display.short_description = _(u'Registration') |
|
880
|
|
|
get_registration_display.admin_order_field = _(u'registration') |
|
881
|
|
|
|
|
882
|
|
|
def get_enabled_display(self, obj): |
|
883
|
|
|
if obj.enabled: |
|
884
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
885
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
886
|
|
|
get_enabled_display.short_description = _(u'Enabled') |
|
887
|
|
|
get_enabled_display.admin_order_field = _(u'enabled') |
|
888
|
|
|
|
|
889
|
|
|
def get_fake_ring_display(self, obj): |
|
890
|
|
|
if obj.fake_ring: |
|
891
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-thumbs-up"></i> YES</span>') |
|
892
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
893
|
|
|
get_fake_ring_display.short_description = _(u'Fake ring') |
|
894
|
|
|
get_fake_ring_display.admin_order_field = _(u'fake_ring') |
|
895
|
|
|
|
|
896
|
|
|
def get_cli_debug_display(self, obj): |
|
897
|
|
|
if obj.cli_debug: |
|
898
|
|
|
return mark_safe('<span class="label label-warning"><i class="icon-thumbs-up"></i> YES</span>') |
|
899
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
900
|
|
|
get_cli_debug_display.short_description = _(u'cli_debug') |
|
901
|
|
|
get_cli_debug_display.admin_order_field = _(u'cli_debug') |
|
902
|
|
|
|
|
903
|
|
|
def has_change_permission(self, request, obj=None): |
|
904
|
|
|
if request.user.is_superuser: |
|
905
|
|
|
return True |
|
906
|
|
|
else: |
|
907
|
|
|
return False |
|
908
|
|
|
|
|
909
|
|
|
# VoipSwitch |
|
910
|
|
|
|
|
911
|
|
|
|
|
912
|
|
|
class VoipSwitchAdmin(admin.ModelAdmin): |
|
913
|
|
|
list_display = ['name', |
|
914
|
|
|
'ip', |
|
915
|
|
|
'date_added', |
|
916
|
|
|
'date_modified'] |
|
917
|
|
|
ordering = ['name', ] |
|
918
|
|
|
|
|
919
|
|
|
def has_change_permission(self, request, obj=None): |
|
920
|
|
|
if request.user.is_superuser: |
|
921
|
|
|
return True |
|
922
|
|
|
else: |
|
923
|
|
|
return False |
|
924
|
|
|
|
|
925
|
|
|
# SofiaGateway |
|
926
|
|
|
|
|
927
|
|
|
|
|
928
|
|
|
class SofiaGatewayAdmin(admin.ModelAdmin): |
|
929
|
|
|
list_display = ['name', |
|
930
|
|
|
'sip_profile', |
|
931
|
|
|
'company', |
|
932
|
|
|
'channels', |
|
933
|
|
|
'proxy', |
|
934
|
|
|
'get_enabled_display', |
|
935
|
|
|
'get_register_display', |
|
936
|
|
|
'date_added', |
|
937
|
|
|
'date_modified'] |
|
938
|
|
|
ordering = ['company', |
|
939
|
|
|
'name', |
|
940
|
|
|
'proxy'] |
|
941
|
|
|
list_filter = ['company', |
|
942
|
|
|
'proxy', |
|
943
|
|
|
'enabled', |
|
944
|
|
|
'sip_profile'] |
|
945
|
|
|
search_fields = ['^company__name', |
|
946
|
|
|
'proxy'] |
|
947
|
|
|
actions = [sofiaupdate] |
|
948
|
|
|
|
|
949
|
|
|
def get_enabled_display(self, obj): |
|
950
|
|
|
if obj.enabled: |
|
951
|
|
|
return mark_safe('<span class="label label-success"><i class="icon-thumbs-up"></i> YES</span>') |
|
952
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> NO</span>') |
|
953
|
|
|
get_enabled_display.short_description = _(u'Enabled') |
|
954
|
|
|
get_enabled_display.admin_order_field = _(u'enabled') |
|
955
|
|
|
|
|
956
|
|
|
def get_register_display(self, obj): |
|
957
|
|
|
if obj.register: |
|
958
|
|
|
return mark_safe('<span class="label label-info"><i class="icon-thumbs-up"></i> ON</span>') |
|
959
|
|
|
return mark_safe('<span class="label label-danger"><i class="icon-thumbs-down"></i> OFF</span>') |
|
960
|
|
|
get_register_display.short_description = _(u'Register') |
|
961
|
|
|
get_register_display.admin_order_field = _(u'register') |
|
962
|
|
|
|
|
963
|
|
|
def has_change_permission(self, request, obj=None): |
|
964
|
|
|
if request.user.is_superuser: |
|
965
|
|
|
return True |
|
966
|
|
|
else: |
|
967
|
|
|
return False |
|
968
|
|
|
|
|
969
|
|
|
|
|
970
|
|
|
class SipProfileAdmin(admin.ModelAdmin): |
|
971
|
|
|
list_display = ['name', |
|
972
|
|
|
'ext_sip_ip', |
|
973
|
|
|
'sip_ip', |
|
974
|
|
|
'sip_port', |
|
975
|
|
|
'auth_calls', |
|
976
|
|
|
'apply_inbound_acl', |
|
977
|
|
|
'disable_register', |
|
978
|
|
|
'log_auth_failures', |
|
979
|
|
|
'disable_transcoding', |
|
980
|
|
|
'date_modified'] |
|
981
|
|
|
ordering = ['name', ] |
|
982
|
|
|
list_filter = ['sip_port', ] |
|
983
|
|
|
search_fields = ['^name', ] |
|
984
|
|
|
affix = True |
|
985
|
|
|
fieldsets = ( |
|
986
|
|
|
(_(u'Basic settings'), { |
|
987
|
|
|
'fields': (('name', 'sip_port'), |
|
988
|
|
|
('sip_ip', 'rtp_ip'), |
|
989
|
|
|
('ext_sip_ip', 'ext_rtp_ip')), |
|
990
|
|
|
'description': _(u'General sip profile informations') |
|
991
|
|
|
}), |
|
992
|
|
|
# ('Media Related Options', { |
|
993
|
|
|
# 'fields': (''), |
|
994
|
|
|
# 'classes': ('collapsed',), |
|
995
|
|
|
# 'description': 'Manage Media Related Options' |
|
996
|
|
|
# }), |
|
997
|
|
|
(_(u'Codecs Related Options'), { |
|
998
|
|
|
'fields': ('disable_transcoding', |
|
999
|
|
|
('inbound_codec_prefs', 'outbound_codec_prefs')), |
|
1000
|
|
|
'classes': ('collapsed',), |
|
1001
|
|
|
'description': _(u'Manage Codecs Related Options') |
|
1002
|
|
|
}), |
|
1003
|
|
|
(_(u'NAT'), { |
|
1004
|
|
|
'fields': ('aggressive_nat_detection', |
|
1005
|
|
|
'NDLB_rec_in_nat_reg_c', |
|
1006
|
|
|
'NDLB_force_rport', |
|
1007
|
|
|
'NDLB_broken_auth_hash'), |
|
1008
|
|
|
'classes': ('collapsed',), |
|
1009
|
|
|
'description': _(u'NAT management') |
|
1010
|
|
|
}), |
|
1011
|
|
|
(_(u'DTMF Related options'), { |
|
1012
|
|
|
'fields': ('pass_rfc2833',), |
|
1013
|
|
|
'classes': ('collapsed',), |
|
1014
|
|
|
'description': _(u'DTMF management') |
|
1015
|
|
|
}), |
|
1016
|
|
|
(_(u'SIP Related Options'), { |
|
1017
|
|
|
'fields': (('enable_timer', 'session_timeout')), |
|
1018
|
|
|
'classes': ('collapsed',), |
|
1019
|
|
|
'description': _(u'Manage SIP Related Options') |
|
1020
|
|
|
}), |
|
1021
|
|
|
(_(u'RTP Related Options'), { |
|
1022
|
|
|
'fields': ('rtp_rewrite_timestamps',), |
|
1023
|
|
|
'classes': ('collapsed',), |
|
1024
|
|
|
'description': _(u'Manage RTP Related Options') |
|
1025
|
|
|
}), |
|
1026
|
|
|
(_(u'Authentification Authorization'), { |
|
1027
|
|
|
'fields': ('apply_inbound_acl', |
|
1028
|
|
|
'auth_calls', |
|
1029
|
|
|
'log_auth_failures'), |
|
1030
|
|
|
'classes': ('collapsed',), |
|
1031
|
|
|
'description': _(u'Authentification Authorization management') |
|
1032
|
|
|
}), |
|
1033
|
|
|
(_(u'Registration'), { |
|
1034
|
|
|
'fields': ('disable_register', |
|
1035
|
|
|
'accept_blind_reg'), |
|
1036
|
|
|
'classes': ('collapsed',), |
|
1037
|
|
|
'description': _(u'Registration settings management') |
|
1038
|
|
|
}), |
|
1039
|
|
|
(_(u'Others'), { |
|
1040
|
|
|
'fields': ('user_agent',), |
|
1041
|
|
|
'classes': ('collapsed',), |
|
1042
|
|
|
'description': _(u'Others parameters') |
|
1043
|
|
|
}), |
|
1044
|
|
|
) |
|
1045
|
|
|
|
|
1046
|
|
|
def has_change_permission(self, request, obj=None): |
|
1047
|
|
|
if request.user.is_superuser: |
|
1048
|
|
|
return True |
|
1049
|
|
|
else: |
|
1050
|
|
|
return False |
|
1051
|
|
|
|
|
1052
|
|
|
# AclLists |
|
1053
|
|
|
|
|
1054
|
|
|
|
|
1055
|
|
|
class AclNodesAdminInline(admin.ModelAdmin): |
|
1056
|
|
|
list_display = ('company', 'cidr', 'policy', 'list') |
|
1057
|
|
|
|
|
1058
|
|
|
|
|
1059
|
|
|
class AclListsAdmin(admin.ModelAdmin): |
|
1060
|
|
|
list_display = ('acl_name', 'default_policy') |
|
1061
|
|
|
ordering = ['acl_name', 'default_policy'] |
|
1062
|
|
|
list_filter = ['default_policy', ] |
|
1063
|
|
|
inlines = [AclNodesAdminInline, ] |
|
1064
|
|
|
|
|
1065
|
|
|
def has_change_permission(self, request, obj=None): |
|
1066
|
|
|
if request.user.is_superuser: |
|
1067
|
|
|
return True |
|
1068
|
|
|
else: |
|
1069
|
|
|
return False |
|
1070
|
|
|
|
|
1071
|
|
|
# AclNodes |
|
1072
|
|
|
|
|
1073
|
|
|
|
|
1074
|
|
|
class AclNodesAdmin(admin.ModelAdmin): |
|
1075
|
|
|
list_display = ('company', 'cidr', 'policy', 'list') |
|
1076
|
|
|
ordering = ['company', 'policy', 'cidr'] |
|
1077
|
|
|
list_filter = ['company', 'list'] |
|
1078
|
|
|
search_fields = ['cidr', ] |
|
1079
|
|
|
|
|
1080
|
|
|
def has_change_permission(self, request, obj=None): |
|
1081
|
|
|
if request.user.is_superuser: |
|
1082
|
|
|
return True |
|
1083
|
|
|
else: |
|
1084
|
|
|
return False |
|
1085
|
|
|
|
|
1086
|
|
|
# Hangup Cause |
|
1087
|
|
|
|
|
1088
|
|
|
|
|
1089
|
|
|
class HangupCauseAdmin(ImportExportMixin, admin.ModelAdmin): |
|
1090
|
|
|
list_display = ('id', 'code', 'enumeration', 'cause', 'description') |
|
1091
|
|
|
search_fields = ('code', 'enumeration') |
|
1092
|
|
|
|
|
1093
|
|
|
def has_change_permission(self, request, obj=None): |
|
1094
|
|
|
if request.user.is_superuser: |
|
1095
|
|
|
return True |
|
1096
|
|
|
else: |
|
1097
|
|
|
return False |
|
1098
|
|
|
|
|
1099
|
|
|
# CDR |
|
1100
|
|
|
|
|
1101
|
|
|
|
|
1102
|
|
|
class TotalAveragesChangeList(ChangeList): |
|
1103
|
|
|
|
|
1104
|
|
|
def get_min_duration(self, sec_duration): |
|
1105
|
|
|
if sec_duration: |
|
1106
|
|
|
min = int(sec_duration / 60) |
|
1107
|
|
|
sec = int(sec_duration % 60) |
|
1108
|
|
|
else: |
|
1109
|
|
|
min = 0 |
|
1110
|
|
|
sec = 0 |
|
1111
|
|
|
return "%02d:%02d" % (min, sec) |
|
1112
|
|
|
|
|
1113
|
|
|
def get_results(self, *args, **kwargs): |
|
1114
|
|
|
super(TotalAveragesChangeList, self).get_results(*args, **kwargs) |
|
1115
|
|
|
self.total_sell_total = 0 |
|
1116
|
|
|
self.total_cost_total = 0 |
|
1117
|
|
|
try: |
|
1118
|
|
|
q = self.result_list.aggregate(total_sell_sum=Sum('total_sell'), |
|
1119
|
|
|
total_cost_sum=Sum('total_cost'), |
|
1120
|
|
|
effective_duration_sum=Sum('effective_duration'), |
|
1121
|
|
|
effective_duration_avg=Avg('effective_duration')) |
|
1122
|
|
|
except: |
|
1123
|
|
|
self.total_effective_duration = 0 |
|
1124
|
|
|
self.total_cost_total = 0 |
|
1125
|
|
|
self.total_sell_total = 0 |
|
1126
|
|
|
self.avg_effective_duration = 0 |
|
1127
|
|
|
self.margin = 0 |
|
1128
|
|
|
return |
|
1129
|
|
|
self.total_effective_duration = q['effective_duration_sum'] |
|
1130
|
|
|
self.total_cost_total = q['total_cost_sum'] |
|
1131
|
|
|
self.total_sell_total = q['total_sell_sum'] |
|
1132
|
|
|
self.avg_effective_duration = q['effective_duration_avg'] |
|
1133
|
|
|
try: |
|
1134
|
|
|
self.margin = self.total_sell_total - self.total_cost_total |
|
1135
|
|
|
except: |
|
1136
|
|
|
self.margin = 0 |
|
1137
|
|
|
self.min_avg_effective_duration = self.get_min_duration(q['effective_duration_avg']) |
|
1138
|
|
|
self.min_total_effective_duration = self.get_min_duration(q['effective_duration_sum']) |
|
1139
|
|
|
|
|
1140
|
|
|
|
|
1141
|
|
|
class CDRAdmin(ExportMixin, admin.ModelAdmin): |
|
1142
|
|
|
search_fields = ['^prefix', |
|
1143
|
|
|
'^destination_number', |
|
1144
|
|
|
'^customer__name', |
|
1145
|
|
|
'^cost_destination', |
|
1146
|
|
|
'^sell_destination'] |
|
1147
|
|
|
list_filter = ('start_stamp',) |
|
1148
|
|
|
# date_hierarchy = 'start_stamp' |
|
1149
|
|
|
change_list_template = 'admin/pyfreebill/cdr/change_list.html' |
|
1150
|
|
|
resource_class = CDRResourceExtra |
|
1151
|
|
|
fieldsets = ( |
|
1152
|
|
|
(_(u'General'), { |
|
1153
|
|
|
'fields': ('customer', |
|
1154
|
|
|
'start_stamp', |
|
1155
|
|
|
'destination_number', |
|
1156
|
|
|
('min_effective_duration', 'billsec'), |
|
1157
|
|
|
('sell_destination', 'cost_destination'), |
|
1158
|
|
|
'switchname') |
|
1159
|
|
|
}), |
|
1160
|
|
|
(_(u'Advanced date / duration infos'), { |
|
1161
|
|
|
'classes': ('collapse',), |
|
1162
|
|
|
'fields': (('answered_stamp', |
|
1163
|
|
|
'end_stamp', |
|
1164
|
|
|
'duration', |
|
1165
|
|
|
'effectiv_duration')) |
|
1166
|
|
|
}), |
|
1167
|
|
|
(_(u'Financial infos'), { |
|
1168
|
|
|
'fields': (('total_cost', 'cost_rate'), |
|
1169
|
|
|
('total_sell', 'rate'), |
|
1170
|
|
|
('init_block', 'block_min_duration')) |
|
1171
|
|
|
}), |
|
1172
|
|
|
(_(u'LCR infos'), { |
|
1173
|
|
|
'classes': ('collapse',), |
|
1174
|
|
|
'fields': ('prefix', |
|
1175
|
|
|
('ratecard_id', 'lcr_group_id'), |
|
1176
|
|
|
('lcr_carrier_id', 'gateway')) |
|
1177
|
|
|
}), |
|
1178
|
|
|
(_(u'Call detailed infos'), { |
|
1179
|
|
|
'classes': ('collapse',), |
|
1180
|
|
|
'fields': ('caller_id_number', |
|
1181
|
|
|
('hangup_cause', |
|
1182
|
|
|
'hangup_cause_q850', |
|
1183
|
|
|
'hangup_disposition', |
|
1184
|
|
|
'sip_hangup_cause'), |
|
1185
|
|
|
('read_codec', 'write_codec'), |
|
1186
|
|
|
'sip_user_agent', |
|
1187
|
|
|
'customer_ip', |
|
1188
|
|
|
('uuid', 'bleg_uuid', 'chan_name', 'country')) |
|
1189
|
|
|
}), |
|
1190
|
|
|
) |
|
1191
|
|
|
|
|
1192
|
|
|
def has_add_permission(self, request, obj=None): |
|
1193
|
|
|
return False |
|
1194
|
|
|
|
|
1195
|
|
|
def has_delete_permission(self, request, obj=None): |
|
1196
|
|
|
return False |
|
1197
|
|
|
|
|
1198
|
|
|
def get_actions(self, request): |
|
1199
|
|
|
if request.user.is_superuser: |
|
1200
|
|
|
return |
|
1201
|
|
|
else: |
|
1202
|
|
|
return |
|
1203
|
|
|
|
|
1204
|
|
|
def get_changelist(self, request, **kwargs): |
|
1205
|
|
|
return TotalAveragesChangeList |
|
1206
|
|
|
|
|
1207
|
|
|
def changelist_view(self, request, extra_context=None): |
|
1208
|
|
|
if request.user.is_superuser: |
|
1209
|
|
|
self.list_display_links = ['start_stamp', ] |
|
1210
|
|
|
return super(CDRAdmin, self).changelist_view(request, |
|
1211
|
|
|
extra_context=None) |
|
1212
|
|
|
else: |
|
1213
|
|
|
self.list_display_links = ['None', ] |
|
1214
|
|
|
return super(CDRAdmin, self).changelist_view(request, |
|
1215
|
|
|
extra_context=None) |
|
1216
|
|
|
|
|
1217
|
|
|
def get_ordering(self, request): |
|
1218
|
|
|
if request.user.is_superuser: |
|
1219
|
|
|
return ['-start_stamp', ] |
|
1220
|
|
|
else: |
|
1221
|
|
|
return ['-start_stamp', ] |
|
1222
|
|
|
|
|
1223
|
|
|
def get_list_display(self, request): |
|
1224
|
|
|
if request.user.is_superuser: |
|
1225
|
|
|
return ['start_stamp', |
|
1226
|
|
|
'customer', |
|
1227
|
|
|
'sell_destination', |
|
1228
|
|
|
'destination_number', |
|
1229
|
|
|
'min_effective_duration', |
|
1230
|
|
|
'hangup_cause_colored', |
|
1231
|
|
|
'lcr_carrier_id', |
|
1232
|
|
|
'cost_rate', |
|
1233
|
|
|
'rate', |
|
1234
|
|
|
'prefix', |
|
1235
|
|
|
'ratecard_id', |
|
1236
|
|
|
'switchname'] |
|
1237
|
|
|
else: |
|
1238
|
|
|
return ['start_stamp', |
|
1239
|
|
|
'customer', |
|
1240
|
|
|
'customer_ip', |
|
1241
|
|
|
'sell_destination', |
|
1242
|
|
|
'destination_number', |
|
1243
|
|
|
'min_effective_duration', |
|
1244
|
|
|
'hangup_cause', |
|
1245
|
|
|
'rate', |
|
1246
|
|
|
'total_sell'] |
|
1247
|
|
|
|
|
1248
|
|
|
def get_list_filter(self, request): |
|
1249
|
|
|
if request.user.is_superuser: |
|
1250
|
|
|
return ['start_stamp', 'customer', 'lcr_carrier_id', 'ratecard_id'] |
|
1251
|
|
|
else: |
|
1252
|
|
|
return ['start_stamp', 'sell_destination'] |
|
1253
|
|
|
|
|
1254
|
|
|
def get_readonly_fields(self, request, obj=None): |
|
1255
|
|
|
if request.user.is_superuser: |
|
1256
|
|
|
return ['customer_ip', |
|
1257
|
|
|
'customer', |
|
1258
|
|
|
'caller_id_number', |
|
1259
|
|
|
'destination_number', |
|
1260
|
|
|
'start_stamp', |
|
1261
|
|
|
'answered_stamp', |
|
1262
|
|
|
'end_stamp', |
|
1263
|
|
|
'duration', |
|
1264
|
|
|
'min_effective_duration', |
|
1265
|
|
|
'billsec', |
|
1266
|
|
|
'hangup_cause', |
|
1267
|
|
|
'hangup_cause_q850', |
|
1268
|
|
|
'gateway', |
|
1269
|
|
|
'lcr_carrier_id', |
|
1270
|
|
|
'prefix', |
|
1271
|
|
|
'country', |
|
1272
|
|
|
'cost_rate', |
|
1273
|
|
|
'total_cost', |
|
1274
|
|
|
'total_sell', |
|
1275
|
|
|
'rate', |
|
1276
|
|
|
'init_block', |
|
1277
|
|
|
'block_min_duration', |
|
1278
|
|
|
'ratecard_id', |
|
1279
|
|
|
'lcr_group_id', |
|
1280
|
|
|
'uuid', |
|
1281
|
|
|
'bleg_uuid', |
|
1282
|
|
|
'chan_name', |
|
1283
|
|
|
'read_codec', |
|
1284
|
|
|
'write_codec', |
|
1285
|
|
|
'sip_user_agent', |
|
1286
|
|
|
'hangup_disposition', |
|
1287
|
|
|
'effectiv_duration', |
|
1288
|
|
|
'sip_hangup_cause', |
|
1289
|
|
|
'sell_destination', |
|
1290
|
|
|
'cost_destination', |
|
1291
|
|
|
'switchname'] |
|
1292
|
|
|
else: |
|
1293
|
|
|
return ['start_stamp', |
|
1294
|
|
|
'customer', |
|
1295
|
|
|
'customer_ip', |
|
1296
|
|
|
'sell_destination', |
|
1297
|
|
|
'destination_number', |
|
1298
|
|
|
'min_effective_duration', |
|
1299
|
|
|
'hangup_cause', |
|
1300
|
|
|
'rate', |
|
1301
|
|
|
'total_sell'] |
|
1302
|
|
|
|
|
1303
|
|
|
def get_form(self, request, obj=None, **kwargs): |
|
1304
|
|
|
self.exclude = ['effectiv_duration', |
|
1305
|
|
|
'effective_duration', |
|
1306
|
|
|
'sip_rtp_rxstat', |
|
1307
|
|
|
'sip_rtp_txstat', |
|
1308
|
|
|
'switch_ipv4'] |
|
1309
|
|
|
if not request.user.is_superuser: |
|
1310
|
|
|
self.exclude.append('cost_rate') |
|
1311
|
|
|
self.exclude.append('total_cost') |
|
1312
|
|
|
self.exclude.append('gateway') |
|
1313
|
|
|
self.exclude.append('switchname') |
|
1314
|
|
|
self.exclude.append('lcr_carrier_id') |
|
1315
|
|
|
self.exclude.append('lcr_group_id') |
|
1316
|
|
|
self.exclude.append('cost_destination') |
|
1317
|
|
|
return super(CDRAdmin, self).get_form(request, obj, **kwargs) |
|
1318
|
|
|
|
|
1319
|
|
|
def queryset(self, request): |
|
1320
|
|
|
today_c = date.today() - datetime.timedelta(days=settings.PFB_NB_CUST_CDR) |
|
1321
|
|
|
today_a = date.today() - datetime.timedelta(days=settings.PFB_NB_ADMIN_CDR) |
|
1322
|
|
|
user = getattr(request, 'user', None) |
|
1323
|
|
|
qs = super(CDRAdmin, self).queryset(request) |
|
1324
|
|
|
# add .prefetch_related('content_type') for reduce queries |
|
1325
|
|
|
if user.is_superuser: |
|
1326
|
|
|
return qs.filter(start_stamp__gte=today_a) |
|
1327
|
|
|
else: |
|
1328
|
|
|
usercompany = Person.objects.get(user=user) |
|
1329
|
|
|
return qs.filter(customer=usercompany.company).filter(start_stamp__gte=today_c).filter(effective_duration__gt="0") |
|
1330
|
|
|
|
|
1331
|
|
|
def get_export_formats(self): |
|
1332
|
|
|
format_csv = DEFAULT_FORMATS |
|
1333
|
|
|
return [f for f in format_csv if f().can_export()] |
|
1334
|
|
|
|
|
1335
|
|
|
|
|
1336
|
|
|
class CarrierNormalizationRulesAdmin(admin.ModelAdmin): |
|
1337
|
|
|
list_display = ('company', 'prefix', 'remove_prefix', 'add_prefix') |
|
1338
|
|
|
ordering = ('company', 'prefix') |
|
1339
|
|
|
search_fields = ('^prefix',) |
|
1340
|
|
|
|
|
1341
|
|
|
def has_change_permission(self, request, obj=None): |
|
1342
|
|
|
if request.user.is_superuser: |
|
1343
|
|
|
return True |
|
1344
|
|
|
else: |
|
1345
|
|
|
return False |
|
1346
|
|
|
|
|
1347
|
|
|
|
|
1348
|
|
|
class CustomerNormalizationRulesAdmin(admin.ModelAdmin): |
|
1349
|
|
|
list_display = ('company', 'prefix', 'remove_prefix', 'add_prefix') |
|
1350
|
|
|
ordering = ('company', 'prefix') |
|
1351
|
|
|
search_fields = ('^prefix',) |
|
1352
|
|
|
|
|
1353
|
|
|
def has_change_permission(self, request, obj=None): |
|
1354
|
|
|
if request.user.is_superuser: |
|
1355
|
|
|
return True |
|
1356
|
|
|
else: |
|
1357
|
|
|
return False |
|
1358
|
|
|
|
|
1359
|
|
|
|
|
1360
|
|
|
class CarrierCIDNormalizationRulesAdmin(admin.ModelAdmin): |
|
1361
|
|
|
list_display = ('company', 'prefix', 'remove_prefix', 'add_prefix') |
|
1362
|
|
|
ordering = ('company',) |
|
1363
|
|
|
|
|
1364
|
|
|
def has_change_permission(self, request, obj=None): |
|
1365
|
|
|
if request.user.is_superuser: |
|
1366
|
|
|
return True |
|
1367
|
|
|
else: |
|
1368
|
|
|
return False |
|
1369
|
|
|
|
|
1370
|
|
|
|
|
1371
|
|
|
class CustomerCIDNormalizationRulesAdmin(admin.ModelAdmin): |
|
1372
|
|
|
list_display = ('company', 'prefix', 'remove_prefix', 'add_prefix') |
|
1373
|
|
|
ordering = ('company',) |
|
1374
|
|
|
|
|
1375
|
|
|
def has_change_permission(self, request, obj=None): |
|
1376
|
|
|
if request.user.is_superuser: |
|
1377
|
|
|
return True |
|
1378
|
|
|
else: |
|
1379
|
|
|
return False |
|
1380
|
|
|
|
|
1381
|
|
|
|
|
1382
|
|
|
class DestinationNumberRulesAdmin(admin.ModelAdmin): |
|
1383
|
|
|
list_display = ('prefix', 'format_num', 'description') |
|
1384
|
|
|
ordering = ('prefix',) |
|
1385
|
|
|
|
|
1386
|
|
|
def has_change_permission(self, request, obj=None): |
|
1387
|
|
|
if request.user.is_superuser: |
|
1388
|
|
|
return True |
|
1389
|
|
|
else: |
|
1390
|
|
|
return False |
|
1391
|
|
|
|
|
1392
|
|
|
|
|
1393
|
|
|
class DimCustomerDestinationAdmin(admin.ModelAdmin): |
|
1394
|
|
|
list_display = ('date', 'customer', 'destination', 'total_calls', 'success_calls', 'total_duration', 'avg_duration', 'max_duration', 'min_duration', 'total_sell', 'total_cost') |
|
1395
|
|
|
readonly_fields = ('date', 'customer', 'destination', 'total_calls', 'success_calls', 'total_duration', 'avg_duration', 'max_duration', 'min_duration', 'total_sell', 'total_cost') |
|
1396
|
|
|
list_filter = ('date', 'customer', 'destination') |
|
1397
|
|
|
ordering = ('-date', 'customer', 'destination') |
|
1398
|
|
|
|
|
1399
|
|
|
def has_add_permission(self, request, obj=None): |
|
1400
|
|
|
return False |
|
1401
|
|
|
|
|
1402
|
|
|
def has_delete_permission(self, request, obj=None): |
|
1403
|
|
|
return False |
|
1404
|
|
|
|
|
1405
|
|
|
|
|
1406
|
|
|
class DimProviderDestinationAdmin(admin.ModelAdmin): |
|
1407
|
|
|
list_display = ('date', 'provider', 'destination', 'total_calls', 'success_calls', 'total_duration', 'avg_duration', 'max_duration', 'min_duration', 'total_sell', 'total_cost') |
|
1408
|
|
|
readonly_fields = ('date', 'provider', 'destination', 'total_calls', 'success_calls', 'total_duration', 'avg_duration', 'max_duration', 'min_duration', 'total_sell', 'total_cost') |
|
1409
|
|
|
list_filter = ('date', 'provider', 'destination') |
|
1410
|
|
|
ordering = ('-date', 'provider', 'destination') |
|
1411
|
|
|
# list_display = ('get_day_stats',) |
|
1412
|
|
|
|
|
1413
|
|
|
def has_add_permission(self, request, obj=None): |
|
1414
|
|
|
return False |
|
1415
|
|
|
|
|
1416
|
|
|
def has_delete_permission(self, request, obj=None): |
|
1417
|
|
|
return False |
|
1418
|
|
|
|
|
1419
|
|
|
|
|
1420
|
|
|
#---------------------------------------- |
|
1421
|
|
|
# register |
|
1422
|
|
|
#---------------------------------------- |
|
1423
|
|
|
admin_site.register(Company, CompanyAdmin) |
|
1424
|
|
|
admin_site.register(Person, PersonAdmin) |
|
1425
|
|
|
admin_site.register(Group, GroupAdmin) |
|
1426
|
|
|
admin_site.register(CompanyBalanceHistory, CompanyBalanceHistoryAdmin) |
|
1427
|
|
|
admin_site.register(CalleridPrefix, CalleridPrefixAdmin) |
|
1428
|
|
|
admin_site.register(CalleridPrefixList, CalleridPrefixListAdmin) |
|
1429
|
|
|
admin_site.register(ProviderTariff, ProviderTariffAdmin) |
|
1430
|
|
|
admin_site.register(ProviderRates, ProviderRatesAdmin) |
|
1431
|
|
|
admin_site.register(LCRGroup, LCRGroupAdmin) |
|
1432
|
|
|
#admin.site.register(LCRProviders, LCRProvidersAdmin) |
|
1433
|
|
|
admin_site.register(RateCard, RateCardAdmin) |
|
1434
|
|
|
admin_site.register(CustomerRates, CustomerRatesAdmin) |
|
1435
|
|
|
admin_site.register(CustomerRateCards, CustomerRateCardsAdmin) |
|
1436
|
|
|
admin_site.register(CustomerDirectory, CustomerDirectoryAdmin) |
|
1437
|
|
|
#admin_site.register(AclLists, AclListsAdmin) |
|
1438
|
|
|
#admin.site.register(AclNodes, AclNodesAdmin) |
|
1439
|
|
|
#admin.site.register(VoipSwitch, VoipSwitchAdmin) |
|
1440
|
|
|
admin_site.register(SipProfile, SipProfileAdmin) |
|
1441
|
|
|
admin_site.register(SofiaGateway, SofiaGatewayAdmin) |
|
1442
|
|
|
#admin.site.register(HangupCause, HangupCauseAdmin) |
|
1443
|
|
|
admin_site.register(CDR, CDRAdmin) |
|
1444
|
|
|
admin_site.register(CarrierNormalizationRules, CarrierNormalizationRulesAdmin) |
|
1445
|
|
|
admin_site.register(CustomerNormalizationRules, |
|
1446
|
|
|
CustomerNormalizationRulesAdmin) |
|
1447
|
|
|
admin_site.register(CarrierCIDNormalizationRules, |
|
1448
|
|
|
CarrierCIDNormalizationRulesAdmin) |
|
1449
|
|
|
admin_site.register(CustomerCIDNormalizationRules, |
|
1450
|
|
|
CustomerCIDNormalizationRulesAdmin) |
|
1451
|
|
|
admin_site.register(DestinationNumberRules, DestinationNumberRulesAdmin) |
|
1452
|
|
|
#admin.site.register(DimCustomerHangupcause, DimCustomerHangupcauseAdmin) |
|
1453
|
|
|
#admin.site.register(DimCustomerSipHangupcause, DimCustomerSipHangupcauseAdmin) |
|
1454
|
|
|
#admin.site.register(DimProviderHangupcause, DimProviderHangupcauseAdmin) |
|
1455
|
|
|
#admin.site.register(DimProviderSipHangupcause, DimProviderSipHangupcauseAdmin) |
|
1456
|
|
|
admin_site.register(DimCustomerDestination, DimCustomerDestinationAdmin) |
|
1457
|
|
|
admin_site.register(DimProviderDestination, DimProviderDestinationAdmin) |
|
1458
|
|
|
|