From c8e8f778d71eddee74cd55eafad68f4afa0b975a Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 13 Nov 2019 12:26:35 +0100 Subject: [PATCH] Rename Service.name --> Service.api_name Avoid collision name attributes with service data. --- musician/models.py | 8 ++++---- musician/views.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/musician/models.py b/musician/models.py index 5eab96f..d73b7ab 100644 --- a/musician/models.py +++ b/musician/models.py @@ -2,13 +2,13 @@ from django.utils.html import format_html class Service: - name = None + api_name = None verbose_name = None fields = () def __init__(self, data={}): if self.verbose_name is None: - self.verbose_name = self.name + self.verbose_name = self.api_name self.data = data @@ -18,7 +18,7 @@ class Service: class MailService(Service): - name = 'address' + api_name = 'address' verbose_name = 'Mail' fields = ('mail_address', 'aliases', 'type', 'type_detail') @@ -50,7 +50,7 @@ class MailService(Service): class MailinglistService(Service): - name = 'mailinglist' + api_name = 'mailinglist' verbose_name = 'Mailing list' fields = ('name', 'status', 'address_name', 'admin_email', 'configure') diff --git a/musician/views.py b/musician/views.py index 23d5b57..539619a 100644 --- a/musician/views.py +++ b/musician/views.py @@ -1,6 +1,7 @@ +from itertools import groupby + from django.core.exceptions import ImproperlyConfigured -from itertools import groupby from django.http import HttpResponseRedirect from django.shortcuts import render from django.urls import reverse_lazy @@ -13,8 +14,8 @@ from . import api, get_version from .auth import login as auth_login from .auth import logout as auth_logout from .forms import LoginForm -from .mixins import CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin -from .models import MailService, MailinglistService +from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin) +from .models import DatabaseService, MailinglistService, MailService class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): @@ -35,15 +36,15 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView): class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin, ListView): """Base list view to all services""" - service = None + service_class = None template_name = "musician/service_list.html" # TODO move to ServiceListView def get_queryset(self): - if self.service_class is None or self.service_class.name is None: + if self.service_class is None or self.service_class.api_name is None: raise ImproperlyConfigured( "ServiceListView requires a definiton of 'service'") - json_qs = self.orchestra.retrieve_service_list(self.service_class.name) + json_qs = self.orchestra.retrieve_service_list(self.service_class.api_name) return [self.service_class(data) for data in json_qs] def get_context_data(self, **kwargs): @@ -68,7 +69,7 @@ class MailView(ServiceListView): # group addresses with the same mailbox raw_data = self.orchestra.retrieve_service_list( - self.service_class.name) + self.service_class.api_name) addresses = [] for key, group in groupby(raw_data, retrieve_mailbox): aliases = []