示例#1
0
 def helper(self):
     """django-uni-form layout specification."""
     helper = FormHelper()
     if self.instance and self.instance.id:
         helper.form_action = reverse("media-edit", args=[self.instance.id])
         delete = Button("delete", "Delete This Item", css_class="secondaryAction")
         helper.add_input(delete)
     else:
         helper.form_action = reverse("media-add")
         another = Submit("save_add", "Save and Add Another", css_class="primaryAction")
         helper.add_input(another)
     submit = Submit("save", "Save", css_class="primaryAction")
     helper.add_input(submit)
     helper.form_method = "POST"
     return helper
示例#2
0
    def test_uni_form_with_helper_attributes(self):
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
    
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form form form_helper %}
        """)        

        # now we render it
        c = Context({'form': TestForm(), 'form_helper': form_helper})            
        html = template.render(c)        
        
        # Lets make sure everything loads right
        self.assertTrue('<form' in html)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        
        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False 
        html = template.render(c)        
        self.assertFalse('<form' in html)        
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#3
0
    def helper(self):
        helper = FormHelper()
        helper.add_input(Submit('submit', _('Search')))

        helper.form_action = reverse('search:search')
        helper.form_method = 'get'
        return helper
示例#4
0
    def test_uni_form_formset_with_helper_without_layout(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)

        form_helper = FormHelper()
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'

        TestFormSet = formset_factory(TestForm, extra=3)
        testFormSet = TestFormSet()

        c = Context({
            'testFormSet': testFormSet,
            'formset_helper': form_helper,
            'csrf_token': _get_new_csrf_key()
        })
        html = template.render(c)

        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(
            html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        # Check formset management form
        self.assertTrue('form-TOTAL_FORMS' in html)
        self.assertTrue('form-INITIAL_FORMS' in html)
        self.assertTrue('form-MAX_NUM_FORMS' in html)

        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
示例#5
0
 def helper(self):
     helper = FormHelper()
     submit = Submit('submit', 'Submit your application')
     helper.add_input(submit)
     helper.form_action = self.form_action
     helper.form_method = 'POST'
     return helper
示例#6
0
def view_helper_set_action(request):

    # Create the form
    form = TestForm()

    # create a formHelper
    helper = FormHelper()

    # add in a submit and reset button
    submit = Submit('send-away', 'Send to other page')
    helper.add_input(submit)

    helper.form_action = 'view_helper'
    helper.form_method = 'GET'

    # create the response dictionary
    response_dictionary = {
        'form': form,
        'helper': helper,
        'title': 'view helper action'
    }

    return render_to_response('test_app/generic_form_test.html',
                              response_dictionary,
                              context_instance=RequestContext(request))
示例#7
0
文件: tests.py 项目: Bauke900/dnevnik
    def test_uni_form_formset(self):
        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """
        )

        form_helper = FormHelper()
        form_helper.form_id = "thisFormsetRocks"
        form_helper.form_class = "formsets-that-rock"
        form_helper.form_method = "POST"
        form_helper.form_action = "simpleAction"

        TestFormSet = formset_factory(TestForm, extra=3)
        testFormSet = TestFormSet()

        c = Context({"testFormSet": testFormSet, "formset_helper": form_helper, "csrf_token": _get_new_csrf_key()})
        html = template.render(c)

        self.assertEqual(html.count("<form"), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse("simpleAction") in html)
示例#8
0
    def test_uni_form_formset_with_helper_without_layout(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)
        
        form_helper = FormHelper()    
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'
                
        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()
        
        c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper, 'csrf_token': _get_new_csrf_key()})
        html = template.render(c)        

        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        # Check formset management form
        self.assertTrue('form-TOTAL_FORMS' in html)
        self.assertTrue('form-INITIAL_FORMS' in html)
        self.assertTrue('form-MAX_NUM_FORMS' in html)
    
        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
示例#9
0
    def test_uni_form_formset(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)
        
        form_helper = FormHelper()    
        form_helper.form_id = 'this-formset-rocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
                
        from django.forms.models import formset_factory
        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()
        
        c = Context({'testFormSet': testFormSet, 'formset_helper': form_helper})
        html = template.render(c)        

        self.assertTrue('<form' in html)
        self.assertEqual(html.count('<form'), 1)
        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-formset-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
