Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 110 additions & 71 deletions stregsystem/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
ProductNote,
)
from stregsystem.templatetags.stregsystem_extras import money
from stregsystem.utils import make_active_productlist_query, make_inactive_productlist_query
from stregsystem.utils import (
make_active_productlist_query,
make_inactive_productlist_query,
)


def refund(modeladmin, request, queryset):
Expand All @@ -35,22 +38,22 @@ def refund(modeladmin, request, queryset):


class SaleAdmin(admin.ModelAdmin):
list_filter = ('room', 'timestamp')
list_filter = ("room", "timestamp")
list_display = (
'get_username',
'get_fullname',
'get_product_name',
'get_room_name',
'timestamp',
'get_price_display',
"get_username",
"get_fullname",
"get_product_name",
"get_room_name",
"timestamp",
"get_price_display",
)
actions = [refund]
search_fields = ['^member__username', '=product__id', 'product__name']
valid_lookups = 'member'
autocomplete_fields = ['member', 'product']
search_fields = ["^member__username", "=product__id", "product__name"]
valid_lookups = "member"
autocomplete_fields = ["member", "product"]

class Media:
css = {'all': ('stregsystem/select2-stregsystem.css',)}
css = {"all": ("stregsystem/select2-stregsystem.css",)}

def get_username(self, obj):
return obj.member.username
Expand Down Expand Up @@ -110,32 +113,32 @@ def toggle_active_selected_products(modeladmin, request, queryset):


class ProductActivatedListFilter(admin.SimpleListFilter):
title = 'activated'
parameter_name = 'activated'
title = "activated"
parameter_name = "activated"

def lookups(self, request, model_admin):
return (
('Yes', 'Yes'),
('No', 'No'),
("Yes", "Yes"),
("No", "No"),
)

def queryset(self, request, queryset):
if self.value() == 'Yes':
if self.value() == "Yes":
return make_active_productlist_query(queryset)
elif self.value() == 'No':
elif self.value() == "No":
return make_inactive_productlist_query(queryset)
else:
return queryset


class ProductAdmin(admin.ModelAdmin):
search_fields = ('name', 'price', 'id')
list_filter = (ProductActivatedListFilter, 'deactivate_date', 'price')
search_fields = ("name", "price", "id")
list_filter = (ProductActivatedListFilter, "deactivate_date", "price")
list_display = (
'activated',
'id',
'name',
'get_price_display',
"activated",
"id",
"name",
"get_price_display",
)
fields = (
"name",
Expand All @@ -150,7 +153,7 @@ class ProductAdmin(admin.ModelAdmin):
readonly_fields = ("get_bought",)

actions = [toggle_active_selected_products]
filter_horizontal = ('categories', 'rooms')
filter_horizontal = ("categories", "rooms")

def get_price_display(self, obj):
if obj.price is None:
Expand All @@ -174,24 +177,24 @@ def activated(self, product):

class NamedProductAdmin(admin.ModelAdmin):
search_fields = (
'name',
'product',
"name",
"product",
)
list_display = (
'name',
'product',
"name",
"product",
)
fields = (
'name',
'product',
"name",
"product",
)
autocomplete_fields = [
'product',
"product",
]


class CategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'items_in_category')
list_display = ("name", "items_in_category")

def items_in_category(self, obj):
return obj.product_set.count()
Expand All @@ -203,7 +206,7 @@ class Meta:
exclude = []

def clean_username(self):
username = self.cleaned_data['username']
username = self.cleaned_data["username"]
if self.instance is None or self.instance.pk is None:
if Member.objects.filter(username__iexact=username).exists():
raise forms.ValidationError("Brugernavnet er allerede taget")
Expand All @@ -212,33 +215,49 @@ def clean_username(self):

class MemberAdmin(admin.ModelAdmin):
form = MemberForm
list_filter = ('want_spam',)
search_fields = ('username', 'firstname', 'lastname', 'email')
list_display = ('username', 'firstname', 'lastname', 'balance', 'email', 'notes')
list_filter = ("want_spam",)
search_fields = ("username", "firstname", "lastname", "email")
list_display = ("username", "firstname", "lastname", "balance", "email", "notes")

# fieldsets is like fields, except that they are grouped and with descriptions
fieldsets = (
(
None,
{
'fields': ('username', 'firstname', 'lastname', 'year', 'gender', 'email'),
'description': "Basal information omkring fember",
"fields": (
"username",
"firstname",
"lastname",
"year",
"gender",
"email",
),
"description": "Basal information omkring fember",
},
),
(None, {'fields': ('notes',), 'description': "Studieretning + evt. andet i noter"}),
(
None,
{"fields": ("notes",), "description": "Studieretning + evt. andet i noter"},
),
(
None,
{
'fields': ('active', 'want_spam', 'signup_due_paid', 'balance', 'undo_count'),
'description': "Lad være med at rode med disse, med mindre du ved hvad du laver ...",
"fields": (
"active",
"want_spam",
"signup_due_paid",
"balance",
"undo_count",
),
"description": "Lad være med at rode med disse, med mindre du ved hvad du laver ...",
},
),
)

def save_model(self, request, obj, form, change):
if 'username' in form.changed_data and change:
if "username" in form.changed_data and change:
if Member.objects.filter(username__iexact=obj.username).exclude(pk=obj.pk).exists():
messages.add_message(request, messages.WARNING, 'Det brugernavn var allerede optaget')
messages.add_message(request, messages.WARNING, "Det brugernavn var allerede optaget")
super().save_model(request, obj, form, change)

