Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat+refactor: Improved and extended
Skeleton.subskel()
(viur-frame…
…work#1259) This PR introduces a new way to define sub-skeletons, additionally to the old one. 1. Renames `Skeleton.subSkel()` into `Skeleton.subskel()` with a deprecation warning 2. Giving names as parameter merges the bones of all `Skeleton.subSkels`-configurations together. This is the usual behavior. 3. Given the `bones`-parameter allows to freely specify a sub-skeleton; One specialty here is, that the order of the bones can also be changed in this mode! 4. 2 + 3 can be combined, but then the original order of the bones is kept 5. Mostly backward-compatible to the original `Skeleton.subSkel()` except that `fnmatch` is used to resolve wildcards, which is more powerful (the old implementation only accepted "*" at the end of the name). Example Skeleton: ```py from viur.core import skeleton, utils from viur.core.bones import * class TodoSkel(skeleton.Skeleton): subSkels = { "*": ["*name"], "add": ["subject"], } firstname = StringBone( descr="Vorname", ) lastname = StringBone( descr="Nachname", required=True, ) category = SelectBone( descr="Kategorie", defaultValue="question", required=True, values={ "question": "Anfrage", "billing": "Abrechnung", "service": "Service", }, ) subject = StringBone( descr="Thema", required=True, ) message = TextBone( descr="Nachricht", required=True, validHtml=None, ) status = SelectBone( descr="Status", required=True, defaultValue="open", values={ "open": "Offen", "pending": "In Bearbeitung", "closed": "Geschlossen", }, ) user = UserBone( descr="Zugewiesen an", ) ``` Example usage: ```py # legacy mode (see 2) subskel = TodoSkel.subskel("add") # creates subskel: key, firstname, lastname, subject # free mode (see 3): subskel = TodoSkel.subskel(bones=("subject", "message", "*stname")) # creates subskel: key, subject, message, firstname, lastname # mixed mode (see 4) subskel = TodoSkel.subskel("add", bones=("message", )) # creates subskel: key, firstname, lastname, subject, message ``` --------- Co-authored-by: Sven Eberth <[email protected]>
- Loading branch information