示例#10
0
 def helper(self):
     helper = FormHelper()
     helper.add_input(Submit('submit', _('Search')))
     
     helper.form_action = reverse('search:search')
     helper.form_method = 'get'
     return helper
示例#11
0
    def set_helper(self):
        print "AadhaarLoginForm.helper In helper"
        #form = AadhaarLoginForm()
        helper = FormHelper()
        reset = Reset('', 'Reset')
        helper.add_input(reset)
        submit = Submit('', 'Authenticate')
        helper.add_input(submit)
        helper.form_action = '/aadhaar/authenticate/' + self.detail
        helper.form_method = 'POST'
        helper.form_class = "blueForms"

        style = """
<style>
fieldset.formRow {
         margin-bottom: 1em;
         border-width: 0 0 1px 0;
         border-color:#CCCCCC;
         border-style:solid;
}
</style>
"""
        common_layout = Layout(
            Fieldset(
                'Required Parameters',
                'aadhaar_id',
                'aadhaar_attributes',
            ))
        pi_layout = Layout(
            Fieldset(
                "Personally Identifiable Information",
                'aadhaar_pi_match',
                'aadhaar_name',
                'aadhaar_dob',
                'aadhaar_age',
                'aadhaar_gender',
                'aadhaar_email',
                'aadhaar_phone',
            ))
        pa_layout = Layout(
            Fieldset("Address", 'aadhaar_pa_match', 'aadhaar_co',
                     'aadhaar_house', 'aadhaar_street', 'aadhaar_landmark',
                     'aadhaar_locality', 'aadhaar_vtc', 'aadhaar_subdist',
                     'aadhaar_district', 'aadhaar_state', 'aadhaar_pincode',
                     'aadhaar_postoffice'))

        if self.detail == "personal":
            layout = Layout(common_layout, pi_layout)
        elif self.detail == "address":
            layout = Layout(common_layout, pa_layout)
        else:
            layout = Layout(common_layout, pi_layout, pa_layout)

        helper.layout = layout

        self.helper = helper
示例#12
0
 def helper(self):
     form = LoginForm()
     helper = FormHelper()
     reset = Reset('','Reset')
     helper.add_input(reset)
     submit = Submit('','Log In')
     helper.add_input(submit)
     helper.form_action = '/account/login'
     helper.form_method = 'POST'
     return helper
示例#13
0
 def helper(self):
     form = SignupForm()
     helper = FormHelper()
     reset = Reset('','Reset')
     helper.add_input(reset)
     submit = Submit('','Sign Up')
     helper.add_input(submit)
     helper.form_action = '/account/signup'
     helper.form_method = 'POST'
     return helper
示例#14
0
 def helper(self):
     form = CreateClientForm()
     helper = FormHelper()
     reset = Reset('','Reset')
     helper.add_input(reset)
     submit = Submit('','Create Client')
     helper.add_input(submit)
     helper.form_action = '/account/clients'
     helper.form_method = 'POST'
     return helper
示例#15
0
 def helper(self):
     form = LoginForm()
     helper = FormHelper()
     reset = Reset('','Reset')
     helper.add_input(reset)
     submit = Submit('','Authenticate')
     helper.add_input(submit)
     helper.form_action = '/account/aadhaar/authenticate'
     helper.form_method = 'POST'
     return helper
示例#16
0
 def set_helper(self):
     helper = FormHelper()
     reset = Reset('','Reset')
     helper.add_input(reset)
     submit = Submit('','Submit')
     helper.add_input(submit)
     helper.form_action = ''
     helper.form_method = 'POST'
     helper.form_class="blueForms"
     self.helper = helper
示例#17
0
文件: forms.py 项目: zuii/oauth2app
 def helper(self):
     form = SignupForm()
     helper = FormHelper()
     reset = Reset('', 'Reset')
     helper.add_input(reset)
     submit = Submit('', 'Sign Up')
     helper.add_input(submit)
     helper.form_action = '/account/signup'
     helper.form_method = 'POST'
     return helper
示例#18
0
文件: forms.py 项目: zuii/oauth2app
 def helper(self):
     form = LoginForm()
     helper = FormHelper()
     reset = Reset('', 'Reset')
     helper.add_input(reset)
     submit = Submit('', 'Log In')
     helper.add_input(submit)
     helper.form_action = '/account/login'
     helper.form_method = 'POST'
     return helper
示例#19
0
 def helper(self):
     form = LoginForm()
     helper = FormHelper()
     reset = Reset("", "Reset")
     helper.add_input(reset)
     submit = Submit("", "Log In")
     helper.add_input(submit)
     helper.form_action = "/account/login"
     helper.form_method = "POST"
     return helper
示例#20
0
 def helper(self):
     form = SignupForm()
     helper = FormHelper()
     reset = Reset("", "Reset")
     helper.add_input(reset)
     submit = Submit("", "Sign Up")
     helper.add_input(submit)
     helper.form_action = "/account/signup"
     helper.form_method = "POST"
     return helper
示例#21
0
 def set_helper(self):
     helper = FormHelper()
     reset = Reset('', 'Reset')
     helper.add_input(reset)
     submit = Submit('', 'Submit')
     helper.add_input(submit)
     helper.form_action = ''
     helper.form_method = 'POST'
     helper.form_class = "blueForms"
     self.helper = helper
示例#22
0
文件: forms.py 项目: zuii/oauth2app
 def helper(self):
     form = CreateClientForm()
     helper = FormHelper()
     reset = Reset('', 'Reset')
     helper.add_input(reset)
     submit = Submit('', 'Create Client')
     helper.add_input(submit)
     helper.form_action = '/account/clients'
     helper.form_method = 'POST'
     return helper
示例#23
0
 def helper(self):
     form = GroupForm()
     helper = FormHelper()
     reset = Reset("", "Reset")
     helper.add_input(reset)
     submit = Submit("", "Create Group")
     helper.add_input(submit)
     helper.form_action = "/account/groups"
     helper.form_method = "POST"
     return helper
示例#24
0
 def helper(self):
     form = LoginForm()
     helper = FormHelper()
     reset = Reset('', 'Reset')
     helper.add_input(reset)
     submit = Submit('', 'Authenticate')
     helper.add_input(submit)
     helper.form_action = '/account/aadhaar/authenticate'
     helper.form_method = 'POST'
     return helper
示例#25
0
    def test_formset_layout(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)
        
        form_helper = FormHelper()    
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'
        form_helper.add_layout(
            Layout(
                Fieldset("Item {{ forloop.counter }}",
                    'is_company',
                    'email',
                ),
                HTML("{% if forloop.first %}Note for first form only{% endif %}"),
                Row('password1', 'password2'),
                Fieldset("",
                    'first_name',
                    'last_name'
                )
            )
        )
                
        TestFormSet = formset_factory(TestForm, extra = 3)
        testFormSet = TestFormSet()
        
        c = Context({
            'testFormSet': testFormSet, 
            'formset_helper': form_helper, 
            'csrf_token': _get_new_csrf_key()
        })
        html = template.render(c)        

        # Check form parameters
        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)

        # Check form layout
        self.assertTrue('Item 1' in html)
        self.assertTrue('Item 2' in html)
        self.assertTrue('Item 3' in html)
        self.assertEqual(html.count('Note for first form only'), 1)
        self.assertEqual(html.count('formRow'), 3)
示例#26
0
    def helper(self):

        print "ProfileForm.helper In helper"
        form = ProfileForm()
        helper = FormHelper()
        reset = Reset('', 'Reset')
        helper.add_input(reset)
        submit = Submit('', 'Update')
        helper.add_input(submit)
        helper.form_action = '/account/profile/edit'
        helper.form_method = 'POST'
        helper.form_class = "blueForms"

        return helper
