<commit_before># -*- coding: utf-8 -*-
"""
    Akvo RSR is covered by the GNU Affero General Public License.
    See more details in the license.txt file located at the root folder of the
    Akvo RSR module. For additional details on the GNU license please
    see < http://www.gnu.org/licenses/agpl.html >.
"""
from __future__ import absolute_import

import json

from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse

from akvo.rsr.views_partner_sites.base import BaseView
from akvo.rsr.models import Organisation, Project


__all__ = [
    'GetWidgetView',
    'ProjectMapView',
    'ProjectCordinates',
    ]


class GetWidgetView(BaseView):
    template_name = 'partner_sites/widgets/get_widget1.html'

    def post(self, request, *args, **kwargs):
        self.template_name = 'partner_sites/widgets/get_widget2.html'
        context = dict(self.get_context_data().items()
                       + self.get_post_context().items())
        return self.render_to_response(context)

    def get_post_context(self):
        widget_type = self.request.POST.get('widget-type', '')
        project = get_object_or_404(Project, pk=self.kwargs['project_id'])
        return {
            'widget_type': widget_type,
            'project': project,
        }


class ProjectMapView(TemplateView):
    template_name = 'partner_sites/widgets/projects_map.html'

    def get_context_data(self, **kwargs):
        context = super(ProjectMapView, self).get_context_data(**kwargs)
        if getattr(settings, 'HTTPS_SUPPORT', True):
            protocol = 'https://'
        else:
            protocol = 'http://'

        context['app_url'] = '%s%s.%s' % (protocol, self.request.partner_site.hostname,
                                          settings.APP_DOMAIN_NAME)
        context['domain_url'] = '%s%s' % (protocol, settings.DOMAIN_NAME)
        context['height'] = self.request.GET.get('height', '300')
        context['width'] = self.request.GET.get('width', '600')
        context['bgcolor'] = self.request.GET.get('bgcolor', 'B50000')
        context['state'] = self.request.GET.get('state', 'dynamic')
        context['organisation'] = get_object_or_404(Organisation, pk=self.request.organisation_id)
        return context


class ProjectCordinates(TemplateView):

    def get_queryset(self):
        projects = get_object_or_404(Organisation, pk=self.request.organisation_id) \
            .published_projects().latest_update_fields().order_by('-id')
        return projects

    def render_to_response(self, context, **kwargs):
        return HttpResponse(context, content_type='application/json', **kwargs)

    def get_context_data(self, **kwargs):
        if getattr(settings, 'HTTPS_SUPPORT', True):<commit_msg>Removed redundant re-definition of app_ and domain_url from akvo.rsr.views_partner_sites.widgets.<commit_after># -*- coding: utf-8 -*-
"""
    Akvo RSR is covered by the GNU Affero General Public License.
    See more details in the license.txt file located at the root folder of the
    Akvo RSR module. For additional details on the GNU license please
    see < http://www.gnu.org/licenses/agpl.html >.
"""
from __future__ import absolute_import

import json

from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.views.generic import TemplateView
from django.core.urlresolvers import reverse

from akvo.rsr.views_partner_sites.base import BaseView
from akvo.rsr.models import Organisation, Project


__all__ = [
    'GetWidgetView',
    'ProjectMapView',
    'ProjectCordinates',
    ]


class GetWidgetView(BaseView):
    template_name = 'partner_sites/widgets/get_widget1.html'

    def post(self, request, *args, **kwargs):
        self.template_name = 'partner_sites/widgets/get_widget2.html'
        context = dict(self.get_context_data().items()
                       + self.get_post_context().items())
        return self.render_to_response(context)

    def get_post_context(self):
        widget_type = self.request.POST.get('widget-type', '')
        project = get_object_or_404(Project, pk=self.kwargs['project_id'])
        return {
            'widget_type': widget_type,
            'project': project,
        }


class ProjectMapView(TemplateView):
    template_name = 'partner_sites/widgets/projects_map.html'

    def get_context_data(self, **kwargs):
        context = super(ProjectMapView, self).get_context_data(**kwargs)
        context['height'] = self.request.GET.get('height', '300')
        context['width'] = self.request.GET.get('width', '600')
        context['bgcolor'] = self.request.GET.get('bgcolor', 'B50000')
        context['state'] = self.request.GET.get('state', 'dynamic')
        context['organisation'] = get_object_or_404(Organisation, pk=self.request.organisation_id)
        return context


class ProjectCordinates(TemplateView):

    def get_queryset(self):
        projects = get_object_or_404(Organisation, pk=self.request.organisation_id) \
            .published_projects().latest_update_fields().order_by('-id')
        return projects

    def render_to_response(self, context, **kwargs):
        return HttpResponse(context, content_type='application/json', **kwargs)

    def get_context_data(self, **kwargs):
        if getattr(settings, 'HTTPS_SUPPORT', True):
{'fraction_non_alphanumeric': 0.11570096874428806, 'fraction_numerical': 0.009504660939499178, 'mean_word_length': 3.45240032546786, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5756657', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1596, 'n_words': 345}