update
[prawokultury.git] / shop / forms.py
1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django import forms
6 from django.utils import formats
7 from django.utils.translation import ugettext_lazy as _, ugettext, get_language
8 from . import app_settings
9 from .models import Order
10 from .widgets import NumberInput
11
12
13 class OrderForm(forms.Form):
14     required_css_class = 'required'
15     backend = 'getpaid.backends.payu'
16     items = forms.IntegerField(label=_("Items"), min_value=1, initial=1,
17         widget=NumberInput(attrs={'min': '1', 'step': '1', 'class': 'cost-items'}))
18     name = forms.CharField(label=_("Name"))
19     email = forms.EmailField(label=_("Contact e-mail"))
20     address = forms.CharField(label=_("Shipping address"), widget=forms.Textarea)
21
22     accept = forms.BooleanField(label=_("Accept terms"),
23         help_text='''Akceptuję <a href='/info/regulamin-sklepu/'>regulamin sklepu</a>.''')
24
25     consent = forms.BooleanField(label=_("Consent to the processing of data"),
26         help_text='''Wyrażam zgodę na przetwarzanie moich danych osobowych w celu realizacji
27 zamówienia. Administratorem danych osobowych jest Fundacja Nowoczesna
28 Polska, ul. Marszałkowska 84/92, lok. 125, 00-514 Warszawa.
29 Zapoznałem/zapoznałam się
30 z&nbsp;<a href="http://nowoczesnapolska.org.pl/prywatnosc/">polityką prywatności Fundacji</a>.
31 Jestem świadom/świadoma, iż moja zgoda może być odwołana w każdym czasie, co skutkować będzie
32 usunięciem mojego adresu e-mail z bazy danych.''')
33
34     def __init__(self, offer, *args, **kwargs):
35         self.offer = offer
36         super(OrderForm, self).__init__(*args, **kwargs)
37         self.fields['items'].widget.attrs.update({
38             'data-cost-price': self.offer.price,
39             'data-cost-per-item': self.offer.cost_per_item,
40             'data-cost-const': self.offer.cost_const,
41             'data-decimal-separator': formats.get_format("DECIMAL_SEPARATOR"),
42             })
43
44     def save(self):
45         order = Order.objects.create(
46             offer=self.offer,
47             items=self.cleaned_data['items'],
48             name=self.cleaned_data['name'],
49             email=self.cleaned_data['email'],
50             address=self.cleaned_data['address'],
51             language_code = get_language(),
52         )
53         return order
54