Example #1
0
class SignatureForm(forms.Form):
    signature = JSignatureField()
    file_name = None

    def has_signature(self):
        return self.is_valid() and self.cleaned_data.get('signature')

    def signature_file(self):
        if not self.file_name:
            self.file_name = "%s.png" % uuid.uuid4()
        return self.file_name

    def signature_path(self):
        return os.path.join(settings.MEDIA_ROOT,
                            "signatures/%s" % self.signature_file())

    def raw_signature_data(self):
        signature_picture = draw_signature(self.cleaned_data.get('signature'))
        output = StringIO.StringIO()
        signature_picture.save(output, format="PNG")
        contents = output.getvalue()
        output.close()
        image_data = base64.b64encode(contents)
        return image_data

    def save_signature(self):
        signature_picture = draw_signature(self.cleaned_data.get('signature'))
        signature_picture.save(self.signature_path())
        return self.signature_file()
Example #2
0
class UserForm(ModelForm):
    #user_signature = JSignatureField()
    user_signature = JSignatureField(widget=JSignatureWidget(
        jsignature_attrs={'color': '#333'}))

    class Meta:
        model = ApplicationForm
        fields = '__all__'
        widgets = {
            'convicted_or_not':
            forms.RadioSelect,
            'allowed_in_usa':
            forms.RadioSelect,
            'work_eligible_usa':
            forms.RadioSelect,
            'domicile_address':
            forms.RadioSelect,
            'law_suite':
            forms.RadioSelect,
            'compensation_claim':
            forms.RadioSelect,
            'other_city':
            forms.RadioSelect,
            'Martial_status':
            forms.Select(attrs={
                'class': 'form-control',
                'required': 'required'
            }),
            'gender':
            forms.Select(attrs={
                'class': 'form-control',
                'required': 'required'
            })
        }

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        for key in self.fields:
            self.fields[key].required = False
