def matchUnfinished_read(self, data, sesh): """Match Unfinished Returns any unfinished matches the thrower is involved in Arguments: data {dict} -- Data sent with the request sesh {Sesh._Session} -- Session associated with the request Returns: Services.Effect """ # Find all unfinished matches the thrower is involved in lMatches = Match.unfinished(sesh['thrower']['_id']) # If there's none if not lMatches: return Services.Effect([]) # Get the other throwers lThrowers = [] for d in lMatches: lThrowers.append( d['initiator'] == sesh['thrower']['_id'] and d['opponent'] or d['initiator']) # If there's any throwers dAliases = {} if lThrowers: oEffect = Services.read('auth', 'thrower/aliases', { "_internal_": Services.internalKey(), "ids": list(set(lThrowers)) }) if oEffect.errorExists(): return oEffect dAliases = oEffect.data # Add the aliases to each record for d in lMatches: s = d['initiator'] == sesh['thrower']['_id'] and d[ 'opponent'] or d['initiator'] d['alias'] = s in dAliases and dAliases[s] or 'N/A' # Return the matches return Services.Effect(lMatches)
def match_read(self, data, sesh): """Match (Read) Fetches and returns the stats from an existing match Arguments: data {dict} -- Data sent with the request sesh {Sesh._Session} -- Session associated with the request Returns: Services.Effect """ # Verify fields try: DictHelper.eval(data, ['id']) except ValueError as e: return Services.Effect(error=(1001, [(f, "missing") for f in e.args])) # Find the match dMatch = Match.get(data['id'], raw=True) if not dMatch: return Services.Effect(error=(1104, 'watl_match:%s' % data['id'])) # Get the aliases of both throwers oEffect = Services.read( 'auth', 'thrower/aliases', { "_internal_": Services.internalKey(), "ids": [dMatch['opponent'], dMatch['initiator']] }) if oEffect.errorExists(): return oEffect # Add the aliases dMatch['initiator_alias'] = oEffect.data[dMatch['initiator']] dMatch['opponent_alias'] = oEffect.data[dMatch['opponent']] # Else return the match return Services.Effect(dMatch)