def players_txt(request, gamename): try: game = Game.objects.get(name=gamename) except: return message(request, "The game %s does not exist" % gamename) joineds = list(Joined.objects.filter(game=game)) joineds.sort(key=lambda x: x.date_joined, reverse=False) return render(request, 'games/players.txt', { 'game': game, 'joineds': joineds, }, content_type='text/text')
def profile(request, username): maxdate = datetime.datetime(datetime.MAXYEAR, 1, 1) try: player = User.objects.get(username=username) except: player = None joineds = list(Joined.objects.filter(user=player)) joineds += getoldjoineds(player) olduser = getolduser(player) joineds.sort(key=lambda x: x.game.date_started or maxdate, reverse=True) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): body = request.POST['message'] send_mail( '[longturn] %s, a message from %s!' % (player, request.user), body + "\n\n--------\nThis message was sent using the longturn.net contact form.", request.user.email, [player.email], fail_silently=False) send_mail( '[longturn] Your message to %s has been sent' % (player), body + "\n\n--------\nKeep in mind %s might have given a fake address for some reason, so don't rely on it." % (player), request.user.email, [request.user.email], fail_silently=False) return message(request, "Message to %s has been sent" % player) else: form = ContactForm() return render( request, "registration/profile.html", { 'olduser': olduser, 'form': form, 'player': player, 'joineds': joineds, 'username': username, }, )
def profile(request, username): maxdate = datetime.datetime(datetime.MAXYEAR, 1, 1) try: player = User.objects.get(username=username) except: player = None joineds = list(Joined.objects.filter(user=player)) joineds += getoldjoineds(player) olduser = getolduser(player) joineds.sort(key=lambda x: x.game.date_started or maxdate, reverse=True) if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): body = request.POST['message'] send_mail( '[longturn] %s, a message from %s!' % (player, request.user), body + "\n\n--------\nThis message was sent using the longturn.org contact form.", request.user.email, [player.email], fail_silently=False) send_mail( '[longturn] Your message to %s has been sent' % (player), body + "\n\n--------\nKeep in mind %s might have given a fake address for some reason, so don't rely on it." % (player), request.user.email, [request.user.email], fail_silently=False) return message(request, "Message to %s has been sent" % player) else: form = ContactForm() return render_to_response( "registration/profile.html", { 'olduser': olduser, 'form': form, 'player': player, 'joineds': joineds, 'username': username, }, context_instance=RequestContext(request))
def game(request, gamename): old = 0 try: game = Game.objects.get(name=gamename) except: try: game = OldGame.objects.get(name=gamename) old = 1 except: return message(request, "The game %s does not exist" % gamename) joineds = None hasjoined = None serv = None startin = None form = None delegateform = None if not old: joineds = list(Joined.objects.filter(game=game)) try: hasjoined = Joined.objects.get(game=game, user=request.user) except: hasjoined = None serv = ServGlobalData.objects.filter(game=game) if game.date_started: startin = game.date_started - datetime.datetime.now() startin = startin.days else: startin = -1 if request.method == 'POST': if 'delegate' in request.POST: form = DelegateForm(request.POST) if form and form.is_valid(): regent = request.POST['regent'] joined = Joined.objects.get(game=game, user=request.user) joined.delegation = regent joined.save() else: return message(request, "Player \"%s\" is incorrect." % request.POST['regent']) elif 'nodelegate' in request.POST: joined = Joined.objects.get(game=game, user=request.user) joined.delegation = None joined.save() joineds = list(Joined.objects.filter(game=game)) if request.method == 'POST' and game.open == True: if 'signin' in request.POST: form = JoinForm(request.POST) if form.is_valid(): nation = request.POST['nation'] if nation != 'random': for j in joineds: if j.user != request.user and j.nation == nation: return message(request, "This nation has already been picked by %s" % j.user) joined, created = Joined.objects.get_or_create(game=game, user=request.user) joined.nation = nation joined.save() #os.system('%s/join_rate.pl %s' % (settings.PLOT_PATH, gamename)) elif 'signout' in request.POST: form = JoinForm(request.POST) if form.is_valid(): joined = Joined.objects.get(game=game, user=request.user) joined.delete() elif 'confirm' in request.POST: joined = Joined.objects.get(game=game, user=request.user) joined.confirmed = True joined.save() return HttpResponseRedirect("/game/%s/" % gamename) else: if hasjoined != None: nation = hasjoined.nation regent = hasjoined.delegation else: nation = 'random' regent = '' form = JoinForm( initial={ 'game': gamename, 'nation': nation, }) delegateform = DelegateForm( initial={ 'regent': regent, }) for j in joineds: if j.nation != "random": j.flag = nations.flags[j.nation] else: j.flag = 'unknown' #joineds.sort(key=lambda x: x.user.username.lower(), reverse=False) joineds.sort(key=lambda x: x.date_joined, reverse=False) else: joineds = list(OldJoined.objects.filter(game=game)) return render( request, 'games/game.html', { 'game': game, 'joineds': joineds, 'hasjoined': hasjoined, 'serv': serv, 'startin': startin, 'form': form, 'delegateform': delegateform, 'old': old, })
def game(request, gamename): old = 0 try: game = Game.objects.get(name=gamename) except: try: game = OldGame.objects.get(name=gamename) old = 1 except: return message(request, "The game %s does not exist" % gamename) joineds = None hasjoined = None serv = None startin = None form = None delegateform = None if not old: joineds = list(Joined.objects.filter(game=game)) try: hasjoined = Joined.objects.get(game=game, user=request.user) except: hasjoined = None serv = ServGlobalData.objects.filter(game=game) if game.date_started: startin = game.date_started - datetime.datetime.now() startin = startin.days else: startin = -1 if request.method == 'POST': if 'delegate' in request.POST: regent = request.POST['regent'] joined = Joined.objects.get(game=game, user=request.user) joined.delegation = regent joined.save() os.system('/home/longturn-www/longturn/log delegate %s to %s' % (request.user, regent)) elif 'nodelegate' in request.POST: joined = Joined.objects.get(game=game, user=request.user) joined.delegation = None joined.save() os.system('/home/longturn-www/longturn/log nodelegate %s' % (request.user)) if request.method == 'POST' and game.open == True: if 'signin' in request.POST: form = JoinForm(request.POST) if form.is_valid(): nation = request.POST['nation'] if nation != 'random': for j in joineds: if j.user != request.user and j.nation == nation: return message(request, "This nation has already been picked by %s" % j.user) joined, created = Joined.objects.get_or_create(game=game, user=request.user) joined.nation = nation joined.save() #os.system('%s/join_rate.pl %s' % (settings.PLOT_PATH, gamename)) elif 'signout' in request.POST: form = JoinForm(request.POST) if form.is_valid(): joined = Joined.objects.get(game=game, user=request.user) joined.delete() elif 'confirm' in request.POST: joined = Joined.objects.get(game=game, user=request.user) joined.confirmed = True joined.save() return HttpResponseRedirect("/game/%s/" % gamename) else: if hasjoined != None: nation = hasjoined.nation regent = hasjoined.delegation else: nation = 'random' regent = '' form = JoinForm( initial={ 'game': gamename, 'nation': nation, }) delegateform = DelegateForm( initial={ 'regent': regent, }) for j in joineds: if j.nation != "random": j.flag = nations.flags[j.nation] else: j.flag = 'unknown' #joineds.sort(key=lambda x: x.user.username.lower(), reverse=False) joineds.sort(key=lambda x: x.date_joined, reverse=False) else: joineds = list(OldJoined.objects.filter(game=game)) return render_to_response( 'games/game.html', { 'game': game, 'joineds': joineds, 'hasjoined': hasjoined, 'serv': serv, 'startin': startin, 'form': form, 'delegateform': delegateform, 'old': old, }, context_instance=RequestContext(request))