예제 #1
0
    def test_submit_cancel_form_helper(self):
        """Test custom crispy forms layout helper"""
        template = Engine().get_default().from_string("""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = SampleForm()
        test_form.helper = SubmitCancelFormHelper(test_form)

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('role="button"'), 1)
        self.assertEqual(html.count('href="#"'), 1)
        self.assertEqual(html.count('Cancel'), 1)
        self.assertEqual(html.count('Submit'), 1)

        test_form = SampleForm()
        test_form.helper = SubmitCancelFormHelper(test_form,
                                                  cancel_href="/some/url/")

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('href="/some/url/'), 1)
예제 #2
0
    def __init__(self, *args, **kwargs):
        user = kwargs.get('instance')
        systers_user = SystersUser.objects.get(user=user)
        systers_user_kwargs = kwargs.copy()
        systers_user_kwargs['instance'] = systers_user
        self.systers_user_form = SystersUserForm(*args, **systers_user_kwargs)

        super(UserForm, self).__init__(*args, **kwargs)

        self.fields.update(self.systers_user_form.fields)
        self.initial.update(self.systers_user_form.initial)

        self.helper = SubmitCancelFormHelper(
            self, cancel_href="{{ systersuser.get_absolute_url }}")
예제 #3
0
    def __init__(self, *args, **kwargs):
        user = kwargs.get('instance')
        bucket_user = BucketUser.objects.get(user=user)
        bucket_user_kwargs = kwargs.copy()
        bucket_user_kwargs['instance'] = bucket_user
        self.bucket_user_form = BucketUserForm(*args, **bucket_user_kwargs)

        super(UserForm, self).__init__(*args, **kwargs)

        self.fields.update(self.bucket_user_form.fields)
        self.initial.update(self.bucket_user_form.initial)

        self.helper = SubmitCancelFormHelper(
            self, cancel_href="{{ bucketuser.get_absolute_url }}")
예제 #4
0
파일: forms.py 프로젝트: singhrash23/portal
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user')
        community = kwargs.pop('community')
        super(PermissionGroupsForm, self).__init__(*args, **kwargs)

        # get all community groups and remove community admin group
        # from the list of choices
        self.groups = list(get_groups(community.name))
        admin_group = Group.objects.get(
            name=COMMUNITY_ADMIN.format(community.name))
        self.groups.remove(admin_group)
        choices = [(group.pk, group.name) for group in self.groups]
        self.fields['groups'] = forms. \
            MultipleChoiceField(choices=choices, label="", required=False,
                                widget=forms.CheckboxSelectMultiple)
        self.member_groups = self.user.get_member_groups(self.groups)
        self.fields['groups'].initial = [
            group.pk for group in self.member_groups
        ]

        self.helper = SubmitCancelFormHelper(
            self, cancel_href="{% url 'community_users' community.slug %}")