def autocomplete_view(self, request):
Expand All @@ -255,17 +274,22 @@ class AutoCompleteJsonViewCorrector(AutocompleteJsonView):

def get_queryset(self):
qs = super().get_queryset()
return qs.filter(active=True).order_by('username')
return qs.filter(active=True).order_by("username")


class PaymentAdmin(admin.ModelAdmin):
list_display = ('get_username', 'timestamp', 'get_amount_display', 'is_mobilepayment')
valid_lookups = 'member'
search_fields = ['member__username']
autocomplete_fields = ['member']
list_display = (
"get_username",
"timestamp",
"get_amount_display",
"is_mobilepayment",
)
valid_lookups = "member"
search_fields = ["member__username"]
autocomplete_fields = ["member"]

class Media:
css = {'all': ('stregsystem/select2-stregsystem.css',)}
css = {"all": ("stregsystem/select2-stregsystem.css",)}

def get_username(self, obj):
return obj.member.username
Expand All @@ -289,20 +313,20 @@ def is_mobilepayment(self, obj):

class MobilePaymentAdmin(admin.ModelAdmin):
list_display = (
'payment',
'customer_name',
'comment',
'timestamp',
'transaction_id',
'get_amount_display',
'status',
"payment",
"customer_name",
"comment",
"timestamp",
"transaction_id",
"get_amount_display",
"status",
)
valid_lookups = 'member'
search_fields = ['member__username']
autocomplete_fields = ['member', 'payment']
valid_lookups = "member"
search_fields = ["member__username"]
autocomplete_fields = ["member", "payment"]

class Media:
css = {'all': ('stregsystem/select2-stregsystem.css',)}
css = {"all": ("stregsystem/select2-stregsystem.css",)}

def get_amount_display(self, obj):
return money(obj.amount)
Expand All @@ -311,11 +335,11 @@ def get_amount_display(self, obj):
get_amount_display.admin_order_field = "amount"

# django-bug, .delete() is not called https://stackoverflow.com/questions/1471909/django-model-delete-not-triggered
actions = ['really_delete_selected']
actions = ["really_delete_selected"]

def get_actions(self, request):
actions = super(MobilePaymentAdmin, self).get_actions(request)
del actions['delete_selected']
del actions["delete_selected"]
return actions

def really_delete_selected(self, _, queryset):
Expand All @@ -326,10 +350,18 @@ def really_delete_selected(self, _, queryset):


class LogEntryAdmin(admin.ModelAdmin):
date_hierarchy = 'action_time'
list_filter = ['content_type', 'action_flag']
search_fields = ['object_repr', 'change_message', 'user__username']
list_display = ['action_time', 'user', 'content_type', 'object_id', 'action_flag', 'change_message', 'object_repr']
date_hierarchy = "action_time"
list_filter = ["content_type", "action_flag"]
search_fields = ["object_repr", "change_message", "user__username"]
list_display = [
"action_time",
"user",
"content_type",
"object_id",
"action_flag",
"change_message",
"object_repr",
]

def has_view_permission(self, request, obj=None):
return request.user.is_superuser
Expand All @@ -345,7 +377,14 @@ def has_delete_permission(self, request, obj=None):


class ThemeAdmin(admin.ModelAdmin):
list_display = ["name", "override", "begin_month", "begin_day", "end_month", "end_day"]
list_display = [
"name",
"override",
"begin_month",
"begin_day",
"end_month",
"end_day",
]
search_fields = ["name"]

@admin.action(description="Do not force chosen themes")
Expand All @@ -364,10 +403,10 @@ def force_hide(modeladmin, request, queryset):


class ProductNoteAdmin(admin.ModelAdmin):
search_fields = ('active', 'text')
search_fields = ("active", "text")
list_display = (
'active',
'text',
"active",
"text",
)

actions = [toggle_active_selected_products]
Expand Down
8 changes: 7 additions & 1 deletion stregsystem/static/stregsystem/stregsystem.css
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,11 @@ footer {
color: red;
}


.note-box {
display: inline;
padding: 2px 4px 2px 4px;
border-radius: 8px;
color: black;
background-color: red;
}

22 changes: 14 additions & 8 deletions stregsystem/templates/stregsystem/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h4>Du

{% block products %}
{% autoescape off %}
{% if product_list %}
{% if product_note_pair_list %}
<form method="post" action="/{{ room.id }}/sale/{{ member.id }}/" id="product-buy-form" name="product-buy-form">
{% csrf_token %}
<input type="hidden" value="{{ room.id }}" name="room_id">
Expand All @@ -89,27 +89,33 @@ <h4>Du
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|first %}
{% for pair in product_note_pair_list|partition:"2"|first %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id" class="linkalike">{{product.name}}</button>
{% for note in pair.note %}
<div class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</div>
{% endfor %}
<button value="{{ pair.product.id }}" name="product_id" class="linkalike">{{pair.product.name}}</button>
</td>
<td class="price">{{product.price|money}} kr</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
{% if product_list|partition:"2"|last %}
{% if product_note_pair_list|partition:"2"|last %}
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|last %}
{% for pair in product_note_pair_list|partition:"2"|last %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id" class="linkalike">{{product.name}}</button>
{% for note in pair.note %}
<div class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</div>
{% endfor %}
<button value="{{ pair.product.id }}" name="product_id" class="linkalike">{{pair.product.name}}</button>
</td>
<td class="price">{{product.price|money}} kr</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
Expand Down