<commit_before>import datetime
#import simplejson as json
from django.utils import simplejson as json


from django.db.models.query_utils import Q
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.http import HttpResponseRedirect, Http404
from django.core.exceptions import *

from domain.decorators import login_and_domain_required
from rapidsms.webui.utils import render_to_response, paginated
from facilities.models import Facility
from maps.utils import encode_myway
from maps.forms import FilterChoiceForm
from resources.models import Resource

@login_and_domain_required
def index(req):
    facilities = Facility.objects.all().order_by('name')
    if req.method == 'POST': # If the form has been submitted...
        form = FilterChoiceForm(req.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # saving the form data is not cleaned
            #form.save()
            start_date = form.cleaned_data["start_date"]
            end_date = form.cleaned_data['end_date']
            status = form.cleaned_data['resource_status']
            
            resources = Resource.objects.filter(facility__in = facilities)
            resources = resources.filter(status__in = status)
            
            facilities = []
            for resource in resources:
                facilities.append(resource.facility)
            
            print 'START: %s -------------- END: %s ---------- STATUS: %s' % (start_date, end_date, status)
            #return HttpResponse('You just submit a form..Horray!')
    else:
        form = FilterChoiceForm() # An unbound form

    return render_to_response(req, 
                              'mapindex.html',
                              {
                               'facilities': facilities,
                               'form': form,
                               },                              
                              )

@login_and_domain_required
def map_resource(req,pk):
    resource = get_object_or_404(Resource, pk=pk)
    if resource:
        # get a coordinate for the resource
        # currently depends on the assigned facility
        # TODO: allow resource to have independent coordinates <commit_msg>removed print wich cause a IOError due cause sys.stdout access restricted by mod_wsgi the print was just used to debugging.<commit_after>import datetime
#import simplejson as json
from django.utils import simplejson as json


from django.db.models.query_utils import Q
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.http import HttpResponseRedirect, Http404
from django.core.exceptions import *

from domain.decorators import login_and_domain_required
from rapidsms.webui.utils import render_to_response, paginated
from facilities.models import Facility
from maps.utils import encode_myway
from maps.forms import FilterChoiceForm
from resources.models import Resource

@login_and_domain_required
def index(req):
    facilities = Facility.objects.all().order_by('name')
    if req.method == 'POST': # If the form has been submitted...
        form = FilterChoiceForm(req.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # saving the form data is not cleaned
            #form.save()
            start_date = form.cleaned_data["start_date"]
            end_date = form.cleaned_data['end_date']
            status = form.cleaned_data['resource_status']
            
            resources = Resource.objects.filter(facility__in = facilities)
            resources = resources.filter(status__in = status)
            
            facilities = []
            for resource in resources:
                facilities.append(resource.facility)
            
    else:
        form = FilterChoiceForm() # An unbound form

    return render_to_response(req, 
                              'mapindex.html',
                              {
                               'facilities': facilities,
                               'form': form,
                               },                              
                              )

@login_and_domain_required
def map_resource(req,pk):
    resource = get_object_or_404(Resource, pk=pk)
    if resource:
        # get a coordinate for the resource
        # currently depends on the assigned facility
        # TODO: allow resource to have independent coordinates 
{'fraction_non_alphanumeric': 0.07078699743370402, 'fraction_numerical': 0.003849443969204448, 'mean_word_length': 2.2188575361321403, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4074238', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1137, 'n_words': 355}