5.5. Abstract Case Study
5.5.1. Part 1
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.2. Part 2
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.3. Part 3
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.4. Part 4
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.5. Part 5
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.6. Part 6
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>
5.5.7. Part 7
class InputText:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="text" placeholder="{self.name}">')
class InputPassword:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="password" placeholder="{self.name}">')
class InputSubmit:
def __init__(self, name):
self.name = name
def render(self):
print(f'\t<input type="submit" value="{self.name}">')
def render(form):
print('<form method="post", action="#login">')
for element in form:
element.render()
print('</form>')
login_form = [
InputText('Username'),
InputPassword('Password'),
InputSubmit('Login'),
]
render(login_form)
# <form method="post", action="#login">
# <input type="text" placeholder="Username">
# <input type="password" placeholder="Password">
# <input type="submit" value="Login">
# </form>