1
|
|
|
# Copyright 2013 Mathias WOLFF |
2
|
|
|
# This file is part of pyfreebilling. |
3
|
|
|
# |
4
|
|
|
# pyfreebilling is free software: you can redistribute it and/or modify |
5
|
|
|
# it under the terms of the GNU General Public License as published by |
6
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
# (at your option) any later version. |
8
|
|
|
# |
9
|
|
|
# pyfreebilling is distributed in the hope that it will be useful, |
10
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
# GNU General Public License for more details. |
13
|
|
|
# |
14
|
|
|
# You should have received a copy of the GNU General Public License |
15
|
|
|
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/> |
16
|
|
|
|
17
|
|
|
from __future__ import absolute_import |
18
|
|
|
|
19
|
|
|
from django.contrib import admin |
20
|
|
|
from django.contrib import messages |
21
|
|
|
from django.template import Context, loader |
22
|
|
|
# from django.utils.safestring import mark_safe |
23
|
|
|
from django.utils.translation import ugettext_lazy as _ |
24
|
|
|
|
25
|
|
|
from import_export.admin import ImportExportModelAdmin |
26
|
|
|
from import_export.formats import base_formats |
27
|
|
|
|
28
|
|
|
from pyfreebilling.did.resources import DidResource |
29
|
|
|
|
30
|
|
|
# from pyfreebilling.switch import esl |
31
|
|
|
|
32
|
|
|
from pyfreebilling.did.models import Did, RoutesDid |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
DEFAULT_FORMATS = (base_formats.CSV, ) |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
# def didupdate(modeladmin, request, queryset): |
39
|
|
|
# """ generate new did xml config file """ |
40
|
|
|
# try: |
41
|
|
|
# t = loader.get_template('xml/00_did.xml') |
42
|
|
|
# except IOError: |
43
|
|
|
# messages.error(request, """did config xml file update failed. |
44
|
|
|
# Can not load template file !""") |
45
|
|
|
# dids = Did.objects.all() |
46
|
|
|
# c = Context({"dids": dids, }) |
47
|
|
|
# try: |
48
|
|
|
# f = open('/usr/local/freeswitch/conf/dialplan/public/00_did.xml', 'w') |
49
|
|
|
# try: |
50
|
|
|
# f.write(t.render(c)) |
51
|
|
|
# f.close() |
52
|
|
|
# try: |
53
|
|
|
# esl.getReloadDialplan() |
54
|
|
|
# messages.success(request, "FS successfully reload") |
55
|
|
|
# except IOError: |
56
|
|
|
# messages.error(request, """DID config xml file update failed. |
57
|
|
|
# FS update failed ! Try manually""") |
58
|
|
|
# finally: |
59
|
|
|
# # f.close() |
60
|
|
|
# messages.success(request, "DID config xml file update success") |
61
|
|
|
# except IOError: |
62
|
|
|
# messages.error(request, """DID config xml file update failed. Can not |
63
|
|
|
# create file !""") |
64
|
|
|
# |
65
|
|
|
# |
66
|
|
|
# didupdate.short_description = _(u"update DID config xml file") |
67
|
|
|
# |
68
|
|
|
# admin.site.add_action(didupdate, _(u"generate DID configuration file")) |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
class RoutesDidInline(admin.StackedInline): |
72
|
|
|
# form = RoutesDidForm |
73
|
|
|
description = 'Did routes' |
74
|
|
|
model = RoutesDid |
75
|
|
|
modal = True |
76
|
|
|
extra = 0 |
77
|
|
|
collapse = False |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
class DidAdmin(ImportExportModelAdmin): |
81
|
|
|
list_display = ('id', |
82
|
|
|
'number', |
83
|
|
|
'provider', |
84
|
|
|
'prov_max_channels', |
85
|
|
|
'prov_ratecard', |
86
|
|
|
'customer', |
87
|
|
|
'cust_max_channels', |
88
|
|
|
'cust_ratecard', |
89
|
|
|
'date_modified') |
90
|
|
|
readonly_fields = ('date_added', |
91
|
|
|
'date_modified') |
92
|
|
|
list_filter = ('provider', |
93
|
|
|
'customer', |
94
|
|
|
'prov_ratecard', |
95
|
|
|
'cust_ratecard',) |
96
|
|
|
list_display_links = ('number',) |
97
|
|
|
ordering = ('number',) |
98
|
|
|
search_fields = ('number',) |
99
|
|
|
inlines = [RoutesDidInline, ] |
100
|
|
|
resource_class = DidResource |
101
|
|
|
#actions = [didupdate] |
102
|
|
|
|
103
|
|
|
# def get_reserved(self, obj): |
104
|
|
|
# if ContractDid.objects.get(did=obj): |
105
|
|
|
# return mark_safe("""<span class="label label-success"> |
106
|
|
|
# <i class="icon-thumbs-up"> |
107
|
|
|
# </i> Reserved</span>""") |
108
|
|
|
# return mark_safe("""<span class="label label-danger"> |
109
|
|
|
# <i class="icon-thumbs-down"> |
110
|
|
|
# </i> NO</span>""") |
111
|
|
|
# get_reserved.short_description = 'Reserved' |
112
|
|
|
# get_reserved.admin_order_field = 'reserved' |
113
|
|
|
|
114
|
|
|
def has_change_permission(self, request, obj=None): |
115
|
|
|
if request.user.is_superuser: |
116
|
|
|
return True |
117
|
|
|
else: |
118
|
|
|
return False |
119
|
|
|
|
120
|
|
|
def get_import_formats(self): |
121
|
|
|
format_csv = DEFAULT_FORMATS |
122
|
|
|
return [f for f in format_csv if f().can_import()] |
123
|
|
|
|
124
|
|
|
# ---------------------------------------- |
125
|
|
|
# register |
126
|
|
|
# ---------------------------------------- |
127
|
|
|
admin.site.register(Did, DidAdmin) |
128
|
|
|
|