Example #3
0
class ApplicationForm(autocomplete_light.ModelForm):
    # pass
    # Date today script
    ADVERTISEMENT_CHOICES = (
        ('Seaway', 'Seaway'),
        ('Buhay Marino', 'Buhay Marino'),
        ('Harbor Scope', 'Harbor Scope'),
        ('Newspaper', 'Newspaper'),
    )
    INTERNET_CHOICES = (
        ('www.manship.com', 'www.manship.com'),
        ('www.seamanjobsite.com', 'www.seamanjobsite.com'),
        ('www.pinoyseaman.com', 'www.pinoyseaman.com'),
        ('www.crewtoo.com', 'www.crewtoo.com'),
    )
    today = date.today()
    today = today.strftime("%m/%d/%y")
    application_date = forms.DateField(widget=forms.TextInput(
        attrs={
            'class': "form-control",
            'placeholder': "Date of Application",
            'data-toggle': 'tooltip',
            'readonly': 'readonly',
            'value': today
        }))
    signature = JSignatureField(widget=JSignatureWidget(
        jsignature_attrs={'color': '#000'}))
    alternative_position = forms.ModelChoiceField(
        widget=forms.Select,
        queryset=Rank.objects.filter(hiring=1).order_by('order'))
    position_applied = forms.ModelChoiceField(
        widget=forms.Select,
        queryset=Rank.objects.filter(hiring=1).order_by('order'))
    source = forms.ModelChoiceField(
        widget=forms.RadioSelect,
        error_messages={
            'required': 'Please let us know how you learned our company'
        },
        queryset=Sources.objects.filter(~Q(source="Friends or Relatives")))
    advertisements = forms.ChoiceField(
        widget=forms.Select(attrs={'class': "specific"}),
        choices=ADVERTISEMENT_CHOICES,
        required=False)
    internet = forms.ChoiceField(widget=forms.Select(attrs={
        'class': "specific",
        'required': 'required'
    }),
                                 choices=INTERNET_CHOICES,
                                 required=False)
    referred_by = forms.CharField(widget=autocomplete_light.TextWidget(
        'ReferrerAutocomplete',
        attrs={
            'placeholder': 'Search Referrer',
            'class': "specific"
        }),
                                  required=False)
    application_picture = forms.CharField()
    scheme = forms.CharField()
    http_host = forms.CharField()
    essay = forms.CharField(
        widget=forms.Textarea(attrs={'class': "form-control essay"}),
        required=False)

    class Meta:
        model = ApplicationForm
        fields = ('application_date', 'alternative_position',
                  'position_applied')

    def save(self, commit=True):
        print self.cleaned_data
        advertisements = self.cleaned_data['advertisements']
        internet = self.cleaned_data['internet']
        referred_by = self.cleaned_data['referred_by']
        essay = self.cleaned_data['essay']
        application_picture = self.cleaned_data['application_picture']
        scheme = self.cleaned_data['scheme']
        http_host = self.cleaned_data['http_host']
        # Sources Validation
        if advertisements:
            self.cleaned_data['specific'] = advertisements
            self.cleaned_data.pop("advertisements")
        elif internet:
            self.cleaned_data['specific'] = internet
            self.cleaned_data.pop("internet")
        # Reffered By and (Friends or Relatives) validation
        # If not in the referrers Pool it will be considerer as a friend or relative
        elif referred_by:
            try:
                referred_by = ReferrersPool.objects.get(name=referred_by)
            except:
                self.cleaned_data['source'] = Sources.objects.get(
                    source='Friends or Relatives')
            self.cleaned_data['specific'] = referred_by
            self.cleaned_data.pop("referred_by")
        else:
            self.cleaned_data['specific'] = ''

        signature = self.cleaned_data['signature']
        source = self.cleaned_data['source']
        specific = self.cleaned_data['specific']
        position_applied = self.cleaned_data['position_applied']
        userprofile = UserProfile.objects.latest('id')
        first_name = userprofile.first_name
        middle_name = userprofile.middle_name
        last_name = userprofile.last_name
        file_name = first_name + middle_name + last_name
        file_name = "".join(file_name.split())

        application = super(ApplicationForm, self).save(commit=False)
        specifics = Specifics.objects.get_or_create(specific=specific)
        if specifics:
            specifics = Specifics.objects.get(specific=specific)

        # Signature script on saving in a folder
        signature_path = "media/signature/application-form/" + file_name + ".png"
        if signature:
            signature_picture = draw_signature(signature)
            _signature_file_path = draw_signature(signature, as_file=True)
            signature_file_path = settings.MEDIA_ROOT + "/signatures/application-form/"
            shutil.move(_signature_file_path, signature_file_path)
            _signature_file_path = _signature_file_path.replace(
                '/tmp/', 'signatures/application-form/')

        essays = Essay.objects.get_or_create(essay=essay)
        if essays:
            essays = Essay.objects.get(essay=essay)

        # Webcam script on saving in a folder
        try:
            tmp_application_picture = application_picture
            tmp_application_picture = tmp_application_picture.replace(
                scheme + "://" + http_host + "/", "")
            # print tmp_application_picture
            application_picture = "media/photos/application-form/" + file_name + ".jpg"
            os.rename(tmp_application_picture, application_picture)
            print application_picture
            application_picture = application_picture.replace("media/", "")
            print application_picture
        except:
            print "%s - %s" % (sys.exc_info()[0], sys.exc_info()[1])

        appsource = AppSource.objects.get_or_create(source=source,
                                                    specific=specifics)
        if appsource:
            appsource = AppSource.objects.get(source=source,
                                              specific=specifics)
        application.user = userprofile
        application.application_source = appsource
        application.picture = application_picture
        application.essay = essays
        application.signature = _signature_file_path
        application.save()
        try:
            referrer = ReferrersPool.objects.get(name=referred_by)
        except:
            referrer = ReferrersPool.objects.get_or_create(name='')
            referrer = ReferrersPool.objects.get(name='')
        self.cleaned_data['signature'] = _signature_file_path
        self.cleaned_data['user'] = userprofile
        self.cleaned_data['picture'] = application_picture
        self.cleaned_data['position'] = position_applied
        self.cleaned_data['referrer'] = referrer
        self.cleaned_data.pop("essay")
        self.cleaned_data.pop("position_applied")
        self.cleaned_data.pop("application_picture")
        self.cleaned_data.pop("source")
        self.cleaned_data.pop("http_host")
        self.cleaned_data.pop("alternative_position")
        self.cleaned_data.pop("scheme")
        self.cleaned_data.pop("application_date")
        try:
            self.cleaned_data.pop("advertisements")
        except:
            pass
        try:
            self.cleaned_data.pop("specific")
        except:
            pass
        try:
            self.cleaned_data.pop("referred_by")
        except:
            pass
        try:
            self.cleaned_data.pop("internet")
        except:
            pass
        value = self.cleaned_data
        MarinersProfile.objects.create(**value)
