Beispiel #1
0
def defaults(): #creates the default user, all users' defaultKinds start as his
	defu = User()
	defu.name = 'RED UNICORN'
	defu.code = 'REDUNICORN'
	defu.save()
	defaultKinds = ['School', 'Work', 'Household', 'Social']
	for k in defaultKinds:
		newKind = Kind()
		newKind.name = k
		newKind.save()
		defu.defaultKinds.add(newKind)
	defu.save()
	return None
Beispiel #2
0
def root(request):
	if('REDUNICORN' not in [u.code for u in User.objects.all()]): #if default user doesn't exist
		defaults()

	if request.method == 'GET': 
		return render_to_response('root.html', context_instance=RequestContext(request))
	
	if request.method == 'POST':
		u = User()
		u.save()
		u.name = request.POST.get('name')		
		run = True
		while run:
			newCode = ''
			for i in range(10):
				newCode += str(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$-_.+!*'))
			run = newCode in [user.code for user in User.objects.all()] #must generate a unique code before exiting
		u.code = newCode 
		u.defaultKinds = User.objects.get(code='REDUNICORN').defaultKinds.all()
		u.save()
		return HttpResponseRedirect('user/'+u.code)