Skip to content

Commit

Permalink
Form.autocomplete is now an enum attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
srittau committed Jul 22, 2020
1 parent 04732d3 commit 61fd60c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# News in version 2.0.0

## Incompatible Changes

* Drop support for Python 2.7 and 3.4.

## API Additions

* Add `Video` element.
* Add `Button.disabled`.
* Add `autocomplete` attribute to `Input`, `TextArea`, `Select`, and `Form`.
* Add `enum_attribute`.

## Incompatible Changes

* Drop support for Python 2.7 and 3.4.

# News in version 1.2.2

## API Additions
Expand Down
1 change: 1 addition & 0 deletions htmlgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from .element import ElementBase, Element, VoidElement, is_element
from .form import (
Autocomplete,
Form,
Input,
TextInput,
Expand Down
10 changes: 8 additions & 2 deletions htmlgen/form.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import datetime
import re
from enum import Enum

from htmlgen.attribute import (
html_attribute,
boolean_html_attribute,
int_html_attribute,
float_html_attribute,
time_html_attribute,
list_html_attribute,
list_html_attribute, enum_attribute,
)
from htmlgen.block import Division
from htmlgen.element import Element, VoidElement, is_element
Expand All @@ -18,6 +19,11 @@
_ENC_TYPE_MULTI_PART = "multipart/form-data"


class Autocomplete(Enum):
OFF = "off"
ON = "on"


class Form(Element):
"""An HTML <form> element.
Expand All @@ -42,7 +48,7 @@ def __init__(self, method="GET", url=""):
url = html_attribute("action", default="")
target = html_attribute("target", "_self")
encryption_type = html_attribute("enctype", _ENC_TYPE_URL_ENCODED)
autocomplete = html_attribute("autocomplete")
autocomplete = enum_attribute("autocomplete", Autocomplete)

def set_blank_target(self):
self.target = "_blank"
Expand Down
5 changes: 5 additions & 0 deletions htmlgen/form.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import datetime
from enum import Enum
from typing import List, Union, Optional

from htmlgen.element import Element, VoidElement
from htmlgen.generator import Generator

class Autocomplete(Enum):
OFF: str
ON: str

class Form(Element):
method: str
url: str
Expand Down
5 changes: 3 additions & 2 deletions test_htmlgen/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
Option,
Label,
)
from htmlgen.form import Autocomplete


class FormTest(TestCase):
Expand All @@ -47,10 +48,10 @@ def test_implicit_arguments(self):

def test_arguments(self):
form = Form("PUT", "/test")
form.autocomplete = "username"
form.autocomplete = Autocomplete.OFF
assert_equal(
[
b'<form action="/test" autocomplete="username" method="PUT">',
b'<form action="/test" autocomplete="off" method="PUT">',
b"</form>",
],
list(iter(form)),
Expand Down

0 comments on commit 61fd60c

Please sign in to comment.