Exemplo n.º 1
0
def ajax_prospect_other(request):
    if request.POST:
        prospect_email = request.POST.get("email")
        p = Prospect.objects.filter(email=prospect_email)[0]

        form = ProspectForm(request.POST)
        if form.is_valid():
            c_postal_code = form.cleaned_data["postal_code"]

            p.postal_code = c_postal_code
            p.save()

            other = False
            active_city = False
            social = True

            prospect_msg = "Thanks! Find us on Facebook and Twitter to stay updated."
            sub_msg = "Invite friends to get an early invite when we make it to your city"

            form = ProspectForm()
            social = True

            """Send referral email"""
            sendComingSoonEmail(p)

            """Send admin referral email"""
            sendOtherSignupAdminEmail(p.email, c_postal_code)

            t = "home/ajax/newprospect_snippet.html"
            d = {
                "form": form,
                "prospect_msg": prospect_msg,
                "sub_msg": sub_msg,
                "active_city": active_city,
                "other": other,
                "social": social,
            }

            rendered = render_to_string(t, d)

            return HttpResponse(rendered, status=200)

        msg = "Enter valid postal code"
        return HttpResponse(msg, status=403)
Exemplo n.º 2
0
def main(request):
    user = getUser(request)
    
    meal_on = True
    if isWeekend():
        meal_on = False
    
    """Get expiration"""
    pacific = timezone('US/Pacific')
    pa_time = datetime.now(pacific)
    pa = pa_time.strftime('%d,%m,%Y,%B,%A')
    date_array = pa.split(',')
    
    day_as_num = int(date_array[0])
    month_as_num = int(date_array[1]) - 1
    year = date_array[2]
    
    """Get meal"""
    id=None
    store=None
    selected_recipes, item_dict, total = getMeal('sanfrancisco', store, id)
    
    url = None
    r_name = None
    r_attr = None
    if selected_recipes:
        r = selected_recipes[0]
        r_name = r.name
        r_attr = r.attribution
        image_key = str(r.image.file.blobstore_info.key())
        url = images.get_serving_url(image_key)
    else:
        meal_on = False
    
    if request.method == 'POST': 
        prospect = ProspectForm(request.POST) # A form bound to the POST data
        if prospect.is_valid():
            new_p = prospect.save()
            """Save location"""
            try:
                new_p.full_address = request.session['location']
            except KeyError:
                pass
            new_p.save()
            #logging.debug('New address: %s' % new_p.full_address)
            
            """Save referrer"""
            new_p.referrer = request.session['whereFrom']
            new_p.save()
            
            if 'referral' in request.GET:
                new_p.invite = request.GET.get('referral')
                new_p.save()
            
            return thanks_page(request, new_p)
    else:         
        prospect = ProspectForm()
    
    CITY_LIST = ['San Francisco', 'Other']
    
    request.session['whereFrom'] = request.META.get('HTTP_REFERER', '')
    template = 'home/home_current.html'
    
    data = {'user':user, 'form':prospect, 'year':year, 'date_today':pa_time, 'rname':r_name,
            'rattr':r_attr, 'image':url, 'dn':day_as_num, 'mn':month_as_num, 'city_list':CITY_LIST, 
            'meal_on':meal_on}
    
    return render_to_response(template, data,context_instance=RequestContext(request))
Exemplo n.º 3
0
def ajax_prospect(request, other_submit=False):

    if request.POST:
        form = ProspectForm(request.POST)

        if form.is_valid():
            c_email = form.cleaned_data["email"]
            c_city = request.POST.get("select_city")

            if "other" not in c_city:
                other = False
                active_city = True
                social = False

                existing_user = CreateNewUserHelper(request, c_email, c_city)

                prospect_msg = "Sweet! You're signed up to start receiving Yupeat service."
                sub_msg = ""

                city = c_city.replace("-", "")
                t = "home/ajax/newprospect_snippet.html"
                d = {
                    "prospect_msg": prospect_msg,
                    "other": other,
                    "social": social,
                    "active_city": active_city,
                    "sub_msg": sub_msg,
                    "city": city,
                }
                rendered = render_to_string(t, d)

                return HttpResponse(rendered, status=200)

            else:
                # created 'user_email' because of appengine quirk
                p = form.save()

                other = True
                active_city = False
                social = False

                prospect_msg = "Enter your postal code. Get notified when we make it to your city."
                sub_msg = "Want us in your city now? Be sure to tell all of your friends."

                pform = ProspectForm()
                csrf_token = csrf.get_token(request)

                t = "home/ajax/newprospect_snippet.html"
                d = {
                    "form": pform,
                    "prospect_msg": prospect_msg,
                    "sub_msg": sub_msg,
                    "csrf_token": csrf_token,
                    "active_city": active_city,
                    "social": social,
                    "other": other,
                    "prospect": p,
                }

                rendered = render_to_string(t, d)

                return HttpResponse(rendered, status=200)

        else:
            logging.error("request post not valid")
            msg = "Enter valid email to continue"
    return HttpResponse(msg, status=200)