def store_email(request): json_rsp = {} json_rsp['success'] = False if request.method == 'POST': form = InviteRequestForm(request.POST) if form.is_valid(): form.save() json_rsp['success'] = True return HttpResponse(simplejson.dumps(json_rsp), content_type='application/json; charset=utf8') else: form = InviteRequestForm() return HttpResponse(simplejson.dumps(json_rsp), content_type='application/json; charset=utf8')
def invite(request, template_name="privatebeta/invite.html", extra_context=None): """ Allow a user to request an invite at a later date by entering their email address. **Arguments:** ``template_name`` The name of the tempalte to render. Optional, defaults to privatebeta/invite.html. ``extra_context`` A dictionary to add to the context of the view. Keys will become variable names and values will be accessible via those variables. Optional. **Context:** The context will contain an ``InviteRequestForm`` that represents a :model:`invitemelater.InviteRequest` accessible via the variable ``form``. If ``extra_context`` is provided, those variables will also be accessible. **Template:** :template:`privatebeta/invite.html` or the template name specified by ``template_name``. """ if request.POST: form = InviteRequestForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('privatebeta_sent')) else: form = InviteRequestForm() context = {'form': form} if extra_context is not None: context.update(extra_context) return render_to_response(template_name, context, context_instance=RequestContext(request))
def index(request): """Index view, displays login mechanism""" if request.user.is_authenticated(): #if loggedin - go to home page and display the interest graph return HttpResponseRedirect('home') # if form has been submitted, show the next steps, or show the form else: if request.method == 'POST': form = InviteRequestForm(request.POST) ctx = RequestContext(request, { 'version' : settings.APP_VERSION, 'form': form, }) if form.is_valid(): """ Check if the user has been invited or needs to be invited""" eml = form.cleaned_data['email'] # if invited then continue to login if user_invited_check(email=eml): ctx['invited']=True return render_to_response('index.html', ctx, RequestContext(request)) # else email is in the invitation queue else: if not InviteRequest.objects.filter(email=eml): form.save() return HttpResponseRedirect(reverse('privatebeta_sent')) else: # email address already exists # TO-DO handle the case when email address is not valid print "form is invalid" print form return HttpResponseRedirect(reverse('privatebeta_sent')) else: form = InviteRequestForm(request.POST) ctx = RequestContext(request, { 'version' : settings.APP_VERSION, 'form': form, }) ctx['invited']=False return render_to_response('index.html', ctx, RequestContext(request))