Started work on expenses claim
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ExpensesClaimConfig(AppConfig):
|
||||
name = 'expenses_claim'
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Expenses claim form."""
|
||||
|
||||
from django import forms
|
||||
|
||||
|
||||
class IBANField(forms.CharField):
|
||||
"""Field that validates Bank Account numbers
|
||||
acording to the IBAN standard."""
|
||||
|
||||
def to_python(self, data):
|
||||
"""1. Remove spaces
|
||||
2. Move the country code and two check digits to the end
|
||||
3. Replace all letters so that A=10, B=11 ... Z=35"""
|
||||
|
||||
# TODO: Field validation not working?
|
||||
if not data:
|
||||
return data
|
||||
print(data)
|
||||
data.replace(" ", "")
|
||||
data = data[4:] + data[0:4]
|
||||
LETTERS = {letter: str(index) for index,
|
||||
letter in enumerate(ascii_uppercase, start=10)}
|
||||
data = data.upper()
|
||||
data = [LETTERS[char] for char in data if char in LETTERS]
|
||||
print(data)
|
||||
return ''.join(data)
|
||||
|
||||
def validate(self, data):
|
||||
"""Validate value constructed by normalize"""
|
||||
|
||||
super().validate(data)
|
||||
if int(data) % 97 != 1:
|
||||
raise forms.ValidationError("Invalid IBAN number!")
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class ExpensesClaim(forms.Form):
|
||||
"""Expenses claim form"""
|
||||
|
||||
name = forms.CharField(label='Nimi', max_length=100)
|
||||
iban = IBANField(label='IBAN', max_length=100)
|
||||
amount = forms.CharField(label="Summa", max_length=100)
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -0,0 +1,6 @@
|
||||
Dis is claim
|
||||
|
||||
<form action="" method="get">
|
||||
{{ form }}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -0,0 +1,10 @@
|
||||
"""Expenses claim urls."""
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.conf import settings
|
||||
from .views import *
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^new', claim)
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
"""Expenses claim views."""
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import *
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from .forms import ExpensesClaim
|
||||
|
||||
# Allow only GET or POST
|
||||
@require_http_methods(["GET", "POST"])
|
||||
def claim(request):
|
||||
"""Render expenses claim form."""
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ExpensesClaim(request.POST)
|
||||
if form.is_valid():
|
||||
return HttpResponse()
|
||||
|
||||
elif request.method == 'GET':
|
||||
form = ExpensesClaim()
|
||||
|
||||
return render(request, 'claim.html', {'form': form})
|
||||
|
||||
@@ -105,6 +105,7 @@ INSTALLED_APPS = [
|
||||
'phonenumber_field',
|
||||
'import_export',
|
||||
'django_filters',
|
||||
'expenses_claim',
|
||||
]
|
||||
|
||||
IMPORT_EXPORT_USE_TRANSACTIONS = True
|
||||
|
||||
+3
-1
@@ -27,6 +27,7 @@ import webapp.urls
|
||||
import infoscreen.urls
|
||||
import members.urls
|
||||
import coffee_scale.urls
|
||||
import expenses_claim.urls
|
||||
|
||||
favicon_view = RedirectView.as_view(
|
||||
url='static/img/favicon.png', permanent=True)
|
||||
@@ -39,7 +40,8 @@ urlpatterns = [
|
||||
url(r'^coffee/', include('coffee_scale.urls')),
|
||||
url(r'^kaehmy/', include('kaehmy.urls')),
|
||||
url(r'^ohlhafv/', include('ohlhafv.urls')),
|
||||
|
||||
url(r'^expenses/', include('expenses_claim.urls')),
|
||||
|
||||
# favourite icon
|
||||
url(r'^favicon\.ico$', favicon_view),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user