Esempio n. 1
0
def new(request):

    d2p = DictToPoint(request.REQUEST)
    pnt = d2p.pnt()

    if request.method == "POST":
        #an UpdateForm is bundled inside ReportForm
        report_form = ReportForm(request.POST,
                                 request.FILES,
                                 user=request.user)
        # this checks update is_valid too
        if report_form.is_valid():
            # this saves the update as part of the report.
            report = report_form.save()
            if report:
                return (HttpResponseRedirect(report.get_absolute_url()))
    else:
        initial = {}
        initial['lat'] = request.GET['lat']
        initial['lon'] = request.GET['lon']
        initial['address'] = request.GET.get('address', None)

        report_form = ReportForm(initial=initial, user=request.user)

    return render_to_response("reports/new.html", {
        "google": FixMyStreetMap(pnt, True),
        'GOOGLE_KEY': settings.GMAP_KEY,
        "report_form": report_form,
        "update_form": report_form.update_form,
        'ward': report_form.ward
    },
                              context_instance=RequestContext(request))
Esempio n. 2
0
def new( request ):
    
    d2p = DictToPoint( request.REQUEST )
    pnt = d2p.pnt()
     
    if request.method == "POST":
        #an UpdateForm is bundled inside ReportForm
        report_form = ReportForm( request.POST, request.FILES, user=request.user )
        # this checks update is_valid too
        if report_form.is_valid():
            # this saves the update as part of the report.
            report = report_form.save()
            if report:
                return( HttpResponseRedirect( report.get_absolute_url() ))
    else:
        initial = {}
        initial['lat' ] =request.GET['lat']
        initial['lon'] = request.GET['lon']
        initial['address'] = request.GET.get('address',None) 
    
        report_form = ReportForm( initial=initial, user=request.user )

    return render_to_response("reports/new.html",
                { "google": FixMyStreetMap(pnt, True),
                  'GOOGLE_KEY': settings.GMAP_KEY,
                  "report_form": report_form,
                  "update_form": report_form.update_form,
                  'ward': report_form.ward },
                context_instance=RequestContext(request))
Esempio n. 3
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)
Esempio n. 4
0
 def reports(self, request):
     if request.method != "POST":
         reports = Report.objects.filter(is_confirmed=True)
         if request.GET.has_key('lat') and request.GET.has_key('lon'):
             pnt = DictToPoint(request.GET).pnt()
             d = request.GET.get('r', '2')
             reports = reports.filter(point__distance_lte=(pnt, D(km=d)))
         if request.GET.has_key('start_date'):
             reports = reports.filter(
                 created_at__gte=request.GET['start_date'])
         if request.GET.has_key('end_date'):
             reports = reports.filter(
                 created_at__lte=request.GET['end_date'])
         reports = reports.order_by('-created_at')[:1000]
         return self._render_reports(request, reports)
     else:
         # creating a new report
         report_form = Open311ReportForm(request.POST,
                                         request.FILES,
                                         user=request.user)
         try:
             if report_form.is_valid():
                 report = report_form.save()
                 if report:
                     return (self._render_reports(request, [report]))
             return (self._render_errors(request, report_form.all_errors()))
         except InvalidAPIKey, e:
             return render(request,
                           'open311/v2/_errors.%s' % (self.content_type),
                           {'errors': {
                               '403': str(e)
                           }},
                           content_type='text/%s' % (self.content_type),
                           context_instance=RequestContext(request),
                           status=403)
Esempio n. 5
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()
    wards = Ward.objects.filter(geom__contains=dict2pt.__unicode__())
    if (len(wards) == 0):
        return( home(request, None, _("Sorry, we don't yet have that area in our database. Please have your area councillor contact fixmystreet.ca.")))
    
    ward = wards[0]
    
    # calculate date range for which to return reports
    if request.GET.has_key('years_ago'):
        years_ago = int(request.GET['years_ago'])
    else:
        years_ago = 0
    yearoffset = datetime.timedelta(days = 365 * years_ago )
    
    date_range_end = datetime.datetime.now() - yearoffset
    date_range_start = date_range_end - datetime.timedelta(days =365)
    
    # do we want to show older reports?
    if Report.objects.filter(ward=ward,created_at__lte=date_range_start).count() > 1:
        older_reports_link = _search_url(request, years_ago - 1) 
    else:
        older_reports_link = None
        
    reports = Report.objects.filter(created_at__gte = date_range_start, created_at__lte = date_range_end, is_confirmed = True,point__distance_lte=(pnt,D(km=2))).distance(pnt).order_by('-created_at')
    gmap = FixMyStreetMap(pnt,True,reports)
        
    return render_to_response("search_result.html",
                {'google' : gmap,
                 "pnt": pnt,
                 "enable_map": True,
                 "ward" : wards[0],
                 "reports" : reports,
                 "date_range_start": date_range_start,
                 "date_range_end": date_range_end,
                 "older_reports_link": older_reports_link },
                 context_instance=RequestContext(request))
Esempio n. 6
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))
Esempio n. 7
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)
Esempio n. 8
0
    def services(self, request):
        city = None
        if request.GET.has_key('lat') and request.GET.has_key('lon'):
            ward = DictToPoint(request.GET).ward()
            if not ward:
                return HttpResponse('lat/lon not supported', status=404)
            city = ward.city
        if request.GET.has_key('jurisdiction_id'):
            # expect format <city>_<province-abbrev>.fixmystreet.ca
            city = self._parse_jurisdiction(request.GET['jurisdiction_id'])
            if not city:
                return HttpResponse('jurisdiction_id provided not found',
                                    status=404)
        if not city:
            return HttpResponse('jurisdiction_id was not provided', status=400)

        categories = city.get_categories()

        return render_to_response('open311/v2/_services.%s' %
                                  (self.content_type),
                                  {'services': categories},
                                  mimetype='text/%s' % (self.content_type),
                                  context_instance=RequestContext(request))