def create_game(cls, tournament_id, user_id, game_number): tournament_id = is_valid_uuid(tournament_id) user_id = is_valid_uuid(user_id) if tournament_id and user_id and game_number > 0: game_data = GameData.objects.filter(tournament_id=tournament_id, user_id=user_id, game_number=game_number).first() if not game_data: game_data = GameData.create(tournament_id, user_id, game_number) game_data.save() return True return False
def get_matchplay_object(tournament): import_data = tournament.matchplay.replace("'", '"') try: import_data = json.loads(import_data) except ValueError: return None if import_data is None: return None matchplays = [] for data in import_data: user_id = is_valid_uuid(data[1]) if user_id is not None: matchplay = MatchPlay() matchplay.user_id = user_id # set place matchplay.place = 0 try: matchplay.place = int(data[0]) except TypeError: matchplay.place = 0 # set scores matchplay.scores = [] for x in range(2, len(data) - 1): score = 0 try: score = int(data[x]) except TypeError: score = 0 matchplay.scores.append(score) matchplays.append(matchplay) return matchplays
def get_vod_url(vod_id): vod_id = is_valid_uuid(vod_id) if vod_id != None: vod = Vod.objects.filter(vod_id=vod_id).first() if vod != None: return '/media/' + vod.video return '/media/vods/default.mp4'
def tournaments_modify_views(request, id): id = is_valid_uuid(id) if request.user.admin and id != None: tournament = get_tournament(id) if tournament is None: redirect('/') if request.method == 'POST': form = ModifyTournament(request.POST) if form.is_valid(): testform = None tournament.name = form.cleaned_data.get('tournament_name') tournament.description = form.cleaned_data.get('tournament_description') tournament.entry_fee = form.cleaned_data.get('entry_fee') tournament.total_games = form.cleaned_data.get('total_games') tournament.tournament_date = form.cleaned_data.get('tournament_date') tournament.tournament_time = form.cleaned_data.get('tournament_time') tournament.sponsor_image = '/media/sponsors/sponsor-image-03.png' tournament.save(force_update=True) if tournament.id != id: return redirect('/') return redirect('/tournaments/') else: testform = None form = ModifyTournament(initial={'tournament_name': tournament.name,'tournament_description': tournament.description,'entry_fee': tournament.entry_fee,'total_games': tournament.total_games, 'tournament_date': tournament.tournament_date.strftime('%d-%m-%Y'), 'tournament_time': tournament.tournament_time}) return render(request, 'tournaments/modify-tournament.html', {'nbar': 'tournaments', 'form': form, 'tournament': tournament, 'testform':testform}) else: return redirect('/')
def remove_friend(cls, user_id, friend_id): user = cls.get_user_by_uuid(user_id) if user: friend_id = is_valid_uuid(friend_id) if user and friend_id: user.friends.remove(friend_id) return True return False
def remove_user_from_roster_obj(tournament, user_id): roster_data = tournament.roster if roster_data != None: user_id = is_valid_uuid(user_id) if user_id != None: user_id = str(user_id) roster = quickle.loads(roster_data) new_roster = [] for user in roster: if user != user_id: new_roster.append(user) tournament.roster = quickle.dumps(new_roster)
def get(self, request, *args, **kwargs): uuid = is_valid_uuid(request.user.id) notifications = [] if uuid: queryset = self.get_queryset() notifications = queryset.filter( recipient=uuid).order_by('-datetime') return Response({ "notifications": NotificationSerializer(notifications, context=self.get_serializer_context(), many=True).data, })
def get_sponsor_pic(request, id): id = is_valid_uuid(id) if id != None: sponsor = Sponsor.objects.filter(sponsor_id=id).first() if sponsor != None: settings = WebSettings() img = open(settings.os_path + 'media/' + str(sponsor.sponsor_image), 'rb') if img != None: return FileResponse(img) img = open(settings.os_path + 'media/sponsor-pictures/default.png', 'rb') if img != None: return FileResponse(img) else: return Http404('Could not find sponsor picture specified.')
def add_user_to_roster_obj(tournament, user_id): roster_data = tournament.roster if roster_data != None: user_id = is_valid_uuid(user_id) if user_id != None: user_id = str(user_id) roster = quickle.loads(roster_data) roster_length = len(roster) if roster_length < tournament.spots_reserved: exists = False for user in roster: if user == user_id: exists = True if not exists: roster.append(user_id) tournament.roster = quickle.dumps(roster)
def get_qualifying_object(tournament): if tournament is None: return None import_data = tournament.qualifiers.replace("'", '"') try: import_data = json.loads(import_data) except ValueError: return None if import_data is None: return None qualifyings = [] for data in import_data: user_id = is_valid_uuid(data[1]) if user_id is not None: qualifying = Qualifying() qualifying.user_id = user_id # set place qualifying.place = 0 try: qualifying.place = int(data[0]) except TypeError: qualifying.place = 0 # set scores qualifying.scores = [] for x in range(2, len(data) - 1): score = 0 try: score = int(data[x]) except TypeError: score = 0 qualifying.scores.append(score) qualifyings.append(qualifying) return qualifyings
def get_center_by_uuid(cls, uuid): uuid = is_valid_uuid(uuid) if uuid: return cls.objects.filter(center_id=uuid).first() return None
def get_game_data(cls, tournament_id, user_id, game_number): tournament_id = is_valid_uuid(tournament_id) user_id = is_valid_uuid(user_id) if tournament_id and user_id and game_number > 0: return cls.filter(tournament_id=tournament_id, user_id=user_id, game_number=game_number).first() return None
def get_sponsor(cls, uuid): if is_valid_uuid(uuid): return cls.objects.filter(sponsor_id=uuid).first() return None
def get_user_statistics(cls, uuid): uuid = is_valid_uuid(uuid) if uuid: return cls.objects.filter(user_id=uuid).first() return None
def get_tournament_data(self, user_id): user_id = is_valid_uuid(user_id) if user_id: return self.tournament_datas.filter(user__id=user_id).first() return None
def get_tournament_by_uuid(cls, uuid): uuid = is_valid_uuid(uuid) if uuid: return cls.objects.filter(id=uuid).first()
def get_pattern_by_id(cls, pattern_id): pattern_id = is_valid_uuid(pattern_id) if not pattern_id: return None return cls.objects.filter(pattern_id=pattern_id).first()
def get_center(center_id): center_id = is_valid_uuid(center_id) if center_id != None: return Center.objects.filter(center_id=center_id).first() else: return None