Changes between Version 17 and Version 18 of S3/S3Tracking
- Timestamp:
- 06/13/14 12:19:35 (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/S3Tracking
v17 v18 19 19 20 20 As this is a pre-defined re-usable field, simply add it to your model: 21 {{{ 21 {{{#!python 22 22 table = self.define_table(tablename, 23 23 ... … … 30 30 31 31 This can be done by defining {{{sit_trackable}}} as super-entity: 32 {{{ 32 {{{#!python 33 33 table = self.define_table(tablename, 34 34 ... … … 42 42 43 43 There is no problem to have this together with other super-entities (the number of super-entities per table is not limited): 44 {{{ 44 {{{#!python 45 45 table = self.define_table(tablename, 46 46 ... … … 60 60 61 61 You can create an S3Trackable by using the {{{s3tracker}}} function with the table and the record ID: 62 {{{ 62 {{{#!python 63 63 trackable = s3tracker(db.my_table, 1) 64 64 }}} 65 65 66 66 Instead of the table, you can specify the tablename: 67 {{{ 67 {{{#!python 68 68 trackable = s3tracker(tablename="my_table", record_id=1) 69 69 }}} 70 70 71 71 You can also specify a query: 72 {{{ 72 {{{#!python 73 73 query = (db.my_table.uuid == "9207324b-5dc6-439b-9410-8920cbaf8a34") 74 74 trackable = s3tracker(query=query) … … 76 76 77 77 or a record (must be a Row instance): 78 {{{ 78 {{{#!python 79 79 record = db(db.my_table.uuid == "9207324b-5dc6-439b-9410-8920cbaf8a34").select(limitby=(0, 1)).first() 80 80 trackable = s3tracker(record=record) … … 85 85 It is possible to specify a super-entity for an {{{S3Trackable}}}. In this case, the tracker will automatically find the respective records in the instance table(s) and use them instead: 86 86 87 {{{ 87 {{{#!python 88 88 trackable = s3tracker(db.pr_pentity, 1) # <= the super-entity is automatically replaced by the respective instance record (e.g. in pr_person) 89 89 }}} … … 92 92 === Base Location === 93 93 To retrieve the base location of an object, use {{{get_base_location()}}}: 94 {{{ 94 {{{#!python 95 95 base_location = s3tracker(db.pr_person, 1).get_base_location() 96 96 }}} … … 99 99 100 100 To set the base location of an object, use set_base_location(): 101 {{{ 101 {{{#!python 102 102 s3tracker(db.pr_person, 1).set_base_location(25) # <= use the record ID of a gis_location 103 103 }}} 104 104 105 105 Other ways to specify the location: 106 {{{ 106 {{{#!python 107 107 # Using a location record 108 108 location = db(db.gis_location.id == 25).select(limitby=(0, 1)).first() … … 120 120 === Current location === 121 121 When setting/retrieving the current location of an object, you can additionally specify a time point: 122 {{{ 122 {{{#!python 123 123 from datetime import datetime, timedelta 124 124 one_hour_ago = datetime.utcnow() - timedelta(hours=1) … … 129 129 130 130 To set a current location, you can use {{{set_location()}}}. 131 {{{ 131 {{{#!python 132 132 s3tracker(db.pr_person, 1).set_location(25, timestmp=datetime.utcnow()) 133 133 }}} … … 142 142 This can be achieved by using the {{{check_in()}}} and {{{check_out()}}} methods. 143 143 144 {{{ 144 {{{#!python 145 145 >>> s3tracker(db.vt_vehicle, 1).set_location(40) # <= set a current location for the vehicle 146 146 >>> s3tracker(db.pr_person, 1).check_in(db.vt_vehicle, 1) # <= check in the person to the vehicle … … 164 164 165 165 If you specify a super-entity instance to check-in to, then the respective instance record will automatically be used: 166 {{{ 166 {{{#!python 167 167 s3tracker(db.pr_person, 1).check_in(db.org_site, 4) # <= checks-in the person to the respective org_site instance, i.e. hospital or office... 168 168 }}}