def _getMatch(self, input): return extract_value_from_input( input=input, field_id="match_id", model_type="Match", model=match_model, )
def update_team(self, inputs): """Aggiorna una squadra esistente (Team) inputs: dict con i parametri per l'aggiornamento """ # TOTEST try: if inputs.get('team_id', None): team_to_update = extract_value_from_input( input=inputs, field_id='team_id', model_type='Team', model=TeamModel, ) except ObjectDoesNotExist: raise GraphQLError(u'Problemi durante il recupero di una squadra.') if inputs.get('name', None): team_to_update.name = inputs.get('name') if inputs.get('defender', None): team_to_update.defender = self._get_player(inputs.get('defender')) if inputs.get('striker', None): team_to_update.striker = self._get_player(inputs.get('striker')) team_to_update.save() return team_to_update
def create_team(self, inputs): """Crea una nuova squadra (Team) """ # TOTEST name = inputs.get('name') defender = extract_value_from_input(input=inputs, field_id='defender', model_type='User', model=User) striker = extract_value_from_input(input=inputs, field_id='striker', model_type='User', model=User) new_team = TeamModel(**{ 'name': name, 'defender': defender, 'striker': striker }) new_team.save() return new_team
def delete_team(self, inputs): try: team_to_delete = extract_value_from_input( input=inputs, field_id='team_id', model_type='Team', model=TeamModel, ) except ObjectDoesNotExist: raise GraphQLError(u'Problemi durante il recupero di una squadra.') return team_to_delete.delete()
def _get_player(self, user_id): """ Funzione di utilità per recuperare un utente in base all'id. """ input_id = { 'user': user_id, } player = extract_value_from_input(input=input_id, field_id='user', model_type='Player', model=User) return player
def delete_tournament(self, input): """ Cancellazione di un torneo. """ try: tour_to_delete = extract_value_from_input( input=input, field_id='tournament_id', model_type='Tournament', model=tournament_model, ) except ObjectDoesNotExist: raise GraphQLError(u'Problemi durante il recupero di un torneo.') return tour_to_delete.delete()
def createMatch(self, input): matchScoreService = MatchScoreService() # creo i match_score red_score = matchScoreService.createMatchScore({ 'team': input.get('red_team', None), 'score': input.get('score', 0), 'color': input.get('color', None) }) blue_score = matchScoreService.createMatchScore({ 'team': input.get('blue_team', None), 'score': input.get('score', 0), 'color': input.get('color', None) }) input_FK = { 'match_day': ['match_day', 'Round', round_model], 'tournament_id': ['tournament_id', 'Tournament', tournament_model] } for key in input_FK.keys(): input[key] = extract_value_from_input(input=input, field_id=input_FK[key][0], model_type=input_FK[key][1], model=input_FK[key][2]) # initialize the match match = match_model(location=input.get('location', None), red_score=red_score, blue_score=blue_score, match_day=input.get('match_day', None), tournament_id=input.get('tournament_id', None), match_ended=input.get('match_ended', False)) match.save() # chiamate per inizializzare il match return match
def update_tournament(self, input): """ Modifica dei dati di un torneo. """ # TOTEST try: if input.get('tournament_id', None): tournament_to_update = extract_value_from_input( input=input, field_id='tournament_id', model_type='Tournament', model=tournament_model, ) except ObjectDoesNotExist: raise GraphQLError(u'Problemi durante il recupero di una squadra.') if input.get('name', None): tournament_to_update.name = input.get('name') tournament_to_update.save() return tournament_to_update
def deleteMatch(self, input): """ Metodo per la cancellazione di un match che non è ancora cominciato. Il match è eliminabile quando non è ancora cominciato e quando non fa parte di un torneo. """ match = extract_value_from_input( input=input, field_id="match_id", model_type="Match", model=match_model, ) # controllo che il match sia cancellabile if match.tournament or match.match_started: # il match è iniziato raise GraphQLError(u"Il Match non si può eliminare.") # se lo è elimino il match return match.delete()
def createMatch(self, input): matchScoreService = MatchScoreService() self._checkDuplicate(input) # creo i match_score red_score = matchScoreService.createMatchScore( {"team": input.get("red_team", None), "score": 0, "color": "red"} ) blue_score = matchScoreService.createMatchScore( {"team": input.get("blue_team", None), "score": 0, "color": "blue"} ) input_FK = { "tournament_id": ["tournament_id", "Tournament", tournament_model] } for key in input_FK.keys(): input[key] = extract_value_from_input( input=input, field_id=input_FK[key][0], model_type=input_FK[key][1], model=input_FK[key][2], ) # initialize the match match = match_model( location=input.get("location", None), red_score=red_score, blue_score=blue_score, tournament_id=input.get("tournament_id", None), match_ended=input.get("match_ended", False), ) match.save() # chiamate per inizializzare il match return match
def _getMatchScore(self, input): return extract_value_from_input(input=input, field_id='team', model_type='Team', model=team_model)
def _getTeam(self, team_id): return extract_value_from_input( input={}, field_id="team", model_type="Team", model=team_model )