tabletop-frog/ttfrog/webserver/forms.py

21 lines
769 B
Python
Raw Normal View History

2024-02-08 01:14:35 -08:00
from ttfrog.db.manager import db
from wtforms.fields import SelectField, SelectMultipleField
2024-02-04 11:40:30 -08:00
2024-02-23 10:45:38 -08:00
2024-02-08 01:14:35 -08:00
class DeferredSelectMultipleField(SelectMultipleField):
def __init__(self, *args, model=None, **kwargs):
super().__init__(*args, **kwargs)
2024-02-18 19:30:41 -08:00
self.choices = [(rec.id, rec.name) for rec in db.query(model).all()]
2024-02-04 11:40:30 -08:00
2024-02-08 01:14:35 -08:00
class DeferredSelectField(SelectField):
def __init__(self, *args, model=None, **kwargs):
super().__init__(*args, **kwargs)
2024-02-18 19:30:41 -08:00
self.choices = [(rec.id, rec.name) for rec in db.query(model).all()]
2024-02-23 10:45:38 -08:00
class NullableDeferredSelectField(DeferredSelectField):
def __init__(self, *args, model=None, label='---', **kwargs):
super().__init__(*args, model=model, **kwargs)
self.choices = [(0, label)] + self.choices