Package: pyrus-orm
pyrus-ormRadically simple, django/peewee-like, easy and incomplete ORM forPyrus.With pyrus-orm, you can read, create and modifytasks.Works withpyrus-apiunder the hood.This is an early development versionFeatures:Define models with:simple fields (text, number, dates, checkmark, flag, ...)catalog fields, single itemcatalog fields, multiple items"title" fields (pyrus-orm ignores the nested structure of 'title' fields, all its contents are treated as usual root-level fields)multiple choice fields (without nested fields at this moment)Operations with models:Create and saveRead from registry by IDModify and save changesFiltering:by include_archived and steps fieldsby value of simple or catalog fieldsless than, greater thanvalue in a listrangesInstallationpipinstallpyrus-ormExamplesDefine model and initializeclassBook(PyrusModel):title=TextField(1)# 1 is a field ID in pyrus's formtime=TimeField(2)date=DateField(3)number=NumericField(4)round_number=IntegerField(5)author=CatalogField(6,catalog=<catalogid>)classMeta:form_id=<form_id>pyrus_api=PyrusAPI(...)session=PyrusORMSession(pyrus_api)set_session_global(session)Create itembook=Book(title='Don Quixote',date='1605-01-01',author=Book.author.find({'Name':'Alonso Fernández de Avellaneda'}))book.save()book.id>>><task_id>Read and modify itembook=Book.objects.get(id=...)# simple fieldbook.title>>>'Don Quixote'book.title='Don Quixote, Part Two'book.save('title changed')# catalog fieldbook.author>>>CatalogItem(item_id=...,values={'Name':'Alonso Fernández de Avellaneda'})# values comes from the catalog definitionbook.author.find_and_set({'Name':'Miguel de Cervantes'})# may raise ValueError if no value foundbook.save('changed an author to the real one')Catalog Enum fieldsEnums can be mapped to catalog items by ID or by custom property name.Enums mapped to specific catalog items IDNo catalog lookups are preformed on reading or writing of such fields.classGenre(Enum):fiction=100001nonfiction=100002classBook(PyrusModel):genre=CatalogEnumField(<field_id>,catalog_id=<catalog_id>,enum=Genre,id_field='item_id')book=Book.objects.get(id=...)book.genre>>>Genre.fictionbook.genre=Genre.nonfictionbook.save()book.genre>>>Genre.nonfictionEnums mapped to catalog item properties(imagine book has a property 'media' with field 'Name')classMedia(Enum):paper='paper'papirus='papirus'pdf='pdf'classBook(PyrusModel):media=CatalogEnumField(<field_id>,catalog_id=<catalog_id>,enum=Genre,id_field='Name')FilteringOnly basic filtering is supported:Book.objects.get_filtered(title='Don Quixote',)>>>[Book(...),...]Book.objects.get_filtered(genre=Book.genre.find({'Name':'Fiction'}))>>>[Book(...),...]Book.objects.get_filtered(...include_archived=True,steps=[1,2],)>>>[Book(...),...]Catalog fields, all the API# Read values# Non-empty valuebook.author>>>CatalogItem(item_id=...,values={<yourcustomvalueshere>})assertbool(book.author)==True# Empty valuebook.author>>>CatalogEmptyValue()assertbool(book.author)==False# Get all possible values (works for empty fields as well)book.author.catalog()>>>[CatalogItem(...),CatalogItem(...),...]# Find a value in a catalognew_author=book.author.catalog().find({'Name':'Miguel de Cervantes'})new_author>>>CatalogItem(item_id=...,values={'Name':'Miguel de Cervantes'})# or Nonebook.author=new_authorbook.save()# Find and set shortcutbook.author.catalog().find_and_set({'Name':'William Shakespeare'})book.author.find_and_set({'Name':'NonExistent'})>>>ValueErrorraised# Set value to a specific item_idbook.author=CatalogItem(item_id=123456)