Show More
@@ -168,6 +168,42 b' page titles, button labels, headers, and' | |||||
168 |
|
168 | |||
169 | .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case |
|
169 | .. _English title case: https://en.wikipedia.org/wiki/Capitalization#Title_case | |
170 |
|
170 | |||
|
171 | Template helpers (that is, everything in ``kallithea.lib.helpers``) | |||
|
172 | should only be referenced from templates. If you need to call a | |||
|
173 | helper from the Python code, consider moving the function somewhere | |||
|
174 | else (e.g. to the model). | |||
|
175 | ||||
|
176 | Notes on the SQLAlchemy session | |||
|
177 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |||
|
178 | ||||
|
179 | Each HTTP request runs inside an independent SQLAlchemy session (as well | |||
|
180 | as in an independent database transaction). Database model objects | |||
|
181 | (almost) always belong to a particular SQLAlchemy session, which means | |||
|
182 | that SQLAlchemy will ensure that they're kept in sync with the database | |||
|
183 | (but also means that they cannot be shared across requests). | |||
|
184 | ||||
|
185 | Objects can be added to the session using ``Session().add``, but this is | |||
|
186 | rarely needed: | |||
|
187 | ||||
|
188 | * When creating a database object by calling the constructor directly, | |||
|
189 | it must explicitly be added to the session. | |||
|
190 | ||||
|
191 | * When creating an object using a factory function (like | |||
|
192 | ``create_repo``), the returned object has already (by convention) | |||
|
193 | been added to the session, and should not be added again. | |||
|
194 | ||||
|
195 | * When getting an object from the session (via ``Session().query`` or | |||
|
196 | any of the utility functions that look up objects in the database), | |||
|
197 | it's already part of the session, and should not be added again. | |||
|
198 | SQLAlchemy monitors attribute modifications automatically for all | |||
|
199 | objects it knows about and syncs them to the database. | |||
|
200 | ||||
|
201 | SQLAlchemy also flushes changes to the database automatically; manually | |||
|
202 | calling ``Session().flush`` is usually only necessary when the Python | |||
|
203 | code needs the database to assign an "auto-increment" primary key ID to | |||
|
204 | a freshly created model object (before flushing, the ID attribute will | |||
|
205 | be ``None``). | |||
|
206 | ||||
171 |
|
207 | |||
172 | "Roadmap" |
|
208 | "Roadmap" | |
173 | --------- |
|
209 | --------- |
General Comments 0
You need to be logged in to leave comments.
Login now