示例#27
0
    def helper(self):
        
        print "ProfileForm.helper In helper"
        form = ProfileForm() 
        helper = FormHelper()
        reset = Reset('','Reset')
        helper.add_input(reset)
        submit = Submit('','Update')
        helper.add_input(submit)
        helper.form_action = '/account/profile/edit'
        helper.form_method = 'POST'
        helper.form_class="blueForms"

        return helper 
示例#28
0
    def test_formset_layout(self):
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """)

        form_helper = FormHelper()
        form_helper.form_id = 'thisFormsetRocks'
        form_helper.form_class = 'formsets-that-rock'
        form_helper.form_method = 'POST'
        form_helper.form_action = 'simpleAction'
        form_helper.add_layout(
            Layout(
                Fieldset(
                    "Item {{ forloop.counter }}",
                    'is_company',
                    'email',
                ),
                HTML(
                    "{% if forloop.first %}Note for first form only{% endif %}"
                ), Row('password1', 'password2'),
                Fieldset("", 'first_name', 'last_name')))

        TestFormSet = formset_factory(TestForm, extra=3)
        testFormSet = TestFormSet()

        c = Context({
            'testFormSet': testFormSet,
            'formset_helper': form_helper,
            'csrf_token': _get_new_csrf_key()
        })
        html = template.render(c)

        # Check form parameters
        self.assertEqual(html.count('<form'), 1)
        self.assertEqual(
            html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)

        # Check form layout
        self.assertTrue('Item 1' in html)
        self.assertTrue('Item 2' in html)
        self.assertTrue('Item 3' in html)
        self.assertEqual(html.count('Note for first form only'), 1)
        self.assertEqual(html.count('formRow'), 3)
示例#29
0
文件: tests.py 项目: Bauke900/dnevnik
    def test_formset_layout(self):
        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form testFormSet formset_helper %}
        """
        )

        form_helper = FormHelper()
        form_helper.form_id = "thisFormsetRocks"
        form_helper.form_class = "formsets-that-rock"
        form_helper.form_method = "POST"
        form_helper.form_action = "simpleAction"
        form_helper.add_layout(
            Layout(
                Fieldset("Item {{ forloop.counter }}", "is_company", "email"),
                HTML("{% if forloop.first %}Note for first form only{% endif %}"),
                Row("password1", "password2"),
                Fieldset("", "first_name", "last_name"),
            )
        )

        TestFormSet = formset_factory(TestForm, extra=3)
        testFormSet = TestFormSet()

        c = Context({"testFormSet": testFormSet, "formset_helper": form_helper, "csrf_token": _get_new_csrf_key()})
        html = template.render(c)

        # Check form parameters
        self.assertEqual(html.count("<form"), 1)
        self.assertEqual(html.count("<input type='hidden' name='csrfmiddlewaretoken'"), 1)

        self.assertTrue('class="uniForm formsets-that-rock"' in html)
        self.assertTrue('method="post"' in html)
        self.assertTrue('id="thisFormsetRocks">' in html)
        self.assertTrue('action="%s"' % reverse("simpleAction") in html)

        # Check form layout
        self.assertTrue("Item 1" in html)
        self.assertTrue("Item 2" in html)
        self.assertTrue("Item 3" in html)
        self.assertEqual(html.count("Note for first form only"), 1)
        self.assertEqual(html.count("formRow"), 3)
示例#30
0
    def helper(self):
      form = HelperAuthenticationForm()
      helper = FormHelper()
  
      

      login = Submit('login','Submit',css_class='primaryAction')
      helper.add_input(login)
  
      helper.form_action = 'login_form'
      helper.form_method = 'POST' # Only GET and POST are legal
  
      layout = Layout(
      	Fieldset('',
      	   HTML('<input type="hidden" name="next" value="{{ request.GET.next }}" />'),
      	   'identification', 'password', 'remember_me', css_class='inlineLabels'),
      )
  
      helper.add_layout(layout)
      return helper
示例#31
0
def view_helper_set_action(request):

    # Create the form
    form = TestForm()

    # create a formHelper
    helper = FormHelper()

    # add in a submit and reset button
    submit = Submit('send-away','Send to other page')
    helper.add_input(submit)
    
    helper.form_action = 'view_helper'
    helper.form_method = 'GET'    

    # create the response dictionary
    response_dictionary = {'form':form, 'helper': helper, 'title':'view helper action'}
    
    return render_to_response('test_app/generic_form_test.html', 
        response_dictionary, 
        context_instance=RequestContext(request))   
