diff --git a/src/postorius/management/commands/mmclient.py b/src/postorius/management/commands/mmclient.py index 1e5ec07..404901a 100644 --- a/src/postorius/management/commands/mmclient.py +++ b/src/postorius/management/commands/mmclient.py @@ -19,6 +19,7 @@ from django.conf import settings from django.core.management.base import BaseCommand, CommandError from mailmanclient import Client, MailmanConnectionError +from postorius import utils from urllib2 import HTTPError class Command(BaseCommand): @@ -44,7 +45,6 @@ shell = code.InteractiveConsole(globals()) console_fn = shell.interact # connect to mailmanclient - client = Client('%s/3.0' % settings.REST_SERVER, - settings.API_USER, settings.API_PASS) + client = utils.get_client() # run the interpreter console_fn() diff --git a/src/postorius/models.py b/src/postorius/models.py index 25e18af..2f002cb 100644 --- a/src/postorius/models.py +++ b/src/postorius/models.py @@ -25,6 +25,7 @@ from django.dispatch import receiver from django.http import Http404 from mailmanclient import Client, MailmanConnectionError +from postorius import utils from urllib2 import HTTPError @@ -48,8 +49,7 @@ """ def __init__(self, resource_name, resource_name_plural, cls_name=None): - self.client = Client('%s/3.0' % settings.REST_SERVER, - settings.API_USER, settings.API_PASS) + self.client = utils.get_client() self.resource_name = resource_name self.resource_name_plural = resource_name_plural diff --git a/src/postorius/utils.py b/src/postorius/utils.py index 84d81a0..587f6c4 100644 --- a/src/postorius/utils.py +++ b/src/postorius/utils.py @@ -33,9 +33,9 @@ def get_client(): - return Client('{0}/3.0'.format(settings.REST_SERVER), - settings.API_USER, - settings.API_PASS) + return Client('{0}/3.0'.format(settings.MAILMAN_API_URL), + settings.MAILMAN_USER, + settings.MAILMAN_PASS) def render_api_error(request): diff --git a/src/postorius/views/api.py b/src/postorius/views/api.py index 093b937..c51b9c1 100644 --- a/src/postorius/views/api.py +++ b/src/postorius/views/api.py @@ -54,8 +54,7 @@ @basic_auth_login @loggedin_or_403 def api_list_index(request): - client = Client('%s/3.0' % settings.REST_SERVER, - settings.API_USER, settings.API_PASS) + client = utils.get_client() res, content = client._connection.call('lists') return HttpResponse(json.dumps(content['entries']), content_type="application/json") diff --git a/src/postorius/views/generic.py b/src/postorius/views/generic.py index 7095dac..4feda1d 100644 --- a/src/postorius/views/generic.py +++ b/src/postorius/views/generic.py @@ -33,8 +33,7 @@ def client(self): if getattr(self._client, '_client', None) is None: - self._client = Client('%s/3.0' % settings.REST_SERVER, - settings.API_USER, settings.API_PASS) + self._client = utils.get_client() return self._client @@ -114,7 +113,7 @@ memberships = [] if (self.mm_user): for a in self.mm_user.addresses: - members = self._client._connection.call('members/find', + members = self.client()._connection.call('members/find', {'subscriber': a}) try: for m in members[1]['entries']: diff --git a/src/postorius/views/settings.py b/src/postorius/views/settings.py index 333191d..305a739 100644 --- a/src/postorius/views/settings.py +++ b/src/postorius/views/settings.py @@ -95,8 +95,7 @@ """ if request.method == 'POST': try: - client = Client(settings.REST_SERVER + '/3.0', settings.API_USER, - settings.API_PASS) + client = utils.get_client() client.delete_domain(domain) messages.success(request, _('The domain %s has been deleted.' % domain))