Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. pees = PostExtraElection.objects.filter(election__slug__in=['local.aberdeen-city.2017-05-04', 'local.aberdeenshire.2017-05-04', 'local.orkney-islands.2017-05-04', 'local.argyll-and-bute.2017-05-04', 'local.angus.2017-05-04', 'local.eilean-siar.2017-05-04', 'local.city-of-edinburgh.2017-05-04', 'local.clackmannanshire.2017-05-04', 'local.dundee-city.2017-05-04', 'local.east-renfrewshire.2017-05-04', 'local.east-lothian.2017-05-04', 'local.glasgow-city.2017-05-04', 'local.dumfries-and-galloway.2017-05-04', 'local.inverclyde.2017-05-04', 'local.east-ayrshire.2017-05-04', 'local.east-dunbartonshire.2017-05-04', 'local.south-ayrshire.2017-05-04', 'local.falkirk.2017-05-04', 'local.fife.2017-05-04', 'local.midlothian.2017-05-04', 'local.the-scottish-borders.2017-05-04', 'local.south-lanarkshire.2017-05-04', 'local.stirling.2017-05-04', 'local.highland.2017-05-04', 'local.moray.2017-05-04', 'local.west-dunbartonshire.2017-05-04', 'local.west-lothian.2017-05-04', 'local.north-ayrshire.2017-05-04', 'local.north-lanarkshire.2017-05-04', 'local.perth-and-kinross.2017-05-04', 'local.renfrewshire.2017-05-04', 'local.shetland-islands.2017-05-04'])
  2. pes = PostExtra.objects.filter(elections__in=[p.election for p in pees])
  3. [(p.slug, p.elections.count()) for p in pes if p.elections.count() > 1]
  4. # [(u'UTW:S13002650', 2)]
  5.  
  6. p = PostExtra.objects.get(slug="UTW:S13002650")
  7. [e.slug for e in p.elections.all()]
  8. # [u'local.glasgow-city.2017-05-04', u'local.glasgow.anderston-city.2016-05-05']
  9.  
  10. lines = []
  11. for pe in pes:
  12. election = pe.elections.get(election_date="2017-05-04").slug
  13. for membership in pe.base.memberships.all():
  14. lines.append([election, pe.base.label, membership.person.name, membership.person.extra.get_absolute_url()])
  15.  
  16. import csv
  17. import sys
  18. out = csv.writer(sys.stdout)
  19. for line in lines:
  20. out.writerow(line)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement