Beispiel #1
0
def disable_filter(request, key):
    #class DisableFilterForm(forms.Form):
    aptf = AptFilter.all().filter("disable_string =", key).filter("active =", True).get()
    if not aptf:
        raise Http404("Could not find disable string")
    if request.method == "POST":
        form = DisableFilterForm(request.POST)
        if form.is_valid():
            aptf.disable_status = '%s,%s' % tuple((form.cleaned_data[x]
                                             for x in ('helpful', 'result')))
            aptf.active = False
            aptf.put()
            return direct_to_template(request, 'disablefilter-success.html')
    else:
        form = DisableFilterForm()
    return direct_to_template(request, 'disablefilter.html',
                              {'form': form})
Beispiel #2
0
def disable_filter(request, key):
    #class DisableFilterForm(forms.Form):
    aptf = AptFilter.all().filter("disable_string =",
                                  key).filter("active =", True).get()
    if not aptf:
        raise Http404("Could not find disable string")
    if request.method == "POST":
        form = DisableFilterForm(request.POST)
        if form.is_valid():
            aptf.disable_status = '%s,%s' % tuple(
                (form.cleaned_data[x] for x in ('helpful', 'result')))
            aptf.active = False
            aptf.put()
            return direct_to_template(request, 'disablefilter-success.html')
    else:
        form = DisableFilterForm()
    return direct_to_template(request, 'disablefilter.html', {'form': form})
Beispiel #3
0
def create_filter(request, city="boston", template="createfilter.html", initial={}, ContactForm=UserForm):
    city_info = settings.CITIES.get(city.lower())
    center = settings.CITY_CENTERS[city.lower()]

    contactform = ContactForm(request.POST or None, initial=initial)
    form = FilterForm(request.POST or None, initial=initial)
    if form.is_valid() and contactform.is_valid():
        cinfo = contactform.contactstring(request)

        m = price_re.search(request.POST.get('price'))
        lprice, hprice = map(float, m.groups())

        apth = AptHunter.all().filter("contactinfo =", cinfo)
        apth = apth.get()
        if apth:
            # Deactivate any old ones
            q = AptFilter.all().filter("apth =", apth)
            q.filter("active =", True)
            for result in q.fetch(1000):
                result.active = False
                result.disable_status = "Replaced, Replaced"
                result.put()

        boolean_data = {}
        for key in ('cats', 'concierge', 'washerdryer', 'heat', 'hotwater',
                    'brokerfee'):
            boolean_data[key] = int(form.cleaned_data[key])

        apth = AptHunter(key_name=cinfo,
                         contactinfo=cinfo,
                         first_created=datetime.datetime.now())
        apth.put()

        # Create Filter
        f = AptFilter(
            active = True,
            apth = apth,
            region = city.upper(),
            expires = form.cleaned_data['expires'],
            distance_centers = [], # Disabled
            distances = [], # Disabled
            polygons = request.POST["location-data"],
            price = [int(lprice), int(hprice)],
            size_names = form.cleaned_data['size'],
            size_weights = [1.0] * len(form.cleaned_data['size']),
            **boolean_data
            )
        f.put()

        namecinfo = cinfo.replace('@', 'AT').replace('.', 'DOT')
        email.enqueue_notify(cinfo)
        response = HttpResponseRedirect('../success/')
        user = AptHunter.make_user(contactform)
        user.last_city = city
        db.put(user)
        response.set_cookie("sessioncookie", user.sessioncookie)
        response.set_cookie("username", user.username)
        return response

    if request.user:
        contactform = None
        filterq = AptFilter.all().filter("apth =", request.user)
        if filterq.count(1) == 0:
            form = FilterForm()
        else:
            filterq.order("created")
            f = filterq.fetch(1)[0]
            fd = {}
            fd["cats"]        = f.cats
            fd["concierge"]   = f.concierge
            fd["washerdryer"] = f.washerdryer
            fd["heat"]        = f.heat
            fd["hotwater"]    = f.hotwater
            fd["brokerfee"]   = f.brokerfee
            fd["size"]        = f.size_names
            form = FilterForm(fd)

    context = {'form': form,
               'cform': contactform,
               'centerlat': center[0],
               'centerlng': center[1],
               'mapzoom': center[2],}

    context['AJAX_KEY'] = settings.GOOGLE_AJAX_KEYS.get(request.META['HTTP_HOST'].lower().split(':')[0])
    context['MAP_KEY'] = settings.GOOGLE_MAP_KEYS.get(request.META['HTTP_HOST'].lower().split(':')[0])
    context["CITY"] = city
    return direct_to_template(request, template, context)