<commit_before>from django.db import transaction
from django.db.models import Q
from django.views.decorators.http import require_GET, require_POST
from django.template import RequestContext
from django.shortcuts import redirect, get_object_or_404, render_to_response
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.contrib.sites.models import Site
from rapidsms_httprouter.router import get_router
from rapidsms.messages.outgoing import OutgoingMessage
from django.contrib.auth.models import Group
from .models import Poll, Category, Rule, Response, ResponseCategory, STARTSWITH_PATTERN_TEMPLATE, CONTAINS_PATTERN_TEMPLATE
from rapidsms.models import Contact
from simple_locations.models import Area
from rapidsms.models import Connection, Backend

from .forms import *

# CSV Export
@require_GET
def responses_as_csv(req, pk):
    poll = get_object_or_404(Poll, pk=pk)

    responses = poll.responses.all().order_by('-pk')

    resp = render_to_response(
        "polls/responses.csv", 
        {'responses': responses},
        mimetype="text/csv",
        context_instance=RequestContext(req))
    resp['Content-Disposition'] = 'attachment;filename="%s.csv"' % poll.name
    return resp

@require_GET
def polls(req): 
    polls = Poll.objects.order_by('start_date')
    breadcrumbs = (('Polls', ''),)
    return render_to_response(
        "polls/poll_index.html", 
        { 'polls': polls, 'breadcrumbs': breadcrumbs },
        context_instance=RequestContext(req))

def demo(req, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    b1, created = Backend.objects.get_or_create(name="dmark")
    c1, created = Connection.objects.get_or_create(identity="256785137868", defaults={
        'backend':b1,
    })
    b2, created = Backend.objects.get_or_create(name="utl")
    c2, created = Connection.objects.get_or_create(identity="256717171100", defaults={
        'backend':b2,
    })    
    router = get_router()
    outgoing = OutgoingMessage(c1, "dear Iganga representative: uReport, Uganda's community-level monitoring system, found that 60%% of young reporters in your district DO NOT have soap or water at their school.")
    router.handle_outgoing(outgoing)
    outgoing = OutgoingMessage(c2, "dear Amuru representative: uReport, Uganda's community-level monitoring system, found that 38.9%% of young reporters in your district DO NOT have soap or water at their school.")
    router.handle_outgoing(outgoing)<commit_msg>scaled images<commit_after>from django.db import transaction
from django.db.models import Q
from django.views.decorators.http import require_GET, require_POST
from django.template import RequestContext
from django.shortcuts import redirect, get_object_or_404, render_to_response
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.contrib.sites.models import Site
from rapidsms_httprouter.router import get_router
from rapidsms.messages.outgoing import OutgoingMessage
from django.contrib.auth.models import Group
from .models import Poll, Category, Rule, Response, ResponseCategory, STARTSWITH_PATTERN_TEMPLATE, CONTAINS_PATTERN_TEMPLATE
from rapidsms.models import Contact
from simple_locations.models import Area
from rapidsms.models import Connection, Backend

from .forms import *

# CSV Export
@require_GET
def responses_as_csv(req, pk):
    poll = get_object_or_404(Poll, pk=pk)

    responses = poll.responses.all().order_by('-pk')

    resp = render_to_response(
        "polls/responses.csv", 
        {'responses': responses},
        mimetype="text/csv",
        context_instance=RequestContext(req))
    resp['Content-Disposition'] = 'attachment;filename="%s.csv"' % poll.name
    return resp

@require_GET
def polls(req): 
    polls = Poll.objects.order_by('start_date')
    breadcrumbs = (('Polls', ''),)
    return render_to_response(
        "polls/poll_index.html", 
        { 'polls': polls, 'breadcrumbs': breadcrumbs },
        context_instance=RequestContext(req))

def demo(req, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    b1, created = Backend.objects.get_or_create(name="dmark")
    # Terra
    c1, created = Connection.objects.get_or_create(identity="256785137868", defaults={
        'backend':b1,
    })
    # Sharad
    b2, created = Backend.objects.get_or_create(name="utl")
    c2, created = Connection.objects.get_or_create(identity="256717171100", defaults={
        'backend':b2,
    })    
    router = get_router()
    outgoing = OutgoingMessage(c1, "dear Bulambuli representative: uReport, Uganda's community-level monitoring system, shows that 75% of young reporters in your district found that their local water point IS NOT functioning.")
    router.handle_outgoing(outgoing)
    outgoing = OutgoingMessage(c2, "dear Amuru representative: uReport, Uganda's community-level monitoring system, shows that 46.7% of young reporters in your district found that their local water point IS NOT functioning.")
    router.handle_outgoing(outgoing)
{'fraction_non_alphanumeric': 0.09479044261652958, 'fraction_numerical': 0.018018018018018018, 'mean_word_length': 4.725336322869955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2916529', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1526, 'n_words': 396}