Exemplo n.º 1
0
def invite(request):
	if request.method == 'POST':
		form = InviteForm(request.POST)
		if form.is_valid():
			data = form.cleaned_data
			invite = Invite()
			try:
				event = NewEvent.objects.get(id = data['event'])
				invitee = MyUser.objects.get(username = data['invitee'])
				inviter = MyUser.objects.get(id = data['inviter'])
			except ObjectDoesNotExist:
				return HttpResponse("Doesn't Exist!", 401)
			invite.event = event
			invite.invitee = invitee
			invite.inviter = inviter
			invite.save()
		else: 
			print "NOT valid"
	return HttpResponseRedirect('/frontend/personal')
Exemplo n.º 2
0
def inviteall(request, event_id):
	if request.method != 'POST':
		return HttpResponseRedirect('/frontend/personal')
	try:
		event_obj = NewEvent.objects.get(id = event_id)
	except ObjectDoesNotExist:
		return HttpResponse('Tried removing non-existent event!', 
				    status=401)
	this_user = MyUser.objects.get(username = request.user.username)
	if event_obj.creator != this_user:
		return HttpResponse('Unauthorized access', status=401)

	friend_obs = Friends.objects.filter(name = this_user)
	assert(len(friend_obs) <= 1)
	if len(friend_obs) == 1:
		for f in friend_obs[0].friends.all():
			#for every friend, send invite
			invite = Invite()
			invite.event = event_obj
			invite.invitee = f
			invite.inviter = this_user
			invite.save()
	return HttpResponseRedirect('/frontend/personal')