Beispiel #1
0
from starlette.routing import Mount, Route
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates

# schema validation
import typesystem
# uvicorn
import uvicorn
# yeoboseyo
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PARENT_FOLDER = os.path.dirname(PROJECT_DIR)
sys.path.append(PARENT_FOLDER)
from yeoboseyo.forms import TriggerSchema
from yeoboseyo.models import Trigger

forms = typesystem.Jinja2Forms(package="bootstrap4")
templates = Jinja2Templates(directory="templates")
statics = StaticFiles(directory="static")


class TriggerEndpoint(HTTPEndpoint):
    async def get(self, request):
        # trigger_id provided, form to edit this one
        trigger_id = request.path_params['trigger_id']
        trigger = await Trigger.objects.get(id=trigger_id)
        form = forms.Form(TriggerSchema, values=trigger)
        triggers = await Trigger.objects.all()
        context = {
            "request": request,
            "form": form,
            "triggers_list": triggers,
from server import settings

import typesystem
from starlette.templating import Jinja2Templates

from .items import *
from .users import *

forms = typesystem.Jinja2Forms(directory="templates")
templates = Jinja2Templates(directory="templates")
Beispiel #3
0
def test_forms_from_directory(tmpdir):
    forms = typesystem.Jinja2Forms(directory=str(tmpdir))
    assert isinstance(forms.env.loader, jinja2.FileSystemLoader)
Beispiel #4
0
def test_forms_with_directory_override(tmpdir):
    forms = typesystem.Jinja2Forms(directory=str(tmpdir), package="typesystem")
    assert isinstance(forms.env.loader, jinja2.ChoiceLoader)
Beispiel #5
0
import jinja2

import typesystem


class Contact(typesystem.Schema):
    a = typesystem.Boolean()
    b = typesystem.String(max_length=10)
    c = typesystem.Text()
    d = typesystem.Choice(choices=[("abc", "Abc"), ("def",
                                                    "Def"), ("ghi", "Ghi")])


forms = typesystem.Jinja2Forms(package="typesystem")


def test_form_rendering():
    form = forms.Form(Contact)

    html = str(form)

    assert html.count('<input type="checkbox" ') == 1
    assert html.count('<input type="text" ') == 1
    assert html.count("<textarea ") == 1
    assert html.count("<select ") == 1


def test_password_rendering():
    class PasswordForm(typesystem.Schema):
        password = typesystem.String(format="password")