def didupdate(modeladmin, request, queryset): """ generate new did xml config file """ try: t = loader.get_template('xml/00_did.xml') except IOError: messages.error( request, """did config xml file update failed. Can not load template file !""") dids = Did.objects.all() c = Context({ "dids": dids, }) try: f = open('/usr/local/freeswitch/conf/dialplan/public/00_did.xml', 'w') try: f.write(t.render(c)) f.close() try: esl.getReloadDialplan() messages.success(request, "FS successfully reload") except IOError: messages.error( request, """DID config xml file update failed. FS update failed ! Try manually""") finally: # f.close() messages.success(request, "DID config xml file update success") except IOError: messages.error( request, """DID config xml file update failed. Can not create file !""")
def update_did(sender, instance, signal, created, **kwargs): """ generate new did xml config file """ if kwargs.get('raw', False): return False request = kwargs.get("request") try: t = loader.get_template('xml/00_did.xml') except IOError: messages.error(request, _(u"""did config xml file update failed. Can not load template file !""")) dids = Did.objects.all() c = Context({"dids": dids, }) try: f = open('/usr/local/freeswitch/conf/dialplan/public/00_did.xml', 'w') try: f.write(t.render(c)) f.close() try: esl.getReloadDialplan() messages.success(_(u"FS successfully reload")) except IOError: messages.error(_(u"""DID config xml file update failed. FS update failed ! Try manually""")) finally: #f.close() messages.success(request, _(u"DID config xml file update success")) except IOError: messages.error(_(u"""DID config xml file update failed. Can not create file !"""))