From 43f33286bfe62dbad7fc22c48c37b44d7ad28839 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 25 Jan 2023 19:45:04 +0100 Subject: [PATCH] Add test creation form --- src/main.rs | 29 +++++++++++++++++---- templates/begin_create.html.tera | 44 ++++++++++++++++++++++++++++++++ templates/create.html.tera | 25 ++++++++++-------- 3 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 templates/begin_create.html.tera diff --git a/src/main.rs b/src/main.rs index ae5b9c6..b38538a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,31 @@ #![feature(decl_macro)] -use rocket::*; +use rocket::{*, response::Redirect, form::Form}; use rocket_dyn_templates::{Template, context}; #[get("/create")] -fn create() -> Template +fn begin_create() -> Template { - Template::render("create", context!{}) + Template::render("begin_create", context!{}) +} + +#[get("/create/")] +fn create(name: &str) -> Template +{ + Template::render("create", context!{ + username: name + }) +} + +#[derive(FromForm)] +struct UserNameData<'r> { + pub username: &'r str, +} + +#[post("/create", data = "")] +fn create_post(name: Form>) -> Redirect +{ + Redirect::to(uri!(create(name.username))) } #[get("/about")] @@ -19,11 +38,11 @@ fn about() -> Template fn index() -> Template { Template::render("index", context! { - create_uri: uri!(create()) + create_uri: uri!(begin_create()) }) } #[launch] fn rocket() -> _ { - rocket::build().mount("/", routes![create, index, about]).attach(Template::fairing()) + rocket::build().mount("/", routes![begin_create, create, create_post, index, about]).attach(Template::fairing()) } diff --git a/templates/begin_create.html.tera b/templates/begin_create.html.tera new file mode 100644 index 0000000..91caecc --- /dev/null +++ b/templates/begin_create.html.tera @@ -0,0 +1,44 @@ +{% extends "base" %} +{% block title %}{% endblock %} +{% block body %} +
+
+

Crea tu propio test

+
+
+
+ + +
+
+ +
+
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/templates/create.html.tera b/templates/create.html.tera index fac795d..0f92201 100644 --- a/templates/create.html.tera +++ b/templates/create.html.tera @@ -3,19 +3,22 @@ {% block body %}
-

Crea tu propio test

-
+

¿Cuál es tu estación favorita?

+
-
- - + +
+
-
- +
+ +
+
+ +
+
+