Skip to content

Commit e9f9e75

Browse files
committed
initial commit
0 parents  commit e9f9e75

27 files changed

+585
-0
lines changed

.coveragerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[run]
2+
branch = True
3+
source = formit
4+
5+
[report]
6+
show_missing = True

.editorconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
8+
[*.{js,py,rst,json,yml,html,txt}]
9+
charset = utf-8
10+
11+
[*.{py,rst,md,ini}]
12+
indent_style = space
13+
indent_size = 4
14+
15+
[Makefile]
16+
indent_style = tab
17+
indent_size = 4
18+
19+
[*.{json,yml,html,css,js}]
20+
indent_style = space
21+
indent_size = 2

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = .tox,.eggs,.git,migrations,docs
3+
max-complexity = 10
4+
max-line-length = 119

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
*.egg-info/
2+
*.orig
3+
*.pyc
4+
*.sqlite3
5+
*.sw[op]
6+
.cache
7+
.coverage
8+
.DS_Store
9+
.eggs
10+
.python-version
11+
.tox
12+
__pycache__/
13+
build/
14+
dist/
15+
docs/_build
16+
example/media/
17+
example/static/
18+
htmlcov/

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sudo: false
2+
language: python
3+
4+
python:
5+
- 2.7
6+
- 3.4
7+
- 3.5
8+
9+
env:
10+
- DJANGO=1.10
11+
- DJANGO=1.11
12+
13+
matrix:
14+
fast_finish: true
15+
include:
16+
- python: "3.5"
17+
env: TOXENV=flake8
18+
19+
before_install: pip install codecov
20+
install: pip install tox
21+
22+
script:
23+
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' && $DJANGO == '1.10' ]]; then export TOXENV=py27-django110; fi"
24+
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' && $DJANGO == '1.11' ]]; then export TOXENV=py27-django111; fi"
25+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' && $DJANGO == '1.10' ]]; then export TOXENV=py34-django110; fi"
26+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' && $DJANGO == '1.11' ]]; then export TOXENV=py34-django111; fi"
27+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $DJANGO == '1.10' ]]; then export TOXENV=py35-django110; fi"
28+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.5' && $DJANGO == '1.11' ]]; then export TOXENV=py35-django111; fi"
29+
- tox -e $TOXENV
30+
31+
after_success: codecov

AUTHORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Original authors:
2+
3+
* Dino Perovic (@dinoperovic)

