示例#1
0
    def __call__(self, environ, start_response):
        path = environ["PATH_INFO"]

        method = environ["REQUEST_METHOD"]
        data = self.get_input_data(environ)
        data = self.decode_input_data(data)

        query_string = environ["QUERY_STRING"]
        request_params = self.parser_input_data(query_string)

        if not path.endswith("/"):
            path = f"{path}/"

        if path in self.urlpatterns:
            view = self.urlpatterns[path]
            request = {
                "method": method,
                "data": data,
                "request_params": request_params
            }

            for middleware in self.middlewares:
                middleware(request)

            code, template = view(request)
            start_response(code, header)

            return [template.encode("utf-8")]

        else:
            start_response(code_not_found, header)
            template = render("404.html")
            return [template.encode("utf-8")]
示例#2
0
def create_course(request):
    if request["method"] == "POST":
        data = request["data"]
        name = data["name"]
        category_id = data.get("category_id")

        if category_id:
            category = site.find_category_by_id(int(category_id))
            course = site.create_course("record", name, category)
            course.observers.append(email_notifier)
            course.observers.append(sms_notifier)
            site.courses.append(course)
        return code_success, render("create_course.html",
                                    categories=site.categories)
    else:
        return code_success, render("create_course.html",
                                    categories=site.categories,
                                    course=site.courses)
示例#3
0
def copy_course(request):
    request_params = request["request_params"]
    name = request_params["name"]
    old_course = site.get_course(name)
    if old_course:
        new_name = f"copy_{name}"
        new_course = old_course.clone()
        new_course.name = new_name
        site.courses.append(new_course)

    return code_success, render("list_courses.html", objects_list=site.courses)
示例#4
0
def docs(docs_name):
    docs = get_all_docs()
    doc = find_doc(docs_name)

    if doc is None:
        raise ValueError(
            "ドキュメントが見つかりませんでした。manifest.jsonに情報を入力し忘れている可能性があります。")

    return render_template("docs.html.j2",
                           body=render(docs_name),
                           docs=docs,
                           **doc)
示例#5
0
    def test_render(self):
        measurements = [{
            'location': 'St. James',
            'measurement': 4,
            'coordinates': [45, 46]
        }, {
            'location': 'St. Boniface',
            'measurement': 6,
            'coordinates': [47, 48]
        }]

        html = render(measurements, "src/templates/")
        self.assertIn('addMarker("45", "46", "St. James", "4");', html)
        self.assertIn('addMarker("47", "48", "St. Boniface", "6")', html)
示例#6
0
def contact(request):
    if request["method"] == "POST":
        data = request["data"]
        theme = data["theme"]
        email = data["email"]
        text = data["text"]

        msg = (f"\nPOST-форма\n"
               f'Дата: {datetime.datetime.now().strftime("%d-%m-%Y %H:%M")}\n'
               f"E-mail: {email}\n"
               f"Тема: {theme}\n"
               f"Сообщение: {text}\n")

        with open("email/emails.txt", "a+") as f:
            f.write(msg)

    return code_success, render("contacts.html")
示例#7
0
def main():
    docs = get_all_docs(DEBUG=False)

    # ==========
    # create a home page
    template = env.get_template("home.html.j2")
    home_html = template.render(docs=docs)
    write_docs(home_html, "index.html")

    # ==========
    # create doc pages
    template = env.get_template("docs.html.j2")
    for doc in docs:
        doc_html = template.render(body=render(doc["path"].split(".")[0]),
                                   docs=docs,
                                   root_path="/cbc-docs",
                                   **doc)
        write_docs(doc_html, doc["path"])
示例#8
0
def about(request):
    static = request.get("static", None)
    return code_success, render("about.html", static=static)
示例#9
0
def courses_list(request):
    logger.log("Список курсов")
    return code_success, render("list_courses.html", objects_list=site.courses)
示例#10
0
def main(request):
    static = request.get("static", None)
    return code_success, render("index.html", static=static)
示例#11
0
def application(environ, start_response):
    start_response("200 OK", )

    return [render("index.html").encode("utf-8")]
示例#12
0
 def render(self, viewport, **config):
     render.render(viewport, self.points, **config)
示例#13
0
from src.scan import scan
from src.play import play
from src.render import render
from openni import openni2

if __name__ == '__main__':
    print('Mode (scan/play/render):', end=' ')
    mode = input()
    print('Record filename:', end=' ')
    name = input()
    if mode == 'scan':
        openni2.initialize()
        print('Exposure Strategy (lock/sweep):', end=' ')
        exposure_strategy = input()
        scan(name, exposure_strategy)
        play(name)
        openni2.unload()
    elif mode == 'play':
        openni2.initialize()
        play(name)
        openni2.unload()
    elif mode == 'render':
        render(name)
示例#14
0
 def render(self):
     template = self.get_template()
     context = self.get_context_data()
     return code_success, render(template, **context)