-
Notifications
You must be signed in to change notification settings - Fork 9
Kaffe bonger #38
Kaffe bonger #38
Changes from all commits
6f4dc66
7bb0049
9eaaacd
8552870
f1be505
837be7b
d4b2fc6
d185598
a924c67
0fc93ca
1284a83
c05dafb
ccb90fe
be5c6fd
4cca494
eff8c51
f6ed59f
029d0df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from django.contrib import admin | ||
from voucher.models import Wallet, WorkLog, UseLog | ||
from voucher.models import Wallet, WorkLog, UseLog, VoucherWallet, CoffeeWallet, VoucherUseLog, CoffeeUseLog, \ | ||
CoffeeRegisterLog | ||
|
||
|
||
class WalletAdmin(admin.ModelAdmin): | ||
model = Wallet | ||
readonly_fields = ('cached_balance',) | ||
|
||
|
||
admin.site.register(Wallet, WalletAdmin) | ||
admin.site.register(VoucherWallet, WalletAdmin) | ||
admin.site.register(CoffeeWallet, WalletAdmin) | ||
admin.site.register(CoffeeRegisterLog) | ||
admin.site.register(WorkLog) | ||
admin.site.register(UseLog) | ||
admin.site.register(VoucherUseLog) | ||
admin.site.register(CoffeeUseLog) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ | |
from django.utils.translation import ugettext_lazy as _ | ||
from django.utils.timezone import get_current_timezone | ||
|
||
from core.models import Card | ||
from voucher.models import UseLog, Wallet, WorkLog | ||
from core.models import NfcCard | ||
from voucher.models import UseLog, Wallet, WorkLog, VoucherWallet, CoffeeWallet, VoucherUseLog, CoffeeUseLog, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeg synder garantert selv, men kan være en fordel å sortere slike imports alfabetisk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Om du ønsker det, kan jeg fikse det. Ser bare ikke noe serlig poeng med å gå igjennom det ekstra-arbeidet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Går nok helt fint, men sikkert nyttig for oss begge å bli påminnet en gang i blant :p |
||
CoffeeRegisterLog | ||
from voucher.utils import get_valid_semesters | ||
|
||
|
||
|
@@ -21,45 +22,75 @@ def apply_date_filter(queryset, value, field, lte): | |
|
||
|
||
class UseLogFilter(django_filters.FilterSet): | ||
user = django_filters.CharFilter(name='wallet__user__username') | ||
semester = django_filters.CharFilter(name='wallet__semester') | ||
date_from = django_filters.MethodFilter(action='filter_date_from') | ||
date_to = django_filters.MethodFilter(action='filter_date_to') | ||
|
||
class Meta: | ||
model = UseLog | ||
fields = ['id', 'user', 'semester'] | ||
|
||
def filter_date_from(self, queryset, value): | ||
return apply_date_filter(queryset, value, 'date_spent', lte=False) | ||
|
||
def filter_date_to(self, queryset, value): | ||
return apply_date_filter(queryset, value, 'date_spent', lte=True) | ||
|
||
|
||
class VoucherUseLogFilter(UseLogFilter): | ||
user = django_filters.CharFilter(name='wallet__user__username') | ||
|
||
class Meta: | ||
model = VoucherUseLog | ||
fields = ['id', 'user', 'semester'] | ||
|
||
|
||
class CoffeeUseLogFilter(UseLogFilter): | ||
card = django_filters.CharFilter(name='wallet__card__card_uid') | ||
|
||
class Meta: | ||
model = CoffeeUseLog | ||
fields = ['id', 'card', 'semester'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noen grunn til at dette er fjernet? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fjernet det ettersom det var snakk om at man ikke ville linke kortnummere med transaksjoner. I tillegg er det vel ingen steder som bruker denne funksjonaliteten? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. Hvis vi går for det så burde vi i så fall kanskje bare fjerne alt som er av koblinger mellom Card og wallets. Hva med å rename Card også, så blir det tydeligere hva det brukes til? F.eks. AccessCard eller noe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enig med det, og AccessCard funker fint! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La oss mekke en issue på det, så tar vi det utenom dette her. Skal jeg mekke issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvis du har noen ting du vil skrive om det, er det kanskje best at du gjør det :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opprettet i #39 |
||
|
||
|
||
class WalletFilter(django_filters.FilterSet): | ||
user = django_filters.CharFilter(name='user__username') | ||
card_number = django_filters.MethodFilter(action='filter_card_number') | ||
valid = django_filters.MethodFilter(action='filter_active') | ||
|
||
class Meta: | ||
model = Wallet | ||
fields = ['user', 'card_number', 'semester'] | ||
|
||
def filter_card_number(self, queryset, value): | ||
cards = Card.objects.filter(card_number=value) | ||
if cards.exists(): | ||
return queryset.filter(user=cards.first().user) | ||
return queryset.none() | ||
fields = ['semester'] | ||
|
||
def filter_active(self, queryset, value): | ||
return queryset.filter(semester__in=get_valid_semesters()) | ||
|
||
|
||
class WorkLogFilter(django_filters.FilterSet): | ||
user = django_filters.CharFilter(name='wallet__user__username') | ||
class VoucherWalletFilter(WalletFilter): | ||
user = django_filters.CharFilter(name='user__username') | ||
|
||
class Meta: | ||
model = VoucherWallet | ||
fields = ['user', 'semester'] | ||
|
||
|
||
class CoffeeWalletFilter(WalletFilter): | ||
card = django_filters.CharFilter(name='nfccard__card_uid') | ||
|
||
class Meta: | ||
model = CoffeeWallet | ||
fields = ['card', 'semester'] | ||
|
||
|
||
class RegisterLogFilter(django_filters.FilterSet): | ||
issuing_user = django_filters.CharFilter(name='issuing_user__username') | ||
semester = django_filters.CharFilter(name='wallet__semester') | ||
|
||
|
||
class CoffeeRegisterLogFilter(RegisterLogFilter): | ||
card = django_filters.CharFilter(name='wallet__card__card_uid') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Siden vi nå har både There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tja, kan kanskje heller kalle det There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hvis vi holder |
||
|
||
class Meta: | ||
model = CoffeeRegisterLog | ||
fields = ['id', 'card', 'issuing_user', 'semester'] | ||
|
||
|
||
class WorkLogFilter(RegisterLogFilter): | ||
user = django_filters.CharFilter(name='wallet__user__username') | ||
date_from = django_filters.MethodFilter(action='filter_date_from') | ||
date_to = django_filters.MethodFilter(action='filter_date_to') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('voucher', '0009_uselog_issuing_user'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel('Wallet', 'VoucherWallet'), | ||
migrations.RenameModel('UseLog', 'VoucherUseLog'), | ||
|
||
migrations.AlterField( | ||
model_name='worklog', | ||
name='wallet', | ||
field=models.ForeignKey(to='voucher.VoucherWallet', related_name='worklogs'), | ||
), | ||
migrations.AlterField( | ||
model_name='voucheruselog', | ||
name='wallet', | ||
field=models.ForeignKey(to='voucher.VoucherWallet', related_name='uselogs'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='voucherwallet', | ||
unique_together=set([('user', 'semester')]), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0006_nfccard'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('voucher', '0010_rename_voucher'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='CoffeeUseLog', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), | ||
('date_spent', models.DateTimeField(auto_now_add=True)), | ||
('comment', models.CharField(blank=True, max_length=100, null=True)), | ||
('vouchers', models.IntegerField()), | ||
('issuing_user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'ordering': ['-date_spent'], | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='CoffeeWallet', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), | ||
('cached_balance', models.DecimalField(max_digits=8, decimal_places=2, editable=False, default=0)), | ||
('cached_vouchers', models.DecimalField(max_digits=8, decimal_places=2, editable=False, default=0)), | ||
('cached_vouchers_used', models.IntegerField(editable=False, default=0)), | ||
('card', models.ForeignKey(to='core.NfcCard')), | ||
('semester', models.ForeignKey(to='core.Semester')), | ||
], | ||
options={ | ||
'ordering': ['card__card_uid'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='CoffeeRegisterLog', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)), | ||
('date_issued', models.DateTimeField(auto_now_add=True)), | ||
('comment', models.CharField(blank=True, max_length=100, null=True)), | ||
('vouchers', models.DecimalField(decimal_places=2, max_digits=8)), | ||
('issuing_user', models.ForeignKey(to=settings.AUTH_USER_MODEL)), | ||
('wallet', models.ForeignKey(to='voucher.CoffeeWallet', related_name='registerlogs')), | ||
], | ||
options={ | ||
'ordering': ['-date_issued'], | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='coffeeuselog', | ||
name='wallet', | ||
field=models.ForeignKey(to='voucher.CoffeeWallet', related_name='uselogs'), | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='coffeewallet', | ||
unique_together=set([('card', 'semester')]), | ||
), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Denne klassen brukes ikke lenger? Kan fjernes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Her har det også skjedd noe rart når jeg merga. Det viewet skal være der.