示例#32
0
文件: tests.py 项目: Bauke900/dnevnik
    def test_uni_form_with_helper_attributes_without_layout(self):
        form_helper = FormHelper()
        form_helper.form_id = "this-form-rocks"
        form_helper.form_class = "forms-that-rock"
        form_helper.form_method = "GET"
        form_helper.form_action = "simpleAction"
        form_helper.form_error_title = "ERRORS"

        template = get_template_from_string(
            u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """
        )

        # now we render it, with errors
        form = TestForm({"password1": "wargame", "password2": "god"})
        form.is_valid()
        c = Context({"testForm": form, "form_helper": form_helper})
        html = template.render(c)

        # Lets make sure everything loads right
        self.assertTrue("<form" in html)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse("simpleAction") in html)

        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        html = template.render(c)
        self.assertFalse("<form" in html)
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#33
0
    def helper(self):
        helper = FormHelper()
        helper.add_input(Submit('submit', _('Submit!')))

        layout = Layout(
                Fieldset('', 
                    'name', 'description'),
                Fieldset(_('When and where'),
                    'date', 'time',
                    'town', 'other_town',
                    'place',
                    ),
                Fieldset(_('Details'),
                    'organizer', 'link', 'contact', 'image',
                    ),
                )

        helper.add_layout(layout)
        helper.form_action = reverse('agenda:create')
        helper.form_method = 'post'
        helper.form_style = 'inline'
        return helper
示例#34
0
    def test_uni_form_with_helper_without_layout(self):
        form_helper = FormHelper()    
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
        form_helper.form_error_title = 'ERRORS'
    
        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """)        

        # now we render it, with errors
        form = TestForm({'password1': 'wargame','password2': 'god'})
        form.is_valid()
        c = Context({'testForm': form, 'form_helper': form_helper})            
        html = template.render(c)
        
        # Lets make sure everything loads right
        self.assertTrue(html.count('<form'), 1)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        self.assertEqual(html.count('<fieldset'), 1)


        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False 
        html = template.render(c)        
        self.assertFalse('<form' in html)        
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#35
0
    def test_uni_form_with_helper_without_layout(self):
        form_helper = FormHelper()
        form_helper.form_id = 'this-form-rocks'
        form_helper.form_class = 'forms-that-rock'
        form_helper.form_method = 'GET'
        form_helper.form_action = 'simpleAction'
        form_helper.form_error_title = 'ERRORS'

        template = get_template_from_string(u"""
            {% load uni_form_tags %}
            {% uni_form testForm form_helper %}
        """)

        # now we render it, with errors
        form = TestForm({'password1': 'wargame', 'password2': 'god'})
        form.is_valid()
        c = Context({'testForm': form, 'form_helper': form_helper})
        html = template.render(c)

        # Lets make sure everything loads right
        self.assertTrue(html.count('<form'), 1)
        self.assertTrue('class="uniForm forms-that-rock"' in html)
        self.assertTrue('method="get"' in html)
        self.assertTrue('id="this-form-rocks">' in html)
        self.assertTrue('action="%s"' % reverse('simpleAction') in html)
        self.assertEqual(html.count('<fieldset'), 1)

        self.assertTrue("<h3>ERRORS</h3>" in html)
        self.assertTrue("<li>Passwords dont match</li>" in html)

        # now lets remove the form tag and render it again. All the True items above
        # should now be false because the form tag is removed.
        form_helper.form_tag = False
        html = template.render(c)
        self.assertFalse('<form' in html)
        self.assertFalse('class="uniForm forms-that-rock"' in html)
        self.assertFalse('method="get"' in html)
        self.assertFalse('id="this-form-rocks">' in html)
