Browse Source

code cosmetics

master
Frederic 11 years ago
parent
commit
ba2f2d5898
  1. 18
      cash/admin.py
  2. 5
      cash/models.py
  3. 3
      cash/views.py

18
cash/admin.py

@ -8,7 +8,9 @@ from django.utils.translation import ugettext_lazy @@ -8,7 +8,9 @@ from django.utils.translation import ugettext_lazy
from django.utils.translation import ugettext_noop
class AccountForm(forms.ModelForm):
credit_change = forms.DecimalField(max_digits = 5, decimal_places = 2, required = False, label = ugettext_lazy('change change'))
credit_change = forms.DecimalField(max_digits = 5, decimal_places = 2,
required = False,
label = ugettext_lazy('change change'))
class Meta:
model = Account
@ -19,7 +21,9 @@ class AccountAdmin(admin.ModelAdmin): @@ -19,7 +21,9 @@ class AccountAdmin(admin.ModelAdmin):
readonly_fields = ('credit',)
def transaction_link(self, account):
return '<a href="%s?account__id__exact=%d">%s</a>' % (reverse("admin:cash_transaction_changelist"), account.id, _('Transactions'))
return '<a href="%s?account__id__exact=%d">%s</a>' % \
(reverse("admin:cash_transaction_changelist"), account.id,
_('Transactions'))
transaction_link.short_description = ugettext_lazy('Transaction link')
@ -40,7 +44,8 @@ class AccountAdmin(admin.ModelAdmin): @@ -40,7 +44,8 @@ class AccountAdmin(admin.ModelAdmin):
else:
subject = PAYOUT_SUBJECT
obj.change_credit(amount, subject, DESC % (request.user.first_name, request.user.last_name))
obj.change_credit(amount, subject, DESC % (request.user.first_name,
request.user.last_name))
class ProductBarcodeInline(admin.TabularInline):
@ -66,7 +71,7 @@ class TransactionAdmin(admin.ModelAdmin): @@ -66,7 +71,7 @@ class TransactionAdmin(admin.ModelAdmin):
actions = None
date_hierarchy = 'timestamp'
# Disable tampering with the transactions completely
# Disable tampering with the transactions completely.
def has_add_permission(self, request):
return False
def has_change_permission(self, request, obj=None):
@ -76,11 +81,12 @@ class TransactionAdmin(admin.ModelAdmin): @@ -76,11 +81,12 @@ class TransactionAdmin(admin.ModelAdmin):
def has_delete_permission(self, request, obj=None):
return False
# Needed to not trigger an ImproperlyConfigured exception
# Needed to not trigger an ImproperlyConfigured exception.
# FIXME: a bit too hacky
def changelist_view(self, request, extra_context=None):
self.list_display_links = (None, )
return super(TransactionAdmin, self).changelist_view(request, extra_context=None)
return super(TransactionAdmin, self).changelist_view(request,
extra_context=None)
admin.site.register(Account, AccountAdmin)
admin.site.register(Product, ProductAdmin)

5
cash/models.py

@ -151,5 +151,8 @@ def logentry_pre_delete_handler(sender, instance, **kwargs): @@ -151,5 +151,8 @@ def logentry_pre_delete_handler(sender, instance, **kwargs):
SUBJECT = ugettext_noop('Cancellation')
DESC = '%d x %s'
instance.account.change_credit(instance.unit_price * instance.count, SUBJECT, DESC % (instance.count, instance.product.name))
instance.account.change_credit(
instance.unit_price * instance.count,
SUBJECT, DESC % (instance.count, instance.product.name)
)

3
cash/views.py

@ -9,7 +9,8 @@ from django.utils.translation import ugettext as _ @@ -9,7 +9,8 @@ from django.utils.translation import ugettext as _
@login_required
def overview(request):
return render_to_response('cash/index.html', context_instance=RequestContext(request))
return render_to_response('cash/index.html',
context_instance=RequestContext(request))
class ProductView(generic.DetailView):

Loading…
Cancel
Save