2014-09-26 19:21:09 +00:00
|
|
|
from django.contrib import admin
|
2014-11-20 15:34:59 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2014-09-26 19:21:09 +00:00
|
|
|
|
|
|
|
from orchestra.apps.accounts.admin import AccountAdminMixin
|
2014-11-12 16:33:40 +00:00
|
|
|
from orchestra.apps.plugins.admin import SelectPluginAdminMixin
|
2014-09-26 19:21:09 +00:00
|
|
|
|
|
|
|
from .models import SaaS
|
|
|
|
from .services import SoftwareService
|
|
|
|
|
|
|
|
|
|
|
|
class SaaSAdmin(SelectPluginAdminMixin, AccountAdminMixin, admin.ModelAdmin):
|
2014-11-20 15:34:59 +00:00
|
|
|
list_display = ('username', 'service', 'display_site_name', 'account_link')
|
2014-09-26 19:21:09 +00:00
|
|
|
list_filter = ('service',)
|
|
|
|
plugin = SoftwareService
|
|
|
|
plugin_field = 'service'
|
2014-11-20 15:34:59 +00:00
|
|
|
|
|
|
|
def display_site_name(self, saas):
|
|
|
|
site_name = saas.get_site_name()
|
|
|
|
return '<a href="http://%s">%s</a>' % (site_name, site_name)
|
|
|
|
display_site_name.short_description = _("Site name")
|
|
|
|
display_site_name.allow_tags = True
|
|
|
|
display_site_name.admin_order_field = 'site_name'
|
|
|
|
|
|
|
|
def get_fields(self, request, obj=None):
|
|
|
|
fields = super(SaaSAdmin, self).get_fields(request, obj)
|
|
|
|
fields = list(fields)
|
|
|
|
# TODO do it in AccountAdminMixin?
|
|
|
|
if obj is not None:
|
|
|
|
fields.remove('account')
|
|
|
|
else:
|
|
|
|
fields.remove('account_link')
|
|
|
|
return fields
|
2014-09-26 19:21:09 +00:00
|
|
|
|
|
|
|
admin.site.register(SaaS, SaaSAdmin)
|