示例#36
0
        # redirects to the provided redirect URL.
        return authorizer.error_redirect()
    if request.method == 'GET':
        # Make sure the authorizer has validated before requesting the client
        # or access_ranges as otherwise they will be None.
        template = {
            "client":authorizer.client,
            "scopes":authorizer.access_ranges}
        template["form"] = AuthorizeForm()
        helper = FormHelper()
        no_submit = Submit('connect','No', css_class='btn btn-large')
        helper.add_input(no_submit)
        yes_submit = Submit('connect', 'Yes', css_class='btn btn-large btn-primary')
        helper.add_input(yes_submit)
        #helper.form_action = '/authorization_manager/oauth2/authorize?%s' % authorizer.query_string
        helper.form_action = reverse('oauth2_authorize') + '?%s' % authorizer.query_string
        helper.form_method = 'POST'
        template["helper"] = helper
        return render_to_response(
            'oauth2/authorize.html',
            template,
            RequestContext(request))
    elif request.method == 'POST':
        form = AuthorizeForm(request.POST)
        if form.is_valid():
            if request.POST.get("connect") == "Yes":
                return authorizer.grant_redirect()
            else:
                return authorizer.error_redirect()
    return HttpResponseRedirect("/")
    Fieldset('',
        'parent',
        'content_type',
        'security_hash',
        'title',
        'name',
        'email',
        'url',
        'comment',
        'honeypot'
    )
)

comment_form_helper.add_layout(comment_form_layout)

comment_form_helper.form_action = reverse('comments-post-comment')
comment_form_helper.form_method = 'POST'
comment_form_helper.add_input(Submit('post','Post'))
comment_form_helper.add_input(Submit('preview','Preview'))

search_form_helper = FormHelper()

search_form_layout = Layout(
    Fieldset('',
        'q',
        'models'
    )
)

search_form_helper.add_layout(search_form_layout)
search_form_helper.form_style = 'inline'
示例#38
0
    try:
        authorizer.validate()
    except MissingRedirectURI, e:
        return HttpResponseRedirect("/oauth2/missing_redirect_uri")
    except AuthorizationException, e:
        # The request is malformed or invalid. Automatically
        # redirects to the provided redirect URL.
        return authorizer.error_redirect()
    if request.method == "GET":
        # Make sure the authorizer has validated before requesting the client
        # or access_ranges as otherwise they will be None.
        template = {"client": authorizer.client, "access_ranges": authorizer.access_ranges}
        template["form"] = AuthorizeForm()
        helper = FormHelper()
        no_submit = Submit("connect", "No")
        helper.add_input(no_submit)
        yes_submit = Submit("connect", "Yes")
        helper.add_input(yes_submit)
        helper.form_action = "/oauth2/authorize?%s" % authorizer.query_string
        helper.form_method = "POST"
        template["helper"] = helper
        return render_to_response("oauth2/authorize.html", template, RequestContext(request))
    elif request.method == "POST":
        form = AuthorizeForm(request.POST)
        if form.is_valid():
            if request.POST.get("connect") == "Yes":
                return authorizer.grant_redirect()
            else:
                return authorizer.error_redirect()
    return HttpResponseRedirect("/")
示例#39
0
        # The request is malformed or invalid. Automatically 
        # redirects to the provided redirect URL.
        return authorizer.error_redirect()
    if request.method == 'GET':
        # Make sure the authorizer has validated before requesting the client
        # or access_ranges as otherwise they will be None.
        template = {
            "client":authorizer.client, 
            "access_ranges":authorizer.access_ranges}
        template["form"] = AuthorizeForm()
        helper = FormHelper()
        no_submit = Submit('connect','No')
        helper.add_input(no_submit)
        yes_submit = Submit('connect', 'Yes')
        helper.add_input(yes_submit)
        helper.form_action = '/oauth2/authorize?%s' % authorizer.query_string
        helper.form_method = 'POST'
        template["helper"] = helper
        return render_to_response(
            'oauth2/authorize.html', 
            template, 
            RequestContext(request))
    elif request.method == 'POST':
        form = AuthorizeForm(request.POST)
        if form.is_valid():
            if request.POST.get("connect") == "Yes":
                return authorizer.grant_redirect()
            else:
                return authorizer.error_redirect()
    return HttpResponseRedirect("/")
