コード例 #1
0
def confirm_booking(request, pod_id):
    pod = Pod.objects.get(pk=pod_id)
    request.session['pod_id'] = pod_id

    start_datetime = request.session['start_datetime']
    end_datetime = request.session['end_datetime']

    if request.method == 'POST':
        pod_id = request.session['pod_id']
        form = ConfirmForm(request.POST, pod_id=pod_id, username=request.user.username)
        if form.is_valid():
            config_set = form.cleaned_data['config_set']

            b = Booking.objects.create(user=request.user.username,
                                       pod=Pod.objects.get(pk=pod_id),
                                       start_datetime=start_datetime, end_datetime=end_datetime,
                                       config_set=ConfigSet.objects.get(pk=config_set))

            messages.add_message(request, messages.SUCCESS, 'Successfully Created Booking: {}'.format(b.__unicode__()))
            send_mail('Booking Confirmation',
                      'Hi {},\n\nI can confirm your booking: {}'.format(b.user,b.__unicode__()),
                      '*****@*****.**',
                      ['{}@example.com'.format(b.user)],
                      fail_silently=False)

            return redirect('ajax_app.views.my_bookings')
        else:
            config_set_form = ConfirmForm(request.POST, pod_id=pod_id, username=request.user.username)
    else:
        config_set_form = ConfirmForm(pod_id=pod_id, username=request.user.username)

    return render_to_response("book/confirm_booking.html",
                              {'pod': pod, 'config_set_form': config_set_form, 't1': start_datetime, 't2': end_datetime},
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: nims11/Foo-Barketplace
def deact_profile(request, nick, curr_user):
	"Admin Action: Deactivate profile nick"
	# error if curr_user doesn't have the rights
	if not curr_user.is_admin:
		return render(request, 'error.html', {'error': 'You are not allowed to be here!'})
	target_user = user(nick=nick)
	# error if target user doesn't exist or is an admin
	if target_user.user_obj == None:
		return render(request, 'error.html', {'error': 'User %s does not exist!' % nick})
	if target_user.is_admin:
		return render(request, 'error.html', {'error': 'Cannot Deactivate an Admin!'})
	if not target_user.is_active:
		return render(request, 'error.html', {'error': 'User %s already deactivated!' % nick})

	if request.method == 'POST':
		form = ConfirmForm(request.POST)
		if form.is_valid():
			if not form.cleaned_data.get('confirm', False):
				return HttpResponseRedirect(target_user.user_obj.get_url())
		else:
			return HttpResponseRedirect(target_user.user_obj.get_url())
	else:
		return render(request, 'confirm.html', {'form': ConfirmForm(), 'title': 'Deactivate user %s' % nick})
	target_user.user_obj.is_active = False
	target_user.user_obj.save()
	logging.info('Admin Action: Deactivated account %s' % target_user.user_obj.nick)
	return HttpResponseRedirect(target_user.user_obj.get_url())
コード例 #3
0
ファイル: views.py プロジェクト: abshkd/benzene
def confirm(request, code=''):
	if request.method == 'GET' and code:
		form = ConfirmForm({'confirmation_key':code})
		if form.is_valid():
			unconfirmed = form.cleaned_data['unconfirmed']
			new_user = User.objects.create_user(unconfirmed.username, unconfirmed.email, unconfirmed.password)
			new_user.save()
			unconfirmed.delete()
			login_user(request, new_user)
			return HttpResponseRedirect(reverse(profile, kwargs={'username': request.user.username}))
	return HttpResponse('The confirmation code was not valid.')
コード例 #4
0
ファイル: views.py プロジェクト: echo0101/PollApp
def confirm(request, poll_pk, keyword):
	request.session.set_test_cookie()
	c = {}
	poll = get_object_or_404(Poll, pk=poll_pk)

	c.update(csrf(request))
	sid = request.session.session_key

	if request.method == 'POST':
		form = ConfirmForm(request.POST)
		if form.is_valid():
		 	keyword = form.clean_keyword()
			choice = get_object_or_404(Choice, keyword=keyword)
			if WebVote.do_vote(sid, choice):
				return HttpResponseRedirect("/success/%s/%s/"%(poll.id, choice.id))
	else:
		form = ConfirmForm(initial={'keyword':keyword,'poll_id':poll.id,'sid_saved':sid})

	c['form'] = form
	c['poll'] = poll
	c['keyword'] = keyword
	return render_to_response('confirm.html', c, context_instance=RequestContext(request))