@@ 29-54 (lines=26) @@ | ||
26 | Session.session_key == machine_identifier |
|
27 | ) |
|
28 | ||
29 | def or_create(self, info, fetch=False): |
|
30 | machine_identifier = info.get('machineIdentifier') |
|
31 | ||
32 | if not machine_identifier: |
|
33 | log.info('No machine identifier available, unable to create session') |
|
34 | return None |
|
35 | ||
36 | try: |
|
37 | # Create new session |
|
38 | obj = self.manager.create( |
|
39 | rating_key=to_integer(info.get('ratingKey')), |
|
40 | session_key=machine_identifier, |
|
41 | ||
42 | state='create' |
|
43 | ) |
|
44 | ||
45 | # Update newly created object |
|
46 | self.manager.update(obj, info, fetch) |
|
47 | ||
48 | # Update active sessions |
|
49 | ModuleManager['sessions'].on_created(obj) |
|
50 | ||
51 | return obj |
|
52 | except (apsw.ConstraintError, peewee.IntegrityError): |
|
53 | # Return existing object |
|
54 | return self(info) |
|
55 | ||
56 | ||
57 | class UpdateLSession(UpdateSession): |
@@ 28-49 (lines=22) @@ | ||
25 | Session.session_key == self.build_session_key(session_key) |
|
26 | ) |
|
27 | ||
28 | def or_create(self, info, fetch=False): |
|
29 | session_key = to_integer(info.get('sessionKey')) |
|
30 | ||
31 | try: |
|
32 | # Create new session |
|
33 | obj = self.manager.create( |
|
34 | rating_key=to_integer(info.get('ratingKey')), |
|
35 | session_key=self.build_session_key(session_key), |
|
36 | ||
37 | state='create' |
|
38 | ) |
|
39 | ||
40 | # Update newly created object |
|
41 | self.manager.update(obj, info, fetch) |
|
42 | ||
43 | # Update active sessions |
|
44 | ModuleManager['sessions'].on_created(obj) |
|
45 | ||
46 | return obj |
|
47 | except (apsw.ConstraintError, peewee.IntegrityError): |
|
48 | # Return existing object |
|
49 | return self(info) |
|
50 | ||
51 | ||
52 | class UpdateWSession(UpdateSession): |