示例#40
0
        return authorizer.error_redirect()

    if request.method == 'GET':
        template = {
            "client": authorizer.client,
            "access_ranges": authorizer.access_ranges
        }
        template["form"] = AuthorizeForm()
        helper = FormHelper()
        no_submit = Submit('connect', 'No', css_class='btn btn-large')
        helper.add_input(no_submit)
        yes_submit = Submit('connect',
                            'Godkend',
                            css_class='btn btn-large btn-success')
        helper.add_input(yes_submit)
        helper.form_action = reverse(
            'oauth2_authorize') + '?%s' % authorizer.query_string
        helper.form_method = 'POST'
        template["helper"] = helper

        is_enrollment = False
        try:
            is_enrollment = AccessRange.objects.get(
                key='enroll') in authorizer.access_ranges
        except AccessRange.DoesNotExist:
            pass

        if is_enrollment:
            return authorizer.grant_redirect()
            template['informed_consent'] = service_manager.getInformedConsent(
                authorizer.client, request.LANGUAGE_CODE)
示例#41
0
        # redirects to the provided redirect URL.
        return authorizer.error_redirect()
    if request.method == 'GET':
        # Make sure the authorizer has validated before requesting the client
        # or access_ranges as otherwise they will be None.
        template = {
            "client": authorizer.client,
            "access_ranges": authorizer.access_ranges
        }
        template["form"] = AuthorizeForm()
        helper = FormHelper()
        no_submit = Submit('connect', 'No')
        helper.add_input(no_submit)
        yes_submit = Submit('connect', 'Yes')
        helper.add_input(yes_submit)
        helper.form_action = '/oauth2/authorize?%s' % authorizer.query_string
        helper.form_method = 'POST'
        template["helper"] = helper
        return render_to_response('oauth2/authorize.html', template,
                                  RequestContext(request))
    elif request.method == 'POST':
        form = AuthorizeForm(request.POST)
        if form.is_valid():
            if request.POST.get("connect") == "Yes":
                return authorizer.grant_redirect()
            else:
                return authorizer.error_redirect()
    return HttpResponseRedirect("/")


def aadhaar_login_required(f):
示例#42
0
    def set_helper(self):
        print "AadhaarLoginForm.helper In helper"
        #form = AadhaarLoginForm()
        helper = FormHelper()
        reset = Reset('','Reset')
        helper.add_input(reset)
        submit = Submit('','Authenticate')
        helper.add_input(submit)
        helper.form_action = '/aadhaar/authenticate/' + self.detail 
        helper.form_method = 'POST'
        helper.form_class="blueForms"

        style="""
<style>
fieldset.formRow {
         margin-bottom: 1em;
         border-width: 0 0 1px 0;
         border-color:#CCCCCC;
         border-style:solid;
}
</style>
"""
        common_layout =  Layout(
            Fieldset('Required Parameters',
                     'aadhaar_id',
                     'aadhaar_attributes',
                     )
            )
        pi_layout= Layout(
            Fieldset("Personally Identifiable Information",
                     'aadhaar_pi_match',
                     'aadhaar_name',
                     'aadhaar_dob', 
                     'aadhaar_age',
                     'aadhaar_gender',
                     'aadhaar_email',
                     'aadhaar_phone',
                     )
            )
        pa_layout = Layout(
            Fieldset("Address",
                     'aadhaar_pa_match',
                     'aadhaar_co',
                     'aadhaar_house',
                     'aadhaar_street',
                     'aadhaar_landmark',
                     'aadhaar_locality',
                     'aadhaar_vtc',
                     'aadhaar_subdist',
                     'aadhaar_district',
                     'aadhaar_state',
                     'aadhaar_pincode',
                     'aadhaar_postoffice')
            )
        
        if self.detail == "personal": 
            layout = Layout(common_layout, pi_layout)
        elif self.detail == "address":
            layout = Layout(common_layout, pa_layout)
        else:
            layout = Layout(common_layout, pi_layout, pa_layout)
            
        helper.layout = layout

        self.helper = helper