def get_anc_details(request): smd = request.GET['smd'] data = { "anc": smd[0:2], "smd": smd[2:4], "num_smds": 123, "bounds": anc_data[smd[0]]['ancs'][smd[1]]['smds'][smd[2:4]]['bounds'], } data.update(CommissionerInfo.get_all(smd[0:2], smd[2:4])) return HttpResponse(json.dumps(data), content_type="application/json")
def get_anc_details(request): smd = request.GET['smd'] anc = smd[0:2] num_smds = len(anc_data[anc[0]]['ancs'][anc[1]]['smds']) data = { "anc": anc, "smd": smd[2:4], "num_smds": num_smds, "bounds": anc_data[smd[0]]['ancs'][smd[1]]['smds'][smd[2:4]]['bounds'], } data.update( CommissionerInfo.get_all(smd[0:2], smd[2:4]) ) return HttpResponse(json.dumps(data), content_type="application/json")
def get_anc_details(request): if "smd" not in request.GET: raise Http404() smd = request.GET['smd'] anc = smd[0:2] num_smds = len(anc_data[anc[0]]['ancs'][anc[1]]['smds']) data = { "anc": anc, "smd": smd[2:4], "num_smds": num_smds, "bounds": anc_data[smd[0]]['ancs'][smd[1]]['smds'][smd[2:4]]['bounds'], } data.update(CommissionerInfo.get_all(smd[0:2], smd[2:4])) return HttpResponse(json.dumps(data), content_type="application/json")
def get(self, request, anc, *args, **kwargs): # Get the ANC and static metadata from ancs.json. anc = anc.upper() try: info = anc_data[anc[0]]["ancs"][anc[1]] except KeyError: raise Http404() # For each SMD, pull in data from our database. smds = [] for smd in info['smds']: smddict = copy.deepcopy(info['smds'][smd]) smddict.update(CommissionerInfo.get_all(anc, smd)) smds.append(smddict) smds.sort(key=lambda x: x['smd']) # Get the committees. committees = CommissionerInfo.get(anc, None, 'committees') if committees is not None: committees = re.sub(r"(^|\n)# ", r"\1### ", committees) committees = markdown.markdown(committees) # Find the next meeting and the most recent two meetings so we can # display related documents for those meetings. now = datetime.datetime.now() all_meetings = meeting_data.get(anc, {}).get("meetings", {}) all_meetings = sorted([ datetime.datetime.strptime(m, "%Y-%m-%dT%H:%M:%S") for m in all_meetings.keys() if all_meetings[m].get("status") != "invalid" ]) next_meeting = None for m in all_meetings: if m > now: next_meeting = m # this is the first meeting in the future (i.e. the next meeting) break i = all_meetings.index( next_meeting) if next_meeting is not None else len(all_meetings) previous_meetings = all_meetings[i - 2:i] prep_hoods(info, True) for smd in info["smds"].values(): prep_hoods(smd, False) census_stats = [ { "key": "P0180002", "label": "families", "details": "A group of two or more related people residing together", "credit": "US Census" }, { "key": "P0180001", "label": "households", "details": "A house, apartment, or room intended as separate living quarters", "credit": "US Census" }, { "key": "P0010001", "label": "residents", "details": "The total population of the ANC", "credit": "US Census" }, { "key": "H0050001_PCT", "label": "vacant homes", "details": "Vacant housing units out of all housing units", "credit": "US Census", "is_percent": True }, { "key": "B07001_001E_PCT", "label": "new residents", "details": "Residents who moved into DC in the last year", "credit": "US Census", "is_percent": True }, { "key": "B01002_001E", "label": "median age", "details": "The median age of all residents in the ANC", "credit": "US Census" }, { "key": "B19019_001E", "label": "median household income", "details": "The median income of households in the ANC", "credit": "US Census", "is_dollars": True }, { "key": "POP_DENSITY", "label": u"density (pop/mi\u00B2)", "details": "Total population divided by the area of the ANC", "credit": "US Census" }, { "key": "liquor_licenses", "label": "liquor licenses", "details": "Liquor licenses granted by ABRA held by bars and restaurants in the area", "credit": "ABRA" }, { "key": "building_permits", "label": "building permits", "details": "Permits granted by DCRA for construction or alteration in the area", "credit": "DCRA" }, { "key": "311_requests", "label": "311 requests", "details": "Requests to the 311 hotline from this area", "credit": "SeeClickFix" }, ] for s in census_stats: try: s["value"] = info["census"][s["key"]]["value"] except KeyError: s["value"] = 0 s["grid"] = census_grids[s["key"]] # recent ANC documents recent_documents = Document.objects.filter( anc=anc).order_by('-created')[0:10] # documents that *should* exist highlight_documents = [] for mtg in previous_meetings + ([next_meeting] if next_meeting else []): hd_mtg = (mtg, []) highlight_documents.append(hd_mtg) has_doc = False for doc_type_id, doc_type_name in [(14, "Summary"), (2, "Minutes"), (1, "Agenda")]: # If minutes or a summary exist for a meeting, don't bother displaying an # agenda (or ask to upload an agenda) for the meeting. if has_doc and doc_type_id == 1: continue # in case there are two documents of the same type, just get the first def first(qs): if qs.count() == 0: raise Document.DoesNotExist() return qs[0] # find the document try: doc = first( Document.objects.filter(anc=anc, doc_type=doc_type_id, meeting_date=mtg)) has_doc = True except Document.DoesNotExist: doc = None # for meetings that aren't behind us, if a summary isn't available # don't bother asking the user to upload one. if not doc and doc_type_id == 14 and mtg >= now: continue # for ANCs that have never had a summary posted, don't ask for one either if not doc and doc_type_id == 14 and not Document.objects.filter( anc=anc, doc_type=doc_type_id).exists(): continue # for meetings that aren't two weeks behind us, if minutes aren't # available, don't bother asking for them because they are almost # certainly not available yet if not doc and doc_type_id == 2 and (now - mtg).days < 14: continue hd_mtg[1].insert(0, (doc_type_id, doc_type_name, doc)) return render( request, self.template_name, { 'anc': anc, 'info': info, 'smds': smds, 'committees': committees, 'documents': recent_documents, 'highlight_documents': highlight_documents, 'census_stats': census_stats, 'next_meeting': next_meeting, })
def get(self, request, anc, *args, **kwargs): # Get the ANC and static metadata from ancs.json. anc = anc.upper() try: info = anc_data[anc[0]]["ancs"][anc[1]] except KeyError: raise Http404() # For each SMD, pull in data from our database. smds = [] for smd in info['smds']: smddict = copy.deepcopy(info['smds'][smd]) smddict.update( CommissionerInfo.get_all(anc, smd) ) smds.append(smddict) smds.sort(key = lambda x : x['smd']) # Get the committees. committees = CommissionerInfo.get(anc, None, 'committees') if committees is not None: committees = re.sub(r"(^|\n)# ", r"\1### ", committees) committees = markdown.markdown(committees) # Find the next meeting and the most recent two meetings so we can # display related documents for those meetings. now = datetime.datetime.now() all_meetings = meeting_data.get(anc, {}).get("meetings", {}) all_meetings = sorted([datetime.datetime.strptime(m, "%Y-%m-%dT%H:%M:%S") for m in all_meetings.keys() if all_meetings[m].get("status") != "invalid" ]) next_meeting = None for m in all_meetings: if m > now: next_meeting = m # this is the first meeting in the future (i.e. the next meeting) break i = all_meetings.index(next_meeting) if next_meeting is not None else len(all_meetings) previous_meetings = all_meetings[i-2:i] prep_hoods(info, True) for smd in info["smds"].values(): prep_hoods(smd, False) census_stats = [ { "key": "P0180002", "label": "families", "details": "A group of two or more related people residing together", "credit": "US Census" }, { "key": "P0180001", "label": "households", "details": "A house, apartment, or room intended as separate living quarters", "credit": "US Census" }, { "key": "P0010001", "label": "residents", "details": "The total population of the ANC", "credit": "US Census" }, { "key": "H0050001_PCT", "label": "vacant homes", "details": "Vacant housing units out of all housing units", "credit": "US Census", "is_percent": True }, { "key": "B07001_001E_PCT", "label": "new residents", "details": "Residents who moved into DC in the last year", "credit": "US Census", "is_percent": True }, { "key": "B01002_001E", "label": "median age", "details": "The median age of all residents in the ANC", "credit": "US Census" }, { "key": "B19019_001E", "label": "median household income", "details": "The median income of households in the ANC", "credit": "US Census", "is_dollars": True }, { "key": "POP_DENSITY", "label": u"density (pop/mi\u00B2)", "details": "Total population divided by the area of the ANC", "credit": "US Census" }, { "key": "liquor_licenses", "label": "liquor licenses", "details": "Liquor licenses granted by ABRA held by bars and restaurants in the area", "credit": "ABRA" }, { "key": "building_permits", "label": "building permits", "details": "Permits granted by DCRA for construction or alteration in the area", "credit": "DCRA" }, { "key": "311_requests", "label": "311 requests", "details": "Requests to the 311 hotline from this area", "credit": "SeeClickFix" }, ] for s in census_stats: try: s["value"] = info["census"][s["key"]]["value"] except KeyError: s["value"] = 0 s["grid"] = census_grids[s["key"]] # recent ANC documents recent_documents = Document.objects.filter(anc=anc).order_by('-created')[0:10] # documents that *should* exist highlight_documents = [] for mtg in previous_meetings + ([next_meeting] if next_meeting else []): hd_mtg = (mtg, []) highlight_documents.append(hd_mtg) has_doc = False for doc_type_id, doc_type_name in [(14, "Summary"), (2, "Minutes"), (1, "Agenda")]: # If minutes or a summary exist for a meeting, don't bother displaying an # agenda (or ask to upload an agenda) for the meeting. if has_doc and doc_type_id == 1: continue # in case there are two documents of the same type, just get the first def first(qs): if qs.count() == 0: raise Document.DoesNotExist() return qs[0] # find the document try: doc = first(Document.objects.filter(anc=anc, doc_type=doc_type_id, meeting_date=mtg)) has_doc = True except Document.DoesNotExist: doc = None # for meetings that aren't behind us, if a summary isn't available # don't bother asking the user to upload one. if not doc and doc_type_id == 14 and mtg >= now: continue # for ANCs that have never had a summary posted, don't ask for one either if not doc and doc_type_id == 14 and not Document.objects.filter(anc=anc, doc_type=doc_type_id).exists(): continue # for meetings that aren't two weeks behind us, if minutes aren't # available, don't bother asking for them because they are almost # certainly not available yet if not doc and doc_type_id == 2 and (now - mtg).days < 14: continue hd_mtg[1].insert(0, (doc_type_id, doc_type_name, doc) ) return render(request, self.template_name, { 'anc': anc, 'info': info, 'smds': smds, 'committees': committees, 'documents': recent_documents, 'highlight_documents': highlight_documents, 'census_stats': census_stats, 'next_meeting': next_meeting, })