Example #4
0
class SignatureForm(forms.Form):
    signature = JSignatureField()
class SupplierIntakeForm(forms.ModelForm):

    supervisor_name = forms.ModelChoiceField(
        label="Supervisor Name",
        queryset=Employee.objects.all().filter(is_supervisor=True),
        widget=forms.Select(attrs={'class': 'form-control'}))

    supplier_name = forms.ModelChoiceField(
        label="Supplier Name",
        queryset=Supplier.objects.all().filter(),
        widget=forms.Select(attrs={'class': 'form-control'}))

    total_box_count = forms.FloatField(
        label="Number of Boxes",
        widget=forms.NumberInput(attrs={'class': 'form-control'}),
        min_value=0)

    passed_float_box_count = forms.FloatField(
        label="Number of Passed Float Boxes",
        required=False,
        widget=forms.NumberInput(attrs={'class': 'form-control'}),
        min_value=0)

    is_floated = forms.BooleanField(
        label="Floated?",
        required=False,
        widget=forms.CheckboxInput(attrs={
            'class': 'form-check-input',
            'id': "is_floated"
        }))

    proof_file = forms.FileField(
        label="Pictures of Batch",
        widget=forms.ClearableFileInput(attrs={
            'multiple': True,
            'class': 'form-control'
        }))

    supervisor_signature = JSignatureField(label="Supervisor Signature")

    representative_name = forms.CharField(
        label="Seller Rep. Name",
        widget=forms.TextInput(attrs={'class': 'form-control'}))

    representative_signature = JSignatureField(label="Seller Rep. Signature ")

    def clean(self):
        cleaned_data = super().clean()
        total_box_count = cleaned_data.get("total_box_count")
        passed_float_box_count = cleaned_data.get("passed_float_box_count")

        if total_box_count and passed_float_box_count:
            # Only do something if both fields are valid so far.
            if passed_float_box_count > total_box_count:
                msg = "Passed float count can not be more than total box count"
                self.add_error('passed_float_box_count', msg)

    class Meta:
        model = Intake
        fields = [
            "supervisor_name", "supplier_name", "total_box_count",
            "passed_float_box_count", "is_floated", "proof_file",
            "supervisor_signature", "representative_name",
            "representative_signature"
        ]
Example #6
0
 def test_widget(self):
     f = JSignatureField()
     self.assertIsInstance(f.widget, JSignatureWidget)
Example #7
0
 def test_to_python_incorrect_values(self):
     f = JSignatureField()
     val = 'foo'
     self.assertRaises(ValidationError, f.to_python, val)
Example #8
0
 def test_to_python_correct_values(self):
     f = JSignatureField()
     val = '[{"x":[1,2], "y":[3,4]}]'
     self.assertEquals([{'x': [1, 2], 'y': [3, 4]}], f.to_python(val))
Example #9
0
 def test_to_python_empty_values(self):
     f = JSignatureField()
     for val in ['', [], '[]']:
         self.assertIsNone(f.to_python(val))
Example #10
0
class AppForms(forms.ModelForm):
	signatures = JSignatureField(widget=JSignatureWidget(jsignature_attrs={'color': '#000'}), error_messages={'required': 'Please do not forget to sign before submitting'})	
	essay = forms.CharField(widget=forms.Textarea(attrs={'class':"form-control essay", 'id':"essay"}))
	class Meta:
		model = AppForm
		fields = ('essay', 'signatures')
Example #11
0
class SignatureForm(forms.Form):
	# pass
	signature = JSignatureField(widget=JSignatureWidget(jsignature_attrs={'color': '#000'}))
Example #12
0
class ConsultationForm(forms.Form):
    client = forms.CharField()
    signature = JSignatureField()