def get_current_members(role_type, delegates, by_party): qs = PersonRole.objects.filter( role_type=role_type, current=True, state__in=set(s for s, t in stateapportionment.items() if (t != "T") ^ delegates) ) if by_party: return qs.values('party').annotate(count=Count('party')).order_by('-count') else: return qs.count()
def handle(self, *args, **options): try: os.mkdir("static/images/cd") except: pass for state, app in sorted(stateapportionment.items()): if app in ("T", 1): self.fetch_static_map(state, 0) else: self.fetch_static_map(state, 0) for cd in range(1, app+1): self.fetch_static_map(state, cd)
#!script from us import stateapportionment from person.views import get_district_bounds_query db = {} for state in stateapportionment: db[(state, None)] = get_district_bounds(state, None) print state, db[(state, None)] for state, numdists in stateapportionment.items(): if numdists in (1, "T"): continue for dist in range(1, numdists + 1): db[(state, dist)] = get_district_bounds(state, dist) print state, dist, db[(state, dist)] import json with open("person/district_bounds.json", "w") as f: f.write( json.dumps(dict( (("%s:%d" % k) if k[1] else k[0], "|".join(str(c) for c in v)) for k, v in db.items()), indent=True, sort_keys=True))
#!script from us import stateapportionment from person.views import get_district_bounds_query db = {} for state in stateapportionment: db[(state,None)] = get_district_bounds(state, None) print state, db[(state,None)] for state, numdists in stateapportionment.items(): if numdists in (1, "T"): continue for dist in range(1, numdists+1): db[(state,dist)] = get_district_bounds(state, dist) print state, dist, db[(state,dist)] import json with open("person/district_bounds.json", "w") as f: f.write(json.dumps(dict( (("%s:%d" % k) if k[1] else k[0], "|".join(str(c) for c in v)) for k,v in db.items() ), indent=True, sort_keys=True))