2014-07-16 15:20:16 +00:00
|
|
|
from django import forms
|
2014-05-27 15:55:09 +00:00
|
|
|
from django.contrib import admin
|
2014-07-16 15:20:16 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2014-05-27 15:55:09 +00:00
|
|
|
|
2014-07-18 15:32:27 +00:00
|
|
|
from orchestra.apps.accounts.admin import AccountAdminMixin
|
2014-07-16 15:20:16 +00:00
|
|
|
from orchestra.core import services
|
|
|
|
|
|
|
|
from .models import Service, Order, MetricStorage
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceAdmin(admin.ModelAdmin):
|
|
|
|
fieldsets = (
|
|
|
|
(None, {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('description', 'model', 'match', 'is_active')
|
|
|
|
}),
|
|
|
|
(_("Billing options"), {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('billing_period', 'billing_point', 'delayed_billing',
|
|
|
|
'is_fee')
|
|
|
|
}),
|
|
|
|
(_("Pricing options"), {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('metric', 'pricing_period', 'rate_algorithm',
|
|
|
|
'orders_effect', ('on_cancel', 'on_disable', 'on_register'),
|
|
|
|
'payment_style', 'trial_period', 'refound_period', 'tax',)
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
|
|
|
def formfield_for_dbfield(self, db_field, **kwargs):
|
|
|
|
""" Improve performance of account field and filter by account """
|
|
|
|
if db_field.name == 'model':
|
|
|
|
models = [model._meta.model_name for model in services.get().keys()]
|
|
|
|
kwargs['queryset'] = db_field.rel.to.objects.filter(model__in=models)
|
|
|
|
if db_field.name in ['match', 'metric']:
|
|
|
|
kwargs['widget'] = forms.TextInput(attrs={'size':'160'})
|
|
|
|
return super(ServiceAdmin, self).formfield_for_dbfield(db_field, **kwargs)
|
2014-05-27 15:55:09 +00:00
|
|
|
|
|
|
|
|
2014-07-18 15:32:27 +00:00
|
|
|
class OrderAdmin(AccountAdminMixin, admin.ModelAdmin):
|
2014-07-18 16:02:05 +00:00
|
|
|
list_display = ('id', 'service', 'account_link', 'cancelled_on')
|
|
|
|
list_filter = ('service',)
|
2014-05-27 15:55:09 +00:00
|
|
|
|
|
|
|
|
2014-07-16 15:20:16 +00:00
|
|
|
class MetricStorageAdmin(admin.ModelAdmin):
|
2014-07-18 16:02:05 +00:00
|
|
|
list_display = ('order', 'value', 'date')
|
|
|
|
list_filter = ('order__service',)
|
2014-05-27 15:55:09 +00:00
|
|
|
|
|
|
|
|
2014-07-16 15:20:16 +00:00
|
|
|
admin.site.register(Service, ServiceAdmin)
|
2014-05-27 15:55:09 +00:00
|
|
|
admin.site.register(Order, OrderAdmin)
|
2014-07-16 15:20:16 +00:00
|
|
|
admin.site.register(MetricStorage, MetricStorageAdmin)
|