Ejemplo n.º 1
0
def form(name, fields, top="", bottom="", err="", submit=None):
    if submit == None:
        submit = name
    finalfields = []
    for field in fields:
        if len(field) < 3:
            raise SyntaxError("Not enough arguments to field")
        attr = {}
        if field[0] not in [0, 1, False, True]:
            raise SyntaxError("required is not a boolean")
        if field[0]:
            attr["required"] = ""

        attr["placeholder"] = field[1]
        attr["name"] = field[2]
        field = field[3:]
        if field and isinstance(field[0], str):
            attr["type"] = field[0]
            field = field[1:]

        for item in field:
            if not isinstance(item, tuple) and len(item) == 2:
                raise SyntaxError("Additional arguments must be a tuple of length 2")
            attr[item[0]] = item[1]

        finalfields.append(attr)
    from template_engine.main import render

    context = {"fields": finalfields, "name": name, "top": top, "bottom": bottom, "err": err, "submit": submit}
    return render("nodes/form.html", None, context)
Ejemplo n.º 2
0
    def wrapper(response, *args):
        user = get_user(response)
        if req == None or (user == None and req == False) or (user != None and req == True):
            try:
                return fn(response, *args, user=user)
            except Exception as err:
                from template_engine.main import render
                exc = traceback.format_exception(*sys.exc_info())
                print("".join(exc))
                exc = "".join([html.escape(line) for line in exc]).split("\n")
                for linenum in range(len(exc)):
                    line = exc[linenum]
                    for index in range(len(line)):
                        if line[index] != " ":
                            break
                    exc[linenum] = "&nbsp" * index * 4 + line[index:]

                render('global/error.html', response, {"error": 500, "debug": settings.DEBUG, "traceback": exc})
        else:
            response.redirect(redirect)
        return None
Ejemplo n.º 3
0
def table(name, nomatch, fields, table, classes=[]):
    for field in fields:
        if field is str:
            raise TypeError("Fields must be a list of tuples or lists")
    for row in table:
        if len(row) != len(fields):
            raise IndexError("Length of all rows must be the same")

    from template_engine.main import render
    context = {
        "title": name,
        "thead": fields,
        "content": table,
        "table_classes": classes,
        "nomatch": nomatch,
    }
    return render("nodes/table.html", None, context)