# 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
                          'details.'))
                    log.error('Internal Server Error: %s', request.path,
                              exc_info=sys.exc_info(),
                              extra={
                                'status_code': 500,
                                'request': request
                              })
                else:
                    messages.success(
                        request,
                        _("Your contact details have been submitted."))
                redirect(self.url)

        return super(RTEIAncillaryPage, self).serve(request)

    def get_template(self, request, *args, **kwargs):
        if self.slug == 'contact-us':
            return "rtei/contact_us.html"
        elif self.get_parent().slug == 'partners':
            return "rtei/partners.html"
        else:
            return "rtei/about.html"


class ResourceIndexPage(Page):
    template = 'rtei/resources.html'

    def resources(self):
        '''Return a queryset of resource documents, filtered based on query
        string args in the passed request.'''

# 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

                          'details.'))
                    log.error('Internal Server Error: %s', request.path,
                              exc_info=sys.exc_info(),
                              extra={
                                'status_code': 500,
                                'request': request
                              })
                else:
                    messages.success(
                        request,
                        _("Your contact details have been submitted."))
                redirect(self.url)

        return super(RTEIAncillaryPage, self).serve(request)

    def get_template(self, request, *args, **kwargs):
        if self.slug == 'contact-us':
            return "rtei/contact_us.html"
        elif self.get_parent().slug == 'partners':
            return "rtei/partners.html"
        else:
            return "rtei/about.html"


class ResourceIndexPage(Page):
    template = 'rtei/resources.html'

    def resources(self):
        '''Return a queryset of resource documents, filtered based on query
        string args in the passed request.'''

        resources = RteiDocument.objects.filter(is_resource=True)