LICENSE.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Copyright (c) 2016, Dino Perovic
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are
6+
met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
* Redistributions in binary form must reproduce the above
11+
copyright notice, this list of conditions and the following
12+
disclaimer in the documentation and/or other materials provided
13+
with the distribution.
14+
* Neither the name of the author nor the names of other
15+
contributors may be used to endorse or promote products derived
16+
from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include AUTHORS
2+
include LICENSE.txt
3+
include README.md
4+
include setup.py
5+
recursive-include formit *.py
6+
recursive-include formit/templates *
7+
recursive-exclude * *.pyc

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
clean:
2+
rm -rf build dist .tox .cache .eggs *.egg-info .coverage .DS_Store
3+
find . -name '*.pyc' -exec rm '{}' ';'
4+
5+
sort:
6+
isort -rc formit -l 119
7+
8+
coverage:
9+
coverage erase
10+
coverage run -m pytest
11+
coverage report

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Formit
2+
3+
[![Build Status](https://img.shields.io/travis/dinoperovic/django-formit.svg)](https://travis-ci.org/dinoperovic/django-formit)
4+
[![Codecov](https://img.shields.io/codecov/c/github/dinoperovic/django-formit.svg)](http://codecov.io/github/dinoperovic/django-formit)
5+
[![PyPI version](https://img.shields.io/pypi/v/django-formit.svg)](https://pypi.python.org/pypi/django-formit)
6+
7+
**Smiple [Django] form formating.**
8+
9+
Formit provides a template tag library for django to ease the formating of forms.
10+
11+
---
12+
13+
## Requirements
14+
15+
* [Django] 1.11, 1.10
16+
* [django-classy-tags] for managing template tags.
17+
18+
## Installation
19+
20+
Install using *pip*:
21+
22+
```bash
23+
pip install django-formit
24+
```
25+
26+
Add `formit` to `INSTALLED_APPS`.
27+
28+
## Usage
29+
30+
To use **Formit** add your templates:
31+
32+
```django
33+
{% load formit_tags %}
34+
35+
{# To render the form. #}
36+
{% form instance action="/" method="get" button="Send" %}
37+
38+
{# To render the form with custom contents. #}
39+
{% form_block instance %}
40+
<h3>Contact form</h3>
41+
{% fieldset %}
42+
{% endform_block %}
43+
44+
{# To render a custom form without any formating. #}
45+
{% form_block instance blank=True %}
46+
{% csrf_token %}
47+
<h3>Contact form</h3>
48+
<div class="column">
49+
{% fieldset fields=form.visible_fields|slice:":3" %}
50+
</div>
51+
<div class="column">
52+
{% fieldset fields=form.visible_fields|slice:"3:" %}
53+
</div>
54+
{% fieldset fields=form.hidden_fields %}
55+
<button>Send</button>
56+
{% endform_block %}
57+
58+
{# You can separate the rendering of visible and hidden fields. #}
59+
{% fieldset visible_fields=instance.visible_fields hidden_fields=instance.hidden_fields %}
60+
{# or to automatically extract them from a form. #}
61+
{% fieldset form=instance %}
62+
63+
{# To render a single field #}
64+
{% field instance.visible_fields.0 placeholder="Enter your name" %}
65+
```
66+
67+
Fieldset tags can also be used without any arguments. In that case ``form`` from the context will be used,
68+
which is automatically available inside the ``form`` or ``form_block`` tag.
69+
70+
## Templates
71+
72+
Templates available to override in ``templates/formit/*``:
73+
74+
* ``form.html``
75+
* ``fieldset.html``
76+
* ``field.html``
77+
78+
79+
[Django]: https://www.djangoproject.com/
80+
[django-classy-tags]: https://github.com/ojii/django-classy-tags

codecov.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
coverage:
2+
status:
3+
project: false
4+
patch: false
5+
changes: false
6+
7+
comment: false

formit/__init__.py

Whitespace-only changes.

formit/settings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.conf import settings
5+
from django.utils.translation import ugettext_lazy as _
6+
7+
# Default value for novalidate attribute on forms.
8+
DEFAULT_NOVALIDATE = getattr(settings, 'FORMIT_DEFAULT_NOVALIDATE', False)
9+
10+
# Default form button text.
11+
DEFAULT_BUTTON = getattr(settings, 'FORMIT_DEFAULT_BUTTON', _('Submit'))

formit/templates/formit/field.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{% if field_type == 'hiddeninput' %}
2+
{# Render hidden field without formating. #}
3+
{{ field }}
4+
{% else %}
5+
<div class="field field-{{ field_type }}{% if is_required %} required{% endif %}{% if has_errors %} error{% endif %}">
6+
{% if field_type == 'checkboxinput' %}
7+
{# Render checkbox input. #}
8+
{{ field }}
9+
<label for="{{ field.id_for_label }}">{{ field_label }}</label>
10+
{% elif field_type == 'radioselect' %}
11+
{# Render radio select. #}
12+
<label for="{{ field.id_for_label }}">{{ field_label }}</label>
13+
<div class="group">
14+
{% for radio in field %}
15+
{{ radio.tag }}
16+
<label for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
17+
{% endfor %}
18+
</div>
19+
{% else %}
20+
{# Render field. #}
21+
{% if show_label %}<label for="{{ field.id_for_label }}">{{ field_label }}</label>{% endif %}
22+
{{ field }}
23+
{% endif %}
24+
25+
{# Show help text. #}
26+
{% if show_help_text and field_help_text %}<span class="help-text">{{ field_help_text|safe }}</span>{% endif %}
27+
28+
{# Show field errors. #}
29+
{% if show_errors and has_errors %}
30+
<ul class="errorlist">
31+
{% for error in field.errors %}<li>{{ error }}</li>{% endfor %}
32+
</ul>
33+
{% endif %}
34+
</div>
35+
{% endif %}
36+
37+
{% comment %}
38+
Variables:
39+
{{ field }}
40+
{{ field_type }}
41+
{{ field_label }}
42+
{{ field_help_text }}
43+
44+
Helpers:
45+
{{ is_required }}
46+
{{ has_errors }}
47+
48+
Flags:
49+
{{ show_label }}
50+
{{ show_help_text }}
51+
{{ show_errors }}
52+
{% endcomment %}

formit/templates/formit/fieldset.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% load formit_tags %}
2+
3+
{% if fields %}
4+
{# Render fields. #}
5+
{% for field in fields %}{% field field %}{% endfor %}
6+
{% else %}
7+
{# Render hidden and visible fields separately. #}
8+
{% for hidden in hidden_fields %}{% field hidden %}{% endfor %}
9+
{% for field in visible_fields %}{% field field %}{% endfor %}
10+
{% endif %}
11+
12+
{% comment %}
13+
Variables:
14+
{{ form }}
15+
{{ fields }}
16+
{{ visible_fields }}
17+
{{ hidden_fields }}
18+
{% endcomment %}

formit/templates/formit/form.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{% load formit_tags %}
2+
3+
<form action="{{ action }}" method="{{ method }}"{% if enctype %} enctype="{{ enctype }}"{% endif %}{% if novalidate %} novalidate{% endif %}>
4+
{% if is_blank %}
5+
{# Blank form block. #}
6+
{{ block_content }}
7+
{% else %}
8+
{# CSRF token. #}
9+
{% if show_csrf_token %}{% csrf_token %}{% endif %}
10+
11+
{# Show non field errors. #}
12+
{% if show_non_field_errors and form.non_field_errors %}
13+
<ul class="non-field-errors">
14+
{% for error in form.non_field_errors %}<li>{{ error }}</li>{% endfor %}
15+
</ul>
16+
{% endif %}
17+
18+
{# Either show rendered block, or display fieldset. #}
19+
{% if is_block %}
20+
{{ block_content }}
21+
{% else %}
22+
{% fieldset %}
23+
{% endif %}
24+
25+
{# Show form button. #}
26+
{% if show_button %}<button>{{ button }}</button>{% endif %}
27+
{% endif %}
28+
</form>
29+
30+
{% comment %}
31+
Variables:
32+
{{ form }}
33+
{{ action }}
34+
{{ method }}
35+
{{ enctype }}
36+
{{ button }}
37+
{{ novalidate }}
38+
39+
Form block:
40+
{{ is_blank }}
41+
{{ is_block }}
42+
{{ block_content }}
43+
44+
Flags:
45+
{{ show_csrf_token }}
46+
{{ show_non_field_errors }}
47+
{{ show_button }}
48+
{% endcomment %}

formit/templatetags/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)