예제 #1
0
 def test_prep_value_correct_values_json(self):
     w = JSignatureWidget()
     val = [{"x": [1, 2], "y": [3, 4]}]
     val_str = '[{"x":[1,2], "y":[3,4]}]'
     val_prep = w.prep_value(val_str)
     self.assertIsInstance(val_prep, six.string_types)
     self.assertEquals(val, json.loads(val_prep))
예제 #2
0
 def test_default_media(self):
     widget = JSignatureWidget()
     media = widget.media
     media_js = list(media.render_js())
     self.assertEqual(2, len(media_js))
     media_js_str = "".join(media_js)
     self.assertIn('jSignature.min.js', media_js_str)
     self.assertIn('django_jsignature.js', media_js_str)
     media_css = list(media.render_css())
     self.assertEquals([], media_css)
예제 #3
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
예제 #4
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)
예제 #5
0
def get_form(form_obj):
    try:
        from django.urls import reverse
    except ImportError:
        from django.core.urlresolvers import reverse
    from django import forms
    from django.http import HttpResponseRedirect

    from jsignature.forms import JSignatureField
    from jsignature.widgets import JSignatureWidget

    class save_form(object):
        def save(self, request, odl=None):
            request.session['flash_alerts'].append({
                'msg': 'Saved successfully',
                'type': 'success'
            })
            return HttpResponseRedirect(
                request.POST.get('next_url', reverse('dashboard')))

    fields = {}
    field_types = {
        'text': forms.CharField,
        'radio': forms.ChoiceField,
        'checkbox': forms.MultipleChoiceField,
        'date': forms.DateField,
        'number': forms.DecimalField,
        'textarea': forms.CharField,
        'select': forms.ChoiceField,
        'signature': JSignatureField,
        'file': forms.FileField,
    }

    for form_field in form_obj.fields.filter(active=True):
        field_kwargs = {'required': form_field.required}
        if form_field.field_type == 'select':
            field_kwargs['choices'] = [('no', 'No'), ('yes', 'yes')]

        elif form_field.field_type == 'radio':
            field_kwargs['widget'] = forms.widgets.RadioSelect
            field_kwargs['choices'] = [('no', 'No'), ('yes', 'yes')]

        elif form_field.field_type == 'checkbox':
            field_kwargs['widget'] = forms.widgets.CheckboxSelectMultiple
            field_kwargs['choices'] = [('no', 'No'), ('yes', 'yes')]

        elif form_field.field_type == 'textarea':
            field_kwargs['widget'] = forms.widgets.Textarea

        elif form_field.field_type == 'signature':
            field_kwargs['widget'] = JSignatureWidget(
                jsignature_attrs={'decor-color': '#000'})

        fields[form_field.name] = field_types.get(form_field.field_type)
        if fields[form_field.name] is not None:
            fields[form_field.name] = fields[form_field.name](**field_kwargs)

    # Create form with previously created set of fields
    form = type('WorkflowForm', (forms.Form, save_form), fields)

    # Return a copy of the derived form class
    return form
예제 #6
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')
예제 #7
0
class SignatureForm(forms.Form):
	# pass
	signature = JSignatureField(widget=JSignatureWidget(jsignature_attrs={'color': '#000'}))
예제 #8
0
 def test_render_reset_button_false(self):
     w = JSignatureWidget(jsignature_attrs={'ResetButton': False})
     output = w.render(name='foo', value=None)
     self.assertEqual(0, len(pq('[type=button]', output)))
예제 #9
0
 def test_render(self):
     w = JSignatureWidget()
     output = w.render(name='foo', value=None)
     # Almost useless :/
     self.assertEqual(1, len(pq('.jsign-wrapper', output)))
     self.assertEqual(1, len(pq('[type=hidden]', output)))
예제 #10
0
 def test_prep_value_incorrect_values(self):
     w = JSignatureWidget()
     val = type('Foo')
     self.assertRaises(ValidationError, w.prep_value, val)
예제 #11
0
 def test_prep_value_empty_values(self):
     w = JSignatureWidget()
     for val in ['', [], '[]']:
         self.assertEqual('[]', w.prep_value(val))
예제 #12
0
 def test_build_jsignature_config(self):
     w = JSignatureWidget(jsignature_attrs={'width': 400})
     config = w.build_jsignature_config()
     self.assertEqual(400, config.get('width'))
     self.assertEqual(settings.JSIGNATURE_HEIGHT, config.get('height'))
예제 #13
0
 def test_build_jsignature_id(self):
     w = JSignatureWidget()
     id = w.build_jsignature_id('foo')
     self.assertEqual('jsign_foo', id)
예제 #14
0
 def test_init(self):
     w = JSignatureWidget()
     self.assertEquals({}, w.jsignature_attrs)
     given_attrs = {'width': 300, 'height': 100}
     w = JSignatureWidget(jsignature_attrs=given_attrs)
     self.assertEquals(given_attrs, w.jsignature_attrs)
예제 #15
0
 def test_media_custom_jquery(self):
     widget = JSignatureWidget()
     media = widget.media
     media_js = list(media.render_js())
     self.assertEqual(3, len(media_js))
예제 #16
0
 def test_media_in_admin(self):
     widget = JSignatureWidget()
     media = widget.media
     media_js = list(media.render_js())
     self.assertEqual(4, len(media_js))