forms.py 3.66 KB
Newer Older
Amap's avatar
Amap committed
1
# coding: utf8
2 3 4 5 6
from django import forms
from django.forms import ModelForm, Form
from django import forms
from django.core.validators import MinValueValidator
from .models import Panier, Paiement, Commande, Credit, Livraison
7
from dateutil.relativedelta import relativedelta
8 9
from django.utils import timezone

10
class NewCommandeForm(ModelForm):
11
    def __init__(self,*args,**kwargs):
12
        is_bureau=kwargs.pop('is_bureau')
13
        super (NewCommandeForm,self ).__init__(*args,**kwargs) # populates the post
14 15 16 17
        if is_bureau:
            self.fields['date'].queryset = Livraison.objects.filter(date__gt=(timezone.now()+relativedelta(weeks=-2)))
        else:
            self.fields['date'].queryset = Livraison.objects.filter(date__gt=timezone.now())
18

19 20 21 22
    class Meta:
        model = Commande
        fields = ['quantite','date']

23 24 25
class BaseEditCommandeForm(ModelForm):
    class Meta:
        model = Commande
26 27
        fields = ['quantite','date']

28 29
class FullEditCommandeForm(BaseEditCommandeForm):
    class Meta(BaseEditCommandeForm.Meta):
30 31 32 33 34 35
        fields = '__all__'

class SelectArticleForm(ModelForm):
    article = forms.ModelChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement")

    class Meta:
36
        exclude = ['nom','prix','coefficient_panier']
37 38 39
        model = Panier


40 41 42
class LivraisonForm(ModelForm):
    class Meta:
        model = Livraison
43
        fields = ['date','date_modif']
44 45 46 47

    def __init__(self, *args, **kwargs):
        super(LivraisonForm, self).__init__(*args, **kwargs)
        self.fields['date'].label = 'Date de livraison'
48
        self.fields['date_modif'].label = 'Date limite de modification'
49

50
class SelectLivraisonForm(ModelForm):
51 52 53
    date = forms.ModelMultipleChoiceField(queryset=Livraison.objects.all(), label="Date de livraison",  widget=forms.CheckboxSelectMultiple)

    class Meta:
54 55 56 57
        exclude = ['date', 'date_modif']
        model = Livraison

class SelectOneLivraisonForm(ModelForm):
Amap's avatar
Amap committed
58
    date = forms.ModelChoiceField(queryset=Livraison.objects.all().order_by('date').reverse(), label="Date de livraison")
59 60 61

    class Meta:
        exclude = ['date', 'date_modif']
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        model = Livraison

class PaiementForm(ModelForm):
    class Meta:
        model = Paiement
        fields = ['moyen']

    def __init__(self, *args, **kwargs):
        super(PaiementForm, self).__init__(*args, **kwargs)
        self.fields['moyen'].label = 'Moyen de paiement à ajouter'

class DelPaiementForm(ModelForm):
    paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels",  widget=forms.CheckboxSelectMultiple)

    class Meta:
        exclude = ['moyen']
        model = Paiement

80 81 82
class PanierForm(ModelForm):
    class Meta:
        model = Panier
83
        fields = ['nom','prix','coefficient_panier']
84 85 86 87 88

class DelPanierForm(ModelForm):
    paniers = forms.ModelMultipleChoiceField(queryset=Panier.objects.all(), label="Articles en vente actuellement",  widget=forms.CheckboxSelectMultiple)

    class Meta:
Amap's avatar
Amap committed
89
        exclude = ['nom','prix','coefficient_panier']
90 91
        model = Panier

92 93 94 95 96 97 98 99
class CreditForm(ModelForm):
    class Meta:
        model = Credit
        fields = ['montant','moyen','validite']

class CreditFullForm(CreditForm):
    class Meta(CreditForm.Meta):
        fields = '__all__'
100

101 102 103 104 105 106 107 108 109 110 111 112 113 114
class CreditNoteForm(forms.Form):
        """A special form to get credential and amount to connect and make a credit using the API of NoteKfet2015 server
        """
        login = forms.CharField(
            label="Pseudo note"
        )
        password = forms.CharField(
            label="Password",
            widget=forms.PasswordInput
        )
        montant = forms.FloatField(
            label="Montant"
        )