aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 16:33:46 -0600
committerMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 16:33:46 -0600
commit311b49a2fdd97b8b870dbaccccb55058ee0207c8 (patch)
tree1ca431733526cac1c7c2f7f1bfda7324ae088d50 /examples
parentcc7d316e588c21de1023d6a76d4ea5e7b893977a (diff)
downloadtosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.tar.gz
tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.zip
lay groundwork for models
Diffstat (limited to 'examples')
-rw-r--r--examples/tutorial01/main.rs4
-rw-r--r--examples/tutorial01/polls/mod.rs2
-rw-r--r--examples/tutorial02/main.rs25
-rw-r--r--examples/tutorial02/polls/mod.rs11
-rw-r--r--examples/tutorial02/polls/models.rs21
-rw-r--r--examples/tutorial02/polls/urls.rs9
-rw-r--r--examples/tutorial02/polls/views.rs5
7 files changed, 75 insertions, 2 deletions
diff --git a/examples/tutorial01/main.rs b/examples/tutorial01/main.rs
index f99ae7f..0fb087d 100644
--- a/examples/tutorial01/main.rs
+++ b/examples/tutorial01/main.rs
@@ -6,8 +6,8 @@ mod polls;
fn urls() -> UrlMap {
url_map! {
- "polls" / ..polls::urls::urls(),
- "admin" / ..admin::site::urls::urls(),
+ "polls" / ..polls::urls(),
+ "admin" / ..admin::site::urls(),
}
}
diff --git a/examples/tutorial01/polls/mod.rs b/examples/tutorial01/polls/mod.rs
index fd1dad8..d22af0f 100644
--- a/examples/tutorial01/polls/mod.rs
+++ b/examples/tutorial01/polls/mod.rs
@@ -1,2 +1,4 @@
pub mod urls;
pub mod views;
+
+pub use urls::urls;
diff --git a/examples/tutorial02/main.rs b/examples/tutorial02/main.rs
new file mode 100644
index 0000000..c662001
--- /dev/null
+++ b/examples/tutorial02/main.rs
@@ -0,0 +1,25 @@
+use tosin::Settings;
+use tosin::contrib::admin;
+use tosin::urls::{UrlMap, url_map};
+
+mod polls;
+
+fn urls() -> UrlMap {
+ url_map! {
+ "polls" / ..polls::urls(),
+ "admin" / ..admin::site::urls(),
+ }
+}
+
+fn settings() -> Settings {
+ Settings {
+ installed_apps: &[
+ &polls::APP,
+ &admin::APP,
+ ],
+ database_url: "example_data.sqlite3",
+ ..Settings::default()
+ }
+}
+
+tosin::main!(urls(), settings());
diff --git a/examples/tutorial02/polls/mod.rs b/examples/tutorial02/polls/mod.rs
new file mode 100644
index 0000000..f4fde54
--- /dev/null
+++ b/examples/tutorial02/polls/mod.rs
@@ -0,0 +1,11 @@
+use tosin::apps::AppConfig;
+
+pub mod models;
+pub mod urls;
+pub mod views;
+
+pub use urls::urls;
+
+pub const APP: AppConfig = AppConfig {
+
+};
diff --git a/examples/tutorial02/polls/models.rs b/examples/tutorial02/polls/models.rs
new file mode 100644
index 0000000..5ed52c5
--- /dev/null
+++ b/examples/tutorial02/polls/models.rs
@@ -0,0 +1,21 @@
+use tosin::db::models::{Model, Id};
+
+#[derive(Model)]
+pub struct Question {
+ id: Option<Id>,
+ #[model(max_length=200)]
+ question_text: String,
+ /// date published
+ pub_date: time::PrimitiveDateTime,
+}
+
+#[derive(Model)]
+pub struct Choice {
+ id: Option<Id>,
+ #[model(Question, on_delete=Cascade)]
+ question: Id,
+ #[model(max_length=200)]
+ choice_text: String,
+ #[model(default = 0)]
+ votes: usize,
+}
diff --git a/examples/tutorial02/polls/urls.rs b/examples/tutorial02/polls/urls.rs
new file mode 100644
index 0000000..04d93cc
--- /dev/null
+++ b/examples/tutorial02/polls/urls.rs
@@ -0,0 +1,9 @@
+use tosin::urls::{UrlMap, url_map};
+
+use super::views;
+
+pub fn urls() -> UrlMap {
+ url_map! {
+ => views::index, // TODO name: "index"
+ }
+}
diff --git a/examples/tutorial02/polls/views.rs b/examples/tutorial02/polls/views.rs
new file mode 100644
index 0000000..4859cec
--- /dev/null
+++ b/examples/tutorial02/polls/views.rs
@@ -0,0 +1,5 @@
+use tosin::http::{Reply, Response};
+
+pub fn index() -> Response {
+ "Hello, world. You're at the polls index.".into_response()
+}