Beispiel #1
0
def search(request):
    """
    Searches images for the following possible criteria:
        * Date time | all images between two dates
        * Location  | all images within one to many 'geofilters' which are a lat/lng point and radius
        * Tag       | all images matching either all, or at least one, tag, depending on the search conjunctivity
    Currently returns map points, as it's only used by Maps, but is searching images then transforming them,
    so could easily be factored more generally (indeed, it probably should...) 
    """
    #TODO - move these into a better/more extensible location
    geofiltered = []
    datefiltered = []
    tagfiltered = []

    if request.POST["geo_filter"] == "true":
        f_count = request.POST["filters"]
        filters = []
        for i in xrange(int(f_count)):
            filters.append(geofilter.Geofilter(i, request.POST["filter_"+str(i)+"_rad"], request.POST["filter_"+str(i)+"_lat"], request.POST["filter_"+str(i)+"_lng"]))
        imgs = Image.objects.filter(is_approved = True)
        for gfilter in filters:
            search_result = search_utils.filter_location(gfilter, imgs)        
            geofiltered = set(geofiltered).union(search_result)

    if request.POST["date_filter"] == "true":    
        date_from = datetime.strptime(request.POST["from"], "%d/%m/%Y")
        date_to = datetime.strptime(request.POST["to"], "%d/%m/%Y")
        datefiltered.extend(search_utils.filter_date(date_from, date_to))

    if request.POST["tag_filter"] == "true":
        tags = [x for x in request.POST["tags"].split(',') if x]
        for img in Image.objects.filter(is_approved = True):
            tag_matches = map((lambda t : t in [x.tag_text for x in img.tags.all()]), tags)
            if len(tag_matches) == 0: continue
            conjunctive = request.POST["conjunctive"] == 'true'
            if(conjunctive and all(tag_matches)):
                tagfiltered.append(img)
            elif(not conjunctive and any(tag_matches)):
                tagfiltered.append(img)
        print tagfiltered           

    latlngs = Image.objects.filter(is_approved = True)
    #TODO - refactor meeeeee
    if len(geofiltered) > 0: latlngs = set(latlngs).intersection(set(geofiltered))
    if len(datefiltered) > 0: latlngs = set(latlngs).intersection(set(datefiltered))
    if len(tagfiltered) > 0: latlngs = set(latlngs).intersection(set(tagfiltered))
    if len(geofiltered) + len(datefiltered) + len(tagfiltered) == 0: latlngs = []
    respDict = {}
    points = [search_utils.to_map_point(image) for image in latlngs]
 
    respDict["points"] = points

    resp = HttpResponse(json.dumps(respDict), "application/json", 200)
    return resp
Beispiel #2
0
def maps(request):
    """
    Converts all images into google maps compatible points, and renders the maps and search sidebar
    html componenents
    """
    #convert image locations to google maps parsable points
    now = datetime.utcnow().replace(tzinfo=utc)
    latlngs = search_utils.filter_date(search_utils.min_date, now)
    points = [search_utils.to_map_point(image) for image in latlngs]
    #load the search form sidebar
    # t = loader.get_template("wainz/search_form.html")
    # ctx = Context({})
    # search_form = t.render(ctx)

    return render_to_response('wainz/mappage.html', {"latLngs":points, "typeAheadTags":Tag.objects.all()}, context_instance = RequestContext(request))
Beispiel #3
0
def maps(request):
    """
    Converts all images into google maps compatible points, and renders the map
    """
    #convert image locations to google maps parsable points
    now = datetime.utcnow().replace(tzinfo=utc)

    notApprovedImages = Image.objects.order_by('-submission_date').filter(is_approved=False)[0:10000]
    unapproved = [search_utils.to_map_point(image) for image in notApprovedImages]

    latlngs = search_utils.filter_date(search_utils.min_date, now)
    points = [search_utils.to_map_point(image) for image in latlngs]
    
    #load the search form sidebar
    # t = loader.get_template("riverwatch/search_form.html")
    # ctx = Context({})
    # search_form = t.render(ctx)

    return render_to_response('riverwatch/mappage.html', {"latLngs":points, "unapproved":unapproved, "all_tags":Tag.objects.all(),}, context_instance = RequestContext(request))
Beispiel #4
0
def homepage(request):
    now = datetime.utcnow().replace(tzinfo=utc)
    latlngs = search_utils.filter_date(search_utils.min_date, now)
    points = [search_utils.to_map_point(image) for image in latlngs]
    return render_to_response('index.html', {"latLngs":points}, context_instance = RequestContext(request))