| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | Quick Start
 | 
					
						
							|  |  |  | ===========
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | We have two varieties of "quick start" instructions:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * :ref:`quick-start-generated`
 | 
					
						
							|  |  |  | * :ref:`quick-start-manual`
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. _quick-start-generated:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | From Generated Code
 | 
					
						
							|  |  |  | -------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Note that this section describes an app based on WuttaWeb (i.e. not
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | just WuttJamaican).  We'll name it "Poser" for sake of example.
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | Make a parent folder for all source code:
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | .. code-block:: sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    mkdir -p ~/src
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  | Make and activate a new :term:`virtual environment` for your project:
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  |    cd /path/to/envs
 | 
					
						
							|  |  |  |    python3 -m venv poser
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  |    source poser/bin/activate
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  | Make a new e.g. ``poser`` database in PostgreSQL (or MySQL).  Nothing
 | 
					
						
							|  |  |  | special here but for instructions see :ref:`create-appdb`.
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  | Install and run `cookiecutter <https://cookiecutter.readthedocs.io/>`_
 | 
					
						
							|  |  |  | with `wuttaweb template
 | 
					
						
							|  |  |  | <https://forgejo.wuttaproject.org/wutta/cookiecutter-wuttaweb>`_:
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  |    pip install cookiecutter
 | 
					
						
							|  |  |  |    cookiecutter -o ~/src git+https://forgejo.wuttaproject.org/wutta/cookiecutter-wuttaweb
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | Assuming you now have project code at ``~/src/poser`` then install
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  | that and run the app installer.  Note the 2nd command name will depend
 | 
					
						
							|  |  |  | on your project:
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  |    pip install -e ~/src/poser
 | 
					
						
							|  |  |  |    poser install
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-26 11:46:17 -06:00
										 |  |  | If all goes well, you can run the web app with:
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-03 09:31:43 -06:00
										 |  |  |    cd /path/to/envs/poser
 | 
					
						
							| 
									
										
										
										
											2025-01-26 09:54:35 -06:00
										 |  |  |    bin/wutta -c app/web.conf webapp -r
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | And browse it at http://localhost:9080
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. _quick-start-manual:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | From Scratch
 | 
					
						
							|  |  |  | ------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | This shows the *minimum* use case, basically how to make/use the
 | 
					
						
							|  |  |  | :term:`config object` and :term:`app handler`.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | (See next section for :ref:`db-setup`.)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You should have already made a :term:`virtual environment`.  Install
 | 
					
						
							|  |  |  | the package with:
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  |    pip install WuttJamaican[db]
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | Create a :term:`config file`, e.g. ``my.conf``:
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: ini
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    [foo]
 | 
					
						
							|  |  |  |    bar = A
 | 
					
						
							|  |  |  |    baz = 2
 | 
					
						
							|  |  |  |    feature = true
 | 
					
						
							|  |  |  |    words = the quick brown fox
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | In code, load the config and reference its values as needed, and/or
 | 
					
						
							|  |  |  | invoke other app/handler logic::
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |    from wuttjamaican.conf import make_config
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    config = make_config('/path/to/my.conf')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # this call..                        ..returns this value
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    config.get('foo.bar')                # 'A'
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    config.get('foo.baz')                # '2'
 | 
					
						
							|  |  |  |    config.get_int('foo.baz')            # 2
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    config.get('foo.feature')            # 'true'
 | 
					
						
							|  |  |  |    config.get_bool('foo.feature')       # True
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    config.get('foo.words')              # 'the quick brown fox'
 | 
					
						
							|  |  |  |    config.get_list('foo.words')         # ['the', 'quick', 'brown', 'fox']
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  |    # now for the app handler..and interacting with DB
 | 
					
						
							|  |  |  |    app = config.get_app()
 | 
					
						
							|  |  |  |    model = app.model
 | 
					
						
							|  |  |  |    session = app.make_session()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # invoke secondary handler to make new user account
 | 
					
						
							|  |  |  |    auth = app.get_auth_handler()
 | 
					
						
							|  |  |  |    user = auth.make_user(session=session, username='barney')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # commit changes to DB
 | 
					
						
							|  |  |  |    session.add(user)
 | 
					
						
							|  |  |  |    session.commit()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | For more info see:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * :func:`~wuttjamaican.conf.make_config()`
 | 
					
						
							|  |  |  | * :class:`~wuttjamaican.conf.WuttaConfig` and especially
 | 
					
						
							|  |  |  |   :meth:`~wuttjamaican.conf.WuttaConfig.get()`
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  | * :class:`~wuttjamaican.app.AppHandler`
 | 
					
						
							| 
									
										
										
										
											2023-11-21 18:27:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | .. _db-setup:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Database Setup
 | 
					
						
							| 
									
										
										
										
											2024-11-24 10:13:56 -06:00
										 |  |  | ~~~~~~~~~~~~~~
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | You should already have the package installed (see previous section).
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Next you must create the database, as well as any user account needed,
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  | within the DB backend.  This is pretty routine but for instructions
 | 
					
						
							|  |  |  | see :ref:`create-appdb`.
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | Now add the DB info to your :term:`config file` (e.g. ``my.conf`` as
 | 
					
						
							|  |  |  | shown above).  Contents for this will look something like (using
 | 
					
						
							|  |  |  | ``poserdb`` as the DB name):
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: ini
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    [wutta.db]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # postgres
 | 
					
						
							|  |  |  |    default.url = postgresql://USERNAME:PASSWORD@localhost/poserdb
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    # mysql
 | 
					
						
							|  |  |  |    default.url = mysql+mysqlconnector://USERNAME:PASSWORD@localhost/poserdb
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You also must add some Alembic config, needed for DB schema
 | 
					
						
							|  |  |  | migrations:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: ini
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    [alembic]
 | 
					
						
							|  |  |  |    script_location = wuttjamaican.db:alembic
 | 
					
						
							|  |  |  |    version_locations = wuttjamaican.db:alembic/versions
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | With config file updated you can run the Alembic command to migrate schema:
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: sh
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  |    alembic -c /path/to/my.conf upgrade heads
 | 
					
						
							| 
									
										
										
										
											2024-08-23 15:20:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | Now you should have all the tables required for a WuttJamaican
 | 
					
						
							|  |  |  | :term:`app database`.
 | 
					
						
							| 
									
										
										
										
											2024-12-08 12:19:42 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | If you wish to store :term:`config settings <config setting>` in the
 | 
					
						
							|  |  |  | DB, don't forget to add to your config file (see also
 | 
					
						
							|  |  |  | :ref:`where-config-settings-come-from`):
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. code-block:: ini
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    [wutta.config]
 | 
					
						
							|  |  |  |    usedb = true
 | 
					
						
							|  |  |  |    preferdb = true
 |