Esempio n. 1
0
	def save(self, request):
		try:
			if 'teamname' not in request.POST or request.POST['teamname'] == '':
				raise Exception(_('TEAM_EMPTY_NAME'))
			team = DtTeam(name=request.POST['teamname'])
			if 'teamid' in request.POST and request.POST['teamid'] != '' and request.POST['teamid'] != '0':
				team.id = int(request.POST['teamid']) 
			team.user = DtUser(id=request.session['user'].id)
			characters = [ DtCharacter.objects.get(id=int(c.split('_')[0])) for c in request.POST['characters'].split(',') if c != '' ]
			objs = [ DtObject.objects.get(id=int(c.split('_')[0])) for c in request.POST['objects'].split(',') if c != '' ]
			rooms = list()
			for c in request.POST['rooms'].split(','):
				if c != '':
					rooms.append(DtRoom.objects.get(number=c.split('_')[1], rotation=1))
					rooms.append(DtRoom.objects.get(number=c.split('_')[1], rotation=2))
			constraint = None
			if 'gameid' in request.POST and request.POST['gameid'] != '' and request.POST['gameid'] != 0:
				constraint = self.gameManager.getGame(request.POST['gameid']).constraint()
			elif 'constraintid' in request.POST and request.POST['constraintid'] != '' and request.POST['constraintid'] != 0:
				constraint = request.POST['constraintid']
			if constraint is not None:
				errors = self.teamManager.checkTeamConstraint(constraint, characters, objs, rooms)
			if len(errors) > 0:
				return self.templates.response('message_return', context={ 'errors': errors })
			team.save()
			DtTeamCharacter.objects.filter(team=team).delete()
			for c in characters:
				o = DtTeamCharacter()
				o.generateUid()
				o.team = team
				o.character = c
				o.save()
			DtTeamObject.objects.filter(team=team).delete()
			for c in objs:
				o = DtTeamObject()
				o.generateUid()
				o.team = team
				o.object = c
				o.save()
			DtTeamRoom.objects.filter(team=team).delete()
			for c in rooms:
				o = DtTeamRoom()
				o.generateUid()
				o.team = team
				o.room = c
				o.save()
		except Exception as err:
			return self.templates.response('message_return', context={ 'error': err})
		return self.templates.empty()
Esempio n. 2
0
	def randomsave(self, request):
		try:
			teamname, teams = request.session['user'].cache
		except:
			return self.templates.response('message_return', context={ 'error': _('RANDOM_NO_TEAM_GENERATE')})
		
		count = 1
		for characters, objects, rooms in teams:
			team = DtTeam()
			team.name = '%s_%d' % (teamname, count)
			team.user = DtUser(id=request.session['user'].id)
			team.save()
			for c in characters:
				o = DtTeamCharacter()
				o.generateUid()
				o.team = team
				o.character = c
				o.save()
			for c in objects:
				o = DtTeamObject()
				o.generateUid()
				o.team = team
				o.object = c
				o.save()
			for c in rooms:
				o = DtTeamRoom()
				o.generateUid()
				o.team = team
				o.room = c[0]
				o.save()
				o = DtTeamRoom()
				o.generateUid()
				o.team = team
				o.room = c[1]
				o.save()
			count += 1
		user = request.session['user']
		user.cache = None
		request.session['user'] = user
		return self.templates.response('message_return', context={ 'message': _('RANDOM_SAVE_DONE')})