Exemplo n.º 1
0
 def __init__(self,data=None,files=None,initial=None,user=None):
     if data:
         d2p = DictToPoint(data,exceptclass=None)
     else:
         d2p = DictToPoint(initial,exceptclass=None)
     
     self.pnt = d2p.pnt()
     self.ward = d2p.ward()
     self.update_form = ReportUpdateForm(data=data,initial=initial,user=user,first_update = True)
     super(ReportForm,self).__init__(data,files, initial=initial)
     self.fields['category'] = CategoryChoiceField(self.ward)
Exemplo n.º 2
0
def search_address(request):
    if request.method == 'POST':
        address = iri_to_uri(u'/search?q=%s' % request.POST["q"])
        return HttpResponseRedirect( address )

    if request.GET.has_key('q'):
        address = request.GET["q"]
        return home( request, address, None )

    # should have a lat and lon by this time.
    dict2pt = DictToPoint( request.GET )
    pnt = dict2pt.pnt()
    ward = dict2pt.ward()
    if not ward:
        return( home(request, None, _("Sorry, we don't yet have that area in our database. Please have your area councillor contact fixmystreet.ca.")))
    
    try:
        page_no = int(request.GET.get('page', '1'))
    except ValueError:
        page_no = 1

    reportQ = Report.objects.filter(is_confirmed = True,point__distance_lte=(pnt,D(km=2))).distance(pnt).order_by('-created_at')
    paginator = Paginator(reportQ, 100) 
    
    try:
        page = paginator.page(page_no)
    except (EmptyPage, InvalidPage):
        page = paginator.page(paginator.num_pages)

    
    reports = page.object_list
    gmap = FixMyStreetMap(pnt,True,reports)
        
    return render_to_response("search_result.html",
                {'google' : gmap,
                 'GOOGLE_KEY': settings.GMAP_KEY,
                 "pnt": pnt,
                 "enable_map": True,
                 "ward" : ward,
                 "reports" : reports,
                 "page":page,
                 "url_parms": "&lat=%s&lon=%s" %( request.GET['lat'], request.GET['lon'])
                  },
                 context_instance=RequestContext(request))