# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import json

from django.conf import settings
from django.http import HttpResponse, HttpResponseNotFound
from django.views.generic import TemplateView, View

from redis_cache import get_redis_connection


redis = get_redis_connection('smithers')


class GlowView(TemplateView):
    template_name = 'base.html'


class ShareView(View):
    def post(self, request, *args, **kwargs):
        data = request.POST.dict()
        # place holder. clearly.
        print data
        return HttpResponse()  # 200 ok


class StringsView(TemplateView):
    content_type = 'text/plain'
    template_name = 'strings.html'


class CurrentDataView(View):
    def get(self, request):
        timestamp = int(redis.get(settings.LATEST_TIMESTAMP_KEY) or 0)
        if timestamp:
            response_data = {
                'status': 'OK',
                'timestamp': timestamp,
                'filename': '/static/data/stats_{}.json'.format(timestamp),
            }
            return HttpResponse(json.dumps(response_data),
                                content_type='application/json')

        response_data = {
            'status': 'NOT FOUND',
        }
        return HttpResponseNotFound(json.dumps(response_data),
                                    content_type='application/json')


@@ -204,16 +204,45 @@
 ort json
+%0Afrom urllib import urlencode
 %0A%0Afrom d
@@ -327,16 +327,67 @@
 otFound%0A
+from django.utils.translation import ugettext as _%0A
 from dja
@@ -524,70 +524,974 @@
 ')%0A%0A
-%0Aclass GlowView(TemplateView):%0A    template_name = 'base.html'
+TWITTER_URL = 'https://twitter.com/share'%0AFB_URL = 'https://www.facebook.com/sharer/sharer.php'%0A%0A%0Adef get_tw_share_url(params):%0A    return '?'.join(%5BTWITTER_URL, urlencode(params)%5D)%0A%0A%0Adef get_fb_share_url(params):%0A    return '?'.join(%5BFB_URL, urlencode(params)%5D)%0A%0A%0Aclass GlowView(TemplateView):%0A    template_name = 'base.html'%0A%0A    def get_context_data(self, **kwargs):%0A        context = super(GlowView, self).get_context_data(**kwargs)%0A        context.update(%7B%0A            'share_map_twitter': get_tw_share_url(%7B%0A                'url': 'https://webwewant.mozilla.org/#web',%0A                'hashtags': '#firefox',%0A                'dnt': True,%0A                'text': _('Join millions of Firefox users around the world '%0A                          'who are shaping the future of the Web.'),%0A            %7D),%0A            'share_map_facebook': get_fb_share_url(%7B%0A                'u': 'https://webwewant.mozilla.org/#web'%0A            %7D),%0A        %7D)%0A        return context
 %0A%0A%0Ac

Add map share urls to view context for twitter and FB.