Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Kaffe bonger #38

Merged
merged 18 commits into from
Jul 11, 2016
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
2 changes: 1 addition & 1 deletion core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Meta:
fields = ['user', 'card_number', 'disabled']


class NfcCardFilet(django_filters.FilterSet):
class NfcCardFilter(django_filters.FilterSet):
user = django_filters.CharFilter(name='user__username')

class Meta:
Expand Down
4 changes: 3 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@ class NfcCard(models.Model):
comment = models.CharField(max_length=20, blank=True)

def __str__(self):
return "NFC Card: [card_uid: %s, user=%s, intern=%s]" % (self.card_uid, self.user, self.intern)
if not self.user:
return self.card_uid
return "%s (%s)" % (self.card_uid, self.user)
4 changes: 2 additions & 2 deletions core/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from core.serializers import CardCreateSerializer, CardSerializer, UserExtendedSerializer, NfcCardCreateSerializer, \
NfcCardSerializer
from core.models import Card, User, NfcCard
from core.filters import CardFilter, UserFilter, NfcCardFilet
from core.filters import CardFilter, UserFilter, NfcCardFilter


class CardViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down Expand Up @@ -44,7 +44,7 @@ def destroy(self, request):

class NfcCardViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = (IsAuthenticated,)
filter_class = NfcCardFilet
filter_class = NfcCardFilter
Copy link
Member

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?

Copy link
Contributor Author

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.

queryset = NfcCard.objects.all()

def get_serializer_class(self):
Expand Down
4 changes: 2 additions & 2 deletions core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class CardSerializer(serializers.ModelSerializer):

class Meta:
model = Card
fields = ('id', 'user', 'card_number', 'disabled', 'comment')
fields = ('id', 'user', 'card_number', 'card_uid', 'disabled', 'comment')


class CardCreateSerializer(serializers.ModelSerializer):
class Meta:
model = Card
fields = ('user', 'card_number', 'comment')
fields = ('user', 'card_number', 'card_uid', 'comment')
extra_kwargs = {'comment': {'default': None}}


Expand Down
2 changes: 1 addition & 1 deletion core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
router = SharedAPIRootRouter()
router.register(r'core/users', UserViewSet, base_name='users')
router.register(r'core/cards', CardViewSet, base_name='voucher_cards')
router.register(r'core/nfc', NfcCardViewSet, base_name='nfc_cards')
router.register(r'core/nfc', NfcCardViewSet)

urlpatterns = patterns('',
url(r'^api/me$', me, name='me'),
Expand Down
10 changes: 7 additions & 3 deletions voucher/admin.py
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)
67 changes: 49 additions & 18 deletions voucher/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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


Expand All @@ -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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noen grunn til at dette er fjernet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enig med det, og AccessCard funker fint!

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Siden vi nå har både card_uid og card_number, burde det vært eksplisitt skrevet her at det er card_uid? Evt. hadde det jo kanskje også vært mulig og søkt på både card_uid og card_number hvis formatet på dem uansett er forskjellig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tja, kan kanskje heller kalle det nfc_card? Tenker at kort nummere er best å bare holde i garm delen av kodebasen, ettersom det var noen usikkerhet på hvor lovlig det var å logge transaksjoner og kunne linke det til kortnummere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hvis vi holder Card fullstendig utenfor så er jeg enig i at card som nå er helt greit


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')

Expand Down
5 changes: 1 addition & 4 deletions voucher/migrations/0008_auto_20160127_0512.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@


def fix_balance(apps, schema_editor):
print(repr(Wallet))
for wallet in Wallet.objects.all():
print(repr(vars(wallet)))
wallet.calculate_balance()
pass


def noop(apps, schema_editor):
Expand Down
33 changes: 33 additions & 0 deletions voucher/migrations/0010_rename_voucher.py
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')]),
),
]
69 changes: 69 additions & 0 deletions voucher/migrations/0011_coffee_vouchers.py
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')]),
),
]
Loading