GlucosesForm   A
last analyzed

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 3 1
1
# coding: utf-8
2
from dj_diabetes.forms.base import pref_filter
3
from dj_diabetes.models.glucoses import Glucoses
4
5
6
from django import forms
7
from django.conf import settings
8
9
10
class GlucosesForm(forms.ModelForm):
11
    """
12
        glucoses Form
13
    """
14
    glucose = forms.IntegerField(widget=forms.TextInput(
15
        attrs={'class': 'form-control', 'type': 'number'}))
16
    # get the list of pref to get the value in the dropdown
17
    insulin = forms.IntegerField(widget=forms.TextInput(
18
        attrs={'class': 'form-control', 'type': 'number'}))
19
    moment = forms.ChoiceField(widget=forms.Select(
20
        attrs={'class': 'form-control'}))
21
    # to " suit " the HTML textearea
22
    comment = forms.CharField(widget=forms.Textarea(
23
        {'class': 'form-control', 'rows': '3'}))
24
    date_glucoses = forms.DateField(widget=forms.TextInput(
25
        {'class': 'form-control'}))
26
    hour_glucoses = forms.TimeField(widget=forms.TextInput(
27
        {'class': 'form-control'}))
28
29
    class Meta:
30
        model = Glucoses
31
        # Do the user uses insulin ?
32
        if settings.DJ_DIABETES['insulin'] is True:
33
            fields = ['moment', 'comment', 'glucose', 'insulin',
34
                      'date_glucoses', 'hour_glucoses']
35
        else:
36
            fields = ['moment', 'comment', 'glucose',
37
                      'date_glucoses', 'hour_glucoses']
38
39
    def __init__(self, *args, **kwargs):
40
        super(GlucosesForm, self).__init__(*args, **kwargs)
41
        self.fields['moment'].choices = pref_filter("moment")
42