示例#1
0
def submitgameplatforms(request,id="-1"):
	context = {'topnav':'submitgameplatforms'}
	try:
		game = Game.objects.get(id=id)
	except Game.DoesNotExist:
		return render_to_response('unicorn/gamesdoesnotexist.html')


	if request.method == 'POST': 
		game.platforms.clear()
		for platform in GamePlatform.objects.all():
			if (str(platform.id) in request.POST):
				url = request.POST[str(platform.id)]
				if url:
					link = GamePlatformLink(platform=platform,game=game,url=url)
					link.save()
		game.save()
		context['success'] = True 
		return HttpResponseRedirect(reverse('games.views.submitgamecategories', kwargs={'id': game.id}))
	
	links = []
	for platform in GamePlatform.objects.all():
		link = GamePlatformLink(platform=platform,game=game)
		for l in GamePlatformLink.objects.filter(game=game):
			if(l.platform == platform):
				link = l
				hasLink = True
		links.append({'platform':link.platform,'url':link.url})

	context['game'] = game;
	context['links'] = links;
	return render_to_response('unicorn/submitgame_links.html', context,context_instance=RequestContext(request))
示例#2
0
def submitgameplatforms(request,id="-1"):
	context = {'topnav':'submitgameplatforms'}
	try:
		game = Game.objects.get(id=id)
	except Game.DoesNotExist:
		return render_to_response('unicorn/gamesdoesnotexist.html')
	if request.user.is_authenticated():
		if not ((game.users.filter(id = request.user.id)[:1]) or (request.user.is_staff)):
			return HttpResponseRedirect(reverse('account_login'))

	if request.method == 'POST': 
		
		for platform in GamePlatform.objects.all():
			if (str(platform.id) in request.POST) or 'file_'+str(platform.id) in request.FILES:
				try:
					old = GamePlatformLink.objects.get(game=game,platform=platform)
				except GamePlatformLink.DoesNotExist:
					old = None

				url = request.POST[str(platform.id)]
		
				if 'file_'+str(platform.id) in request.FILES:
					link = GamePlatformLink(platform=platform,game=game,archive=request.FILES['file_'+str(platform.id)])
					if link.archive.size>40*1024*1024:
						context['error'] = True
						context['errorMsg'] = "The file was too large. Keep it under 40MB or host it yourself.";
					else:
						link.save()
					if old:
						old.delete()
				elif url != '':
					link = GamePlatformLink(platform=platform,game=game,url=url)
					link.save()
					if old:
						old.delete()
		game.save()
		context['success'] = True 
		return HttpResponseRedirect(reverse('games.views.submitgamecategories', kwargs={'id': game.id}))
	
	links = []
	for platform in GamePlatform.objects.all():
		link = GamePlatformLink(platform=platform,game=game)
		for l in GamePlatformLink.objects.filter(game=game):
			if(l.platform == platform):
				link = l
				hasLink = True
		links.append({'platform':link.platform,'url':link.url,'file':link.archive})

	context['game'] = game;
	context['links'] = links;
	return render_to_response('unicorn/submitgame_links.html', context,context_instance=RequestContext(request))