Added select account template
This commit is contained in:
parent
7128db2640
commit
fe71ef72d6
|
@ -2,7 +2,7 @@ import copy
|
|||
import re
|
||||
from urllib.parse import parse_qsl
|
||||
|
||||
from django import forms
|
||||
from django import apps, forms
|
||||
from django.conf.urls import url
|
||||
from django.contrib import admin, messages
|
||||
from django.contrib.admin.utils import unquote
|
||||
|
@ -92,7 +92,7 @@ class AccountAdmin(ChangePasswordAdminMixin, auth.UserAdmin, ExtendedModelAdmin)
|
|||
}
|
||||
context.update(extra_context or {})
|
||||
return super(AccountAdmin, self).change_view(
|
||||
request, object_id, form_url, context)
|
||||
request, object_id, form_url=form_url, extra_context=context)
|
||||
|
||||
def get_fieldsets(self, request, obj=None):
|
||||
fieldsets = super(AccountAdmin, self).get_fieldsets(request, obj)
|
||||
|
@ -125,6 +125,7 @@ class AccountListAdmin(AccountAdmin):
|
|||
""" Account list to allow account selection when creating new services """
|
||||
list_display = ('select_account', 'username', 'type', 'username')
|
||||
actions = None
|
||||
change_list_template = 'admin/accounts/account/select_account_list.html'
|
||||
|
||||
def select_account(self, instance):
|
||||
# TODO get query string from request.META['QUERY_STRING'] to preserve filters
|
||||
|
@ -139,12 +140,13 @@ class AccountListAdmin(AccountAdmin):
|
|||
select_account.admin_order_field = 'username'
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
original_app_label = request.META['PATH_INFO'].split('/')[-5]
|
||||
original_model = request.META['PATH_INFO'].split('/')[-4]
|
||||
app_label = request.META['PATH_INFO'].split('/')[-5]
|
||||
model = request.META['PATH_INFO'].split('/')[-4]
|
||||
model = apps.get_model(app_label, model)
|
||||
opts = model._meta
|
||||
context = {
|
||||
'title': _("Select account for adding a new %s") % (original_model),
|
||||
'original_app_label': original_app_label,
|
||||
'original_model': original_model,
|
||||
'title': _("Select account for adding a new %s") % (opts.verbose_name),
|
||||
'original_opts': opts,
|
||||
}
|
||||
context.update(extra_context or {})
|
||||
response = super(AccountListAdmin, self).changelist_view(request, extra_context=context)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{% extends 'admin/change_list.html' %}
|
||||
{% load i18n admin_urls %}
|
||||
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
|
||||
› <a href="{% url 'admin:app_list' app_label=cl.opts.app_label %}">{{ original_opts.app_config.verbose_name }}</a>
|
||||
› <a href="{% url opts|admin_urlname:'changelist' %}">{{ original_opts.verbose_name_plural|capfirst }}</a>
|
||||
› {% trans 'Add' %}
|
||||
› {% trans 'Select contact' %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -47,13 +47,14 @@ class BillLineInline(admin.TabularInline):
|
|||
order_link = admin_link('order', display='pk')
|
||||
|
||||
def display_total(self, line):
|
||||
total = line.compute_total()
|
||||
sublines = line.sublines.all()
|
||||
if sublines:
|
||||
content = '\n'.join(['%s: %s' % (sub.description, sub.total) for sub in sublines])
|
||||
img = static('admin/img/icon_alert.gif')
|
||||
return '<span title="%s">%s <img src="%s"></img></span>' % (content, total, img)
|
||||
return total
|
||||
if line.pk:
|
||||
total = line.compute_total()
|
||||
sublines = line.sublines.all()
|
||||
if sublines:
|
||||
content = '\n'.join(['%s: %s' % (sub.description, sub.total) for sub in sublines])
|
||||
img = static('admin/img/icon_alert.gif')
|
||||
return '<span title="%s">%s <img src="%s"></img></span>' % (content, total, img)
|
||||
return total
|
||||
display_total.short_description = _("Total")
|
||||
display_total.allow_tags = True
|
||||
|
||||
|
@ -97,7 +98,8 @@ class ClosedBillLineInline(BillLineInline):
|
|||
display_subtotal.allow_tags = True
|
||||
|
||||
def display_total(self, line):
|
||||
return line.compute_total()
|
||||
if line.pk:
|
||||
return line.compute_total()
|
||||
display_total.short_description = _("Total")
|
||||
display_total.allow_tags = True
|
||||
|
||||
|
@ -110,8 +112,8 @@ class ClosedBillLineInline(BillLineInline):
|
|||
|
||||
class BillLineAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'description', 'bill_link', 'display_is_open', 'account_link', 'rate', 'quantity', 'tax',
|
||||
'subtotal', 'display_sublinetotal', 'display_total'
|
||||
'description', 'bill_link', 'display_is_open', 'account_link', 'rate', 'quantity',
|
||||
'tax', 'subtotal', 'display_sublinetotal', 'display_total'
|
||||
)
|
||||
actions = (
|
||||
actions.undo_billing, actions.move_lines, actions.copy_lines, actions.service_report
|
||||
|
@ -201,7 +203,8 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
|||
}),
|
||||
(_("Dates"), {
|
||||
'classes': ('collapse',),
|
||||
'fields': ('created_on_display', 'closed_on_display', 'updated_on_display', 'due_on'),
|
||||
'fields': ('created_on_display', 'closed_on_display', 'updated_on_display',
|
||||
'due_on'),
|
||||
}),
|
||||
(_("Raw"), {
|
||||
'classes': ('collapse',),
|
||||
|
@ -219,7 +222,9 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
|||
actions.amend_bills, actions.bill_report, actions.service_report,
|
||||
actions.close_send_download_bills, list_accounts,
|
||||
]
|
||||
change_readonly_fields = ('account_link', 'type', 'is_open', 'amend_of_link', 'amend_links')
|
||||
change_readonly_fields = (
|
||||
'account_link', 'type', 'is_open', 'amend_of_link', 'amend_links'
|
||||
)
|
||||
readonly_fields = (
|
||||
'number', 'display_total', 'is_sent', 'display_payment_state', 'created_on_display',
|
||||
'closed_on_display', 'updated_on_display'
|
||||
|
@ -265,7 +270,8 @@ class BillAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
|||
transactions = bill.transactions.all()
|
||||
if len(transactions) == 1:
|
||||
args = (transactions[0].pk,)
|
||||
url = reverse('admin:%s_%s_change' % (t_opts.app_label, t_opts.model_name), args=args)
|
||||
view = 'admin:%s_%s_change' % (t_opts.app_label, t_opts.model_name)
|
||||
url = reverse(view, args=args)
|
||||
else:
|
||||
url = reverse('admin:%s_%s_changelist' % (t_opts.app_label, t_opts.model_name))
|
||||
url += '?bill=%i' % bill.pk
|
||||
|
|
|
@ -11,7 +11,7 @@ from orchestra.admin.utils import admin_link, admin_date
|
|||
|
||||
class LogEntryAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'id', 'display_message', 'display_action_time', 'user_link',
|
||||
'display_action_time', 'user_link', 'display_message',
|
||||
)
|
||||
list_filter = (
|
||||
'action_flag',
|
||||
|
@ -32,6 +32,10 @@ class LogEntryAdmin(admin.ModelAdmin):
|
|||
user_link = admin_link('user')
|
||||
display_action_time = admin_date('action_time', short_description=_("Time"))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LogEntryAdmin, self).__init__(*args, **kwargs)
|
||||
self.list_display_links = (None, )
|
||||
|
||||
def display_message(self, log):
|
||||
edit = '<a href="%(url)s"><img src="%(img)s"></img></a>' % {
|
||||
'url': reverse('admin:admin_logentry_change', args=(log.pk,)),
|
||||
|
@ -68,8 +72,9 @@ class LogEntryAdmin(admin.ModelAdmin):
|
|||
|
||||
def content_object_link(self, log):
|
||||
ct = log.content_type
|
||||
view = 'admin:%s_%s_change' % (ct.app_label, ct.model)
|
||||
try:
|
||||
url = reverse('admin:%s_%s_change' % (ct.app_label, ct.model), args=(log.object_id,))
|
||||
url = reverse(view, args=(log.object_id,))
|
||||
except NoReverseMatch:
|
||||
return log.object_repr
|
||||
return '<a href="%s">%s</a>' % (url, log.object_repr)
|
||||
|
@ -87,7 +92,8 @@ class LogEntryAdmin(admin.ModelAdmin):
|
|||
'object': obj,
|
||||
}
|
||||
context.update(extra_context or {})
|
||||
return super(LogEntryAdmin, self).changeform_view(request, object_id, form_url, extra_context=context)
|
||||
return super(LogEntryAdmin, self).changeform_view(
|
||||
request, object_id, form_url, extra_context=context)
|
||||
|
||||
def response_change(self, request, obj):
|
||||
""" save and continue preserve edit query string """
|
||||
|
@ -100,9 +106,12 @@ class LogEntryAdmin(admin.ModelAdmin):
|
|||
""" save redirect to object history """
|
||||
if 'edit' in request.GET.urlencode():
|
||||
opts = obj.content_type.model_class()._meta
|
||||
post_url = reverse('admin:%s_%s_history' % (opts.app_label, opts.model_name), args=(obj.object_id,))
|
||||
view = 'admin:%s_%s_history' % (opts.app_label, opts.model_name)
|
||||
post_url = reverse(view, args=(obj.object_id,))
|
||||
preserved_filters = self.get_preserved_filters(request)
|
||||
post_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, post_url)
|
||||
post_url = add_preserved_filters({
|
||||
'preserved_filters': preserved_filters, 'opts': opts
|
||||
}, post_url)
|
||||
return HttpResponseRedirect(post_url)
|
||||
return super(LogEntryAdmin, self).response_post_save_change(request, obj)
|
||||
|
||||
|
|
Loading…
Reference in New Issue