<commit_before>import datetime

#Django Imports
from django import forms
from django.conf import settings

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Div, Submit
from crispy_forms.bootstrap import FormActions


#Local App Imports
import contacts.models as cont
import utils.forms as util
from utils import today


class ContactAdd(forms.ModelForm):

    phone_number = forms.CharField(label='Phone Number',
        widget=forms.TextInput(attrs={'required':'True','placeholder':'07xxxxxxx','pattern': '^07[0-9]{8}'}))

    def clean_phone_number(self):
        ''' Add custom validation for unique phone number '''
        phone_number = '+254%s'%self.cleaned_data['phone_number'][1:]
        connection = cont.Connection.objects.get_or_none(identity=phone_number)
        if connection is not None:
            raise forms.ValidationError("Phone number provided already exists",code="unique")
        return self.cleaned_data['phone_number']

    clinic_visit = forms.DateField(label='Next Clinic Visit')

    def __init__(self, *args, **kwargs):
        super(ContactAdd, self).__init__(*args, **kwargs)

        #Moved this here so that current date can be calculated for each new form

        birth_BO = [{
                'from': (today() - datetime.timedelta(days=14*365)).strftime("%Y-%m-%d"),
                'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
            }]
        due_date_BO = [{
                'from': (datetime.datetime(1970,1,1)).strftime("%Y-%m-%d"),
                'to': (today() + datetime.timedelta(weeks=4)).strftime("%Y-%m-%d"), # between 4 ....
            }, {
                'from': (today() + datetime.timedelta(weeks=36)).strftime("%Y-%m-%d"), # ...and 36 weeks in the future
                'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
            }]
        art_BO = [{
            'from': today().strftime("%Y-%m-%d"),
            'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
        }]
        self.fields['due_date'].widget = util.AngularPopupDatePicker({'required':True})
        self.fields['birthdate'].widget = util.AngularPopupDatePicker({'required':True,'datepicker-position-right':True})
        self.fields['art_initiation'].widget = util.AngularPopupDatePicker()
        self.fields['clinic_visit'].widget = util.AngularPopupDatePicker({'required':True})

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_id = 'participant-details-form'
        self.helper.label_class = 'col-sm-6'
        self.helper.field_class = 'col-sm-6'
        self.helper.form_tag = False

        self.helper.layout = Layout(
            Fieldset(
                'Study Information',
                Div(
                    Div('study_id', css_class="col-md-4"),
                    Div('anc_num', css_class="col-md-4"),
                    Div('study_group', css_class="col-md-4"),
                    css_class="row"
                ),
                Div(
                    Div('ccc_num', css_class="col-md-4"),
                    Div('send_day', css_class="col-md-4", ng_if="participant.study_group != 'control'" ),
                    Div('send_time', css_class="col-md-4", ng_if="participant.study_group != 'control'" ),
                    css_class="row",
                ),
            ),<commit_msg>feat(participant-add) close #307 min/max dates on enroll<commit_after>import datetime

#Django Imports
from django import forms
from django.conf import settings

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, Div, Submit
from crispy_forms.bootstrap import FormActions


#Local App Imports
import contacts.models as cont
import utils.forms as util
from utils import today


class ContactAdd(forms.ModelForm):

    phone_number = forms.CharField(label='Phone Number',
        widget=forms.TextInput(attrs={'required':'True','placeholder':'07xxxxxxx','pattern': '^07[0-9]{8}'}))

    def clean_phone_number(self):
        ''' Add custom validation for unique phone number '''
        phone_number = '+254%s'%self.cleaned_data['phone_number'][1:]
        connection = cont.Connection.objects.get_or_none(identity=phone_number)
        if connection is not None:
            raise forms.ValidationError("Phone number provided already exists",code="unique")
        return self.cleaned_data['phone_number']

    clinic_visit = forms.DateField(label='Next Clinic Visit')

    def __init__(self, *args, **kwargs):
        super(ContactAdd, self).__init__(*args, **kwargs)

        #Moved this here so that current date can be calculated for each new form

        birth_BO = [{
                'from': (today() - datetime.timedelta(days=14*365)).strftime("%Y-%m-%d"),
                'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
            }]
        due_date_BO = [{
                'from': (datetime.datetime(1970,1,1)).strftime("%Y-%m-%d"),
                'to': (today() + datetime.timedelta(weeks=4)).strftime("%Y-%m-%d"), # between 4 ....
            }, {
                'from': (today() + datetime.timedelta(weeks=36)).strftime("%Y-%m-%d"), # ...and 36 weeks in the future
                'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
            }]
        art_BO = [{
            'from': today().strftime("%Y-%m-%d"),
            'to': (datetime.datetime(2100,1,1)).strftime("%Y-%m-%d"),
        }]
        self.fields['due_date'].widget = util.AngularPopupDatePicker({'required':True},min=28)
        self.fields['birthdate'].widget = util.AngularPopupDatePicker(
            {'required':True,'datepicker-position-right':True},max=-5110 # 14 years or older 
        )
        self.fields['art_initiation'].widget = util.AngularPopupDatePicker(max=0)
        self.fields['clinic_visit'].widget = util.AngularPopupDatePicker({'required':True}, min=7)

        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_id = 'participant-details-form'
        self.helper.label_class = 'col-sm-6'
        self.helper.field_class = 'col-sm-6'
        self.helper.form_tag = False

        self.helper.layout = Layout(
            Fieldset(
                'Study Information',
                Div(
                    Div('study_id', css_class="col-md-4"),
                    Div('anc_num', css_class="col-md-4"),
                    Div('study_group', css_class="col-md-4"),
                    css_class="row"
                ),
                Div(
                    Div('ccc_num', css_class="col-md-4"),
                    Div('send_day', css_class="col-md-4", ng_if="participant.study_group != 'control'" ),
                    Div('send_time', css_class="col-md-4", ng_if="participant.study_group != 'control'" ),
                    css_class="row",
                ),
            ),
{'fraction_non_alphanumeric': 0.1544256120527307, 'fraction_numerical': 0.017528610748949732, 'mean_word_length': 2.502790461694571, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1021038', 'n_tokens_mistral': 2158, 'n_tokens_neox': 1993, 'n_words': 362}