Beispiel #1
0
def mps(request, group_by, type, extraction_date, openparlamento_url):
  if group_by == 'constituency':
    json_endpoint = "json_getIndexChartsRegions"
  elif group_by == 'group':
    json_endpoint = "json_getIndexChartsGroups"
  elif group_by == 'sex':
    json_endpoint = "json_getIndexChartsSex"
  else :
    json_endpoint = "json_getIndexChartsPoliticians"

  if  type=='deputati':
    tree = 'C'
  else:
    tree = 'S'
    
  last_date = datetime.strftime(extraction_date, "%Y-%m-%d")
  json_url = "%s/%s?ramo=%s&data=%s" % (openparlamento_url, json_endpoint, tree, last_date)
  
  import sys
  print >> sys.stderr, "json url: %s" % json_url
  
  records = get_json_data(json_url)
  
  return render_to_response("parlamentari_%s.html" % group_by, 
    { 
      'object_list': records, 
      'objects_count': len(records), 
      'type': type, 
      'extraction_date': extraction_date, 
      'openparlamento_url': openparlamento_url,
    },
    context_instance=RequestContext(request)
  )
Beispiel #2
0
 def render(self, context):
   try:
     actual_extraction_date = self.extraction_date.resolve(context)    
     last_date = datetime.strftime(actual_extraction_date, "%Y-%m-%d")
     json_endpoint = "json_getIndexChartsTopPoliticians"
     json_url = "%s/%s?ramo=%s&data=%s&limit=%s" % (settings.OPENPARLAMENTO_URL, json_endpoint, self.tree, last_date, self.num)
     
     context[self.varname] = get_json_data(json_url)
     return ''
   except template.VariableDoesNotExist:
     return ''
Beispiel #3
0
  def render(self, context):
    try:
      actual_extraction_date = self.extraction_date.resolve(context)    
      actual_constituency = self.constituency.resolve(context)

      last_date = datetime.strftime(actual_extraction_date, "%Y-%m-%d")
      json_endpoint = "json_getIndexChartsPoliticiansInConstituency"
      json_url = "%s/%s?ramo=%s&data=%s&circoscrizione=%s" % (settings.OPENPARLAMENTO_URL, json_endpoint, self.tree, last_date, urllib2.quote(actual_constituency))
      context[self.varname] = get_json_data(json_url)
      return ''
    except template.VariableDoesNotExist:
      return ''
Beispiel #4
0
from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template
from django.conf import settings
from django.utils import translation
from datetime import datetime
from json_proxy import get_json_data

last_date_data = get_json_data("%s/json_getLastDateForPoliticianHistoryCache" % settings.OPENPARLAMENTO_URL)
extraction_date = datetime.strptime(last_date_data["last_date"], "%Y-%m-%d")

from django.contrib import admin

admin.autodiscover()

# extract last date for politician_history cached data from opp
# TODO: move to a proper location (proxy json request handler)

urlpatterns = patterns(
    "",
    (r"^admin/", include(admin.site.urls)),
    # home page
    (
        r"^$",
        "charts.views.home",
        {
            "openparlamento_url": settings.OPENPARLAMENTO_URL,
            "extraction_date": extraction_date,
            "fetch_s3_images": settings.FETCH_S3_IMAGES,
        },
    ),
    # info page