# Path: rtei/data.py
# def get_json_file(path, ordered_dict=True):
# def get_file_path(file_name, year=''):
# def get_indicators(year):
# def get_themes(year):
# def get_countries():
# def get_scores_per_country(year):
# def get_c3_scores_per_country(year):
# def get_indicators_for_country(country_code, year):
# def get_countries_with_data():
# def get_country_name(country_code):
# 
# Path: rtei/forms.py
# class ContactForm(forms.Form):
#     contact_name = forms.CharField(
#         label=_('Name'), max_length=100,
#         widget=forms.TextInput(attrs={'class': "short"}))
#     contact_email = forms.EmailField(
#         label=_('Email'), widget=forms.TextInput(attrs={'class': "short"}))
#     contact_affiliation = forms.CharField(
#         label=_('Affiliation'), max_length=256,
#         widget=forms.TextInput(attrs={'class': "short"}))
# 
#     def save(self):
#         message = '''A user has submitted the contact form with the following details:
# 
# Name: {0}
# Email: {1}
# Affiliation: {2}'''.format(self.cleaned_data['contact_name'],
#                            self.cleaned_data['contact_email'],
#                            self.cleaned_data['contact_affiliation'])
# 
#         send_mail('[RTEI] New Contact', message, 'no-reply@results.org',
#                   [settings.RTEI_CONTACT_FORM_EMAIL], fail_silently=False)


import sys
import json
import logging
from collections import OrderedDict
from smtplib import SMTPException
from django.db import models
from django.http import Http404
from django.utils.translation import ugettext as _
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.validators import RegexValidator, URLValidator
from django.shortcuts import redirect
from django.contrib import messages
from django.conf import settings
from wagtail.core.models import Page, get_root_collection_id
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.documents.models import AbstractDocument
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index
from modelcluster.fields import ParentalKey
from modelcluster.tags import ClusterTaggableManager
from taggit.models import TaggedItemBase
from rtei import data
from rtei.forms import ContactForm
    def get_context(self, request):
        context = super(ResourceIndexPage, self).get_context(request)
        # Get all resource documents as a queryset
        resources = self.resources()

        # Get data to populate filter dropdowns from resources.
        context['years'] = self.years(resources)
        context['countries'] = self.countries(resources)
        context['collections'] = self.collections(resources)

        # Get the resource documents to display
        resources_to_display = resources.order_by('-created_at')

        # Filter resources to display as necessary.
        has_filter = False
        for filter_name in ['year', 'country', 'collection']:
            filter_value = request.GET.get(filter_name)
            if filter_value:
                if filter_value != "all":
                    kwargs = {'{0}'.format(filter_name): filter_value}
                    resources_to_display = resources_to_display.filter(
                        **kwargs)
                has_filter = True

        page = request.GET.get('page')
        paginator = Paginator(resources_to_display, 10)
        try:
            resources_to_display = paginator.page(page)
        except PageNotAnInteger:
            resources_to_display = paginator.page(1)

# Path: rtei/data.py
# def get_json_file(path, ordered_dict=True):
# def get_file_path(file_name, year=''):
# def get_indicators(year):
# def get_themes(year):
# def get_countries():
# def get_scores_per_country(year):
# def get_c3_scores_per_country(year):
# def get_indicators_for_country(country_code, year):
# def get_countries_with_data():
# def get_country_name(country_code):
# 
# Path: rtei/forms.py
# class ContactForm(forms.Form):
#     contact_name = forms.CharField(
#         label=_('Name'), max_length=100,
#         widget=forms.TextInput(attrs={'class': "short"}))
#     contact_email = forms.EmailField(
#         label=_('Email'), widget=forms.TextInput(attrs={'class': "short"}))
#     contact_affiliation = forms.CharField(
#         label=_('Affiliation'), max_length=256,
#         widget=forms.TextInput(attrs={'class': "short"}))
# 
#     def save(self):
#         message = '''A user has submitted the contact form with the following details:
# 
# Name: {0}
# Email: {1}
# Affiliation: {2}'''.format(self.cleaned_data['contact_name'],
#                            self.cleaned_data['contact_email'],
#                            self.cleaned_data['contact_affiliation'])
# 
#         send_mail('[RTEI] New Contact', message, 'no-reply@results.org',
#                   [settings.RTEI_CONTACT_FORM_EMAIL], fail_silently=False)


# Path: rtei/models.py
import sys
import json
import logging
from collections import OrderedDict
from smtplib import SMTPException
from django.db import models
from django.http import Http404
from django.utils.translation import ugettext as _
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.validators import RegexValidator, URLValidator
from django.shortcuts import redirect
from django.contrib import messages
from django.conf import settings
from wagtail.core.models import Page, get_root_collection_id
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.documents.models import AbstractDocument
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.search import index
from modelcluster.fields import ParentalKey
from modelcluster.tags import ClusterTaggableManager
from taggit.models import TaggedItemBase
from rtei import data
from rtei.forms import ContactForm

    def get_context(self, request):
        context = super(ResourceIndexPage, self).get_context(request)
        # Get all resource documents as a queryset
        resources = self.resources()

        # Get data to populate filter dropdowns from resources.
        context['years'] = self.years(resources)
        context['countries'] = self.countries(resources)
        context['collections'] = self.collections(resources)

        # Get the resource documents to display
        resources_to_display = resources.order_by('-created_at')

        # Filter resources to display as necessary.
        has_filter = False
        for filter_name in ['year', 'country', 'collection']:
            filter_value = request.GET.get(filter_name)
            if filter_value:
                if filter_value != "all":
                    kwargs = {'{0}'.format(filter_name): filter_value}
                    resources_to_display = resources_to_display.filter(
                        **kwargs)
                has_filter = True

        page = request.GET.get('page')
        paginator = Paginator(resources_to_display, 10)
        try:
            resources_to_display = paginator.page(page)
        except PageNotAnInteger:
            resources_to_display = paginator.page(1)

        except EmptyPage: