From 6e6cac950cac21eabc741e1a63ba3c84f9d872d6 Mon Sep 17 00:00:00 2001 From: agrogers Date: Mon, 9 Nov 2020 10:58:11 +1000 Subject: [PATCH 1/4] Added a missing bracket. --- docs/glossary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/glossary.md b/docs/glossary.md index 92b524e..8dbb87d 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -43,7 +43,7 @@ and converts the result into a string. Often that string is rendered as HTML to * The action named `@action('index')` would process the HTTP request `myapp/index`, calling the controller function `index`. -* The action named `@action('view/'` would process HTTP requests like `myapp/view/2022` to +* The action named `@action('view/')` would process HTTP requests like `myapp/view/2022` to call a controller function named `view` on the record whose ID is 2022 * The action named `@action('edit/',method=['GET','POST'])` would work on an edit form, so `myapp/edit/2022` would call the controller function named `edit`. It could, for example, display the contents of the record whose ID is 2022 (the `GET` request) in form, and post back any changes to it (the `EDIT` request) From b7cbb872c9895b0b689abfba239747ef993e6f7a Mon Sep 17 00:00:00 2001 From: agrogers Date: Mon, 9 Nov 2020 11:03:20 +1000 Subject: [PATCH 2/4] Removed 'to' that was not needed. --- docs/glossary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/glossary.md b/docs/glossary.md index 8dbb87d..16a6dcd 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -72,7 +72,7 @@ See also [MVC](#mvc) ## DAL -DAL stands for Database Abstraction Layer (DAL). From the [PyDAL](https://github.com/web2py/pydal) documentation: A DAL is "an API that maps Python objects into database objects such as queries, tables, and records." A DAL differ from an [ORM](#orm) in that it doesn't use an extensive object model. In practice that means it's lightweight, faster, and requires less overhead to both to write and to execute. It also lets you perform database operations on noSQL and SQL databases using the same Python code. +DAL stands for Database Abstraction Layer (DAL). From the [PyDAL](https://github.com/web2py/pydal) documentation: A DAL is "an API that maps Python objects into database objects such as queries, tables, and records." A DAL differ from an [ORM](#orm) in that it doesn't use an extensive object model. In practice that means it's lightweight, faster, and requires less overhead both to write and to execute. It also lets you perform database operations on noSQL and SQL databases using the same Python code. By default py4web uses [PyDal](#pydal) for its DAL, though you can use any Python ORM or DAL package you like. From a9e07f766d21a02fa7a2ba67298dc38d554061cd Mon Sep 17 00:00:00 2001 From: agrogers Date: Mon, 9 Nov 2020 11:03:51 +1000 Subject: [PATCH 3/4] Remove an errant line return. --- docs/glossary.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/glossary.md b/docs/glossary.md index 16a6dcd..a835939 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -78,8 +78,7 @@ By default py4web uses [PyDal](#pydal) for its DAL, though you can use any Pytho ## database level -When you define a model in [PyDal](#pydal), you can pass parameters to the [Field constructor](#field-constructor) -constraining whether record can be inserted into the database. The term used informally in py4web for this is that these are applied *database level*. +When you define a model in [PyDal](#pydal), you can pass parameters to the [Field constructor](#field-constructor) constraining whether record can be inserted into the database. The term used informally in py4web for this is that these are applied *database level*. For example, if your back end is SQL this would be a considered SQL constraint. In the example below, a column in the `task` table named `title` is defined as `notnull`. From 0e8627323ed71fc36a9f5ea3082f12bdc1bd8ff6 Mon Sep 17 00:00:00 2001 From: agrogers Date: Mon, 9 Nov 2020 14:42:38 +1000 Subject: [PATCH 4/4] Update glossary.md I modified some terminology that I found confusing when i was learning pyDAL. db(db.task).select(...) doesn't really return a query - it returns a list of records (or rows). To my mind, the query part is 'db.Task'. The 'select()' executes the query part and returns records (or rows). I often build big queries with something like q1=db.Task.id>10 and also q2=dbTask.id<100 and then records=db(q1 & q2).select(). So the query parts are inside the brackets. --- docs/glossary.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/glossary.md b/docs/glossary.md index a835939..8e81ffb 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -78,12 +78,11 @@ By default py4web uses [PyDal](#pydal) for its DAL, though you can use any Pytho ## database level -When you define a model in [PyDal](#pydal), you can pass parameters to the [Field constructor](#field-constructor) constraining whether record can be inserted into the database. The term used informally in py4web for this is that these are applied *database level*. +When you define a model in [PyDal](#pydal), you can pass parameters to the [Field constructor](#field-constructor) constraining whether the record can be inserted into the database. The term used informally in py4web for this is that these are applied considered atn *database level*. -For example, if your back end is SQL this would be a considered SQL constraint. +For example, if your back end is SQL this would be considered an SQL constraint. In the example below, a column in the `task` table named `title` is defined as `notnull`. -While it works on all back ends py4web supports, if it's a SQL database `notnull` would be -translated into a `NOT NULL` SQL constraint. +While it works on all database platforms py4web supports, if it's an SQL database `notnull` would be translated into a `NOT NULL` SQL constraint. ```python db.define_table('task', @@ -91,8 +90,7 @@ db.define_table('task', Field('description','text')) ``` -No matter what the PyDal form validators say, it's impossible in the above example -for a record to be added to the database with an empty `title` field, hence the term *database level*. +No matter what the PyDal form validators say, it's impossible in the above example for a record to be added to the database with an empty `title` field, hence the term *database level*. This differs from parameters applied at the *[forms level](#forms-level)*, which constrain data entry at runtime. @@ -294,28 +292,28 @@ Unfortunately Django web framework confuses `view` with `template`, so py4web so that usage. The python code is embedded into HTML using square brackets as delimiter by convention, although -that can be changed on a per-function bases with py4web (shown below). This example ranges through -a set named `query` returned from a [PyDAL](#pydal) `select` call: +that can be changed on a per-function basis with py4web (shown below). This example loops through +a set named `records` returned from a [PyDAL](#pydal) `select` call: ```html - [[for q in query:]] - [[=q.priority]][[=q.title]] + [[for r in records:]] + [[=r.priority]][[=r.title]] [[pass]] ``` ### view example Here's a complete though simplistic example of Python embedded in a view. The controller -generates a query of the `task` table that returns all tasks in reverse priority order. -It returns that query as a Python [dictionary object](https://realpython.com/python-dicts/): +generates a set of records based on the `task` table that includes all tasks in reverse priority order. +It returns those records as a Python [dictionary object](https://realpython.com/python-dicts/): ##### file controllers.py ```python @action('index') def index(): - query=db(db.task).select(orderby=~db.task.priority) - return dict(query=query) + records=db(db.task).select(orderby=~db.task.priority) + return dict(records=records) ``` The `index` [action](#action) shown above is shorthand for this: @@ -335,8 +333,8 @@ the `index.html` [template](#template):

Tasks

- [[for q in query:]] - + [[for r in records:]] + [[pass]]
PriorityTitle
[[=q.priority]][[=q.title]]
[[=r.priority]][[=r.title]]
[[=A('New task', _href=URL('new'))]]