def collecteddata_import(request): """ Import collected data from Tola Tables :param request: :return: """ owner = request.user # get the TolaTables URL and token from the sites object service = TolaSites.objects.get(site_id=1) # add filter to get just the users tables only user_filter_url = service.tola_tables_url + "&owner__username="******"&shared__username="******"POST": id = request.POST["service_table"] filter_url = service.tola_tables_url + "&id=" + id data = get_table(filter_url) # Get Data Info for item in data: name = item["name"] url = item["data"] remote_owner = item["owner"]["username"] # send table ID to count items in data count = getTableCount(url, id) # get the users country countries = getCountry(request.user) check_for_existence = TolaTable.objects.all().filter(name=name, owner=owner) if check_for_existence: result = "error" else: create_table = TolaTable.objects.create( name=name, owner=owner, remote_owner=remote_owner, table_id=id, url=url, unique_count=count ) create_table.country.add(countries[0].id) create_table.save() result = "success" # send result back as json message = result return HttpResponse(json.dumps(message), content_type="application/json") # send the keys and vars from the json data to the template along with submitted feed info and silos for new form return render(request, "indicators/collecteddata_import.html", {"getTables": data})
def getTableCount(url, table_id): """ Count the number of rowns in a TolaTable :param table_id: The TolaTable ID to update count from and return :return: count : count of rows from TolaTable """ filter_url = url # loop over the result table and count the number of records for actuals actual_data = get_table(filter_url) count = 0 if actual_data: # check if json data is in the 'data' attribute or at the top level of the JSON object try: looper = actual_data['data'] except KeyError: looper = actual_data for item in looper: count = count + 1 # update with new count TolaTable.objects.filter(table_id=table_id).update(unique_count=count) return count
def getTableCount(url, table_id): """ Count the number of rowns in a TolaTable :param table_id: The TolaTable ID to update count from and return :return: count : count of rows from TolaTable """ filter_url = url # loop over the result table and count the number of records for actuals actual_data = get_table(filter_url) count = 0 if actual_data: # check if json data is in the 'data' attribute or at the top level of the JSON object try: looper = actual_data["data"] except KeyError: looper = actual_data for item in looper: count = count + 1 # update with new count TolaTable.objects.filter(table_id=table_id).update(unique_count=count) return count
def getTableCount(table_id): """ Count the number of rowns in a TolaTable :param table_id: The TolaTable ID to update count from and return :return: count : count of rows from TolaTable """ service = ExternalService.objects.get(name="TolaTables") filter_url = service.feed_url + "&id=" + table_id # loop over the result table and count the number of records for actuals actual_data = get_table(filter_url, count=True) count = 0 if actual_data: for item in actual_data: count = count + 1 # update with new count TolaTable.objects.filter(table_id=table_id).update(unique_count=count) return count
def getTableCount(table_id): """ Count the number of rowns in a TolaTable :param table_id: The TolaTable ID to update count from and return :return: count : count of rows from TolaTable """ service = ExternalService.objects.get(name="TolaTables") filter_url = service.feed_url + "&id=" + table_id # loop over the result table and count the number of records for actuals actual_data = get_table(filter_url,count=True) count = 0 if actual_data: for item in actual_data: count = count + 1 # update with new count TolaTable.objects.filter(table_id = table_id).update(unique_count=count) return count
def collecteddata_import(request): """ Import collected data from Tola Tables :param request: :return: """ owner = request.user #get the TolaTables URL and token from the sites object service = TolaSites.objects.get(site_id=1) # add filter to get just the users tables only user_filter_url = service.tola_tables_url + "&owner__username="******"&shared__username="******"&id=" + id data = get_table(filter_url) # Get Data Info for item in data: name = item['name'] url = item['data'] remote_owner = item['owner']['username'] #send table ID to count items in data count = getTableCount(url, id) # get the users country countries = getCountry(request.user) check_for_existence = TolaTable.objects.all().filter(name=name, owner=owner) if check_for_existence: result = check_for_existence[0].id else: create_table = TolaTable.objects.create(name=name, owner=owner, remote_owner=remote_owner, table_id=id, url=url, unique_count=count) create_table.country.add(countries[0].id) create_table.save() result = create_table.id # send result back as json message = result return HttpResponse(json.dumps(message), content_type='application/json') # send the keys and vars from the json data to the template along with submitted feed info and silos for new form return render(request, "indicators/collecteddata_import.html", {'getTables': data})
def PublicDashboard(request, id=0, public=0): """ This is used as the internal and external (public) dashboard view the template is changed for public :public: if URL contains a 0 then show the internal dashboard if 1 then public dashboard http://127.0.0.1:8000/customdashboard/program_dashboard/65/0/ """ program_id = id getQuantitativeDataSums_2 = CollectedData.objects.all().filter( indicator__program__id=program_id, achieved__isnull=False).order_by('indicator__source').values( 'indicator__number', 'indicator__source', 'indicator__id') getQuantitativeDataSums = CollectedData.objects.all().filter( indicator__program__id=program_id, achieved__isnull=False).exclude( achieved=None, targeted=None).order_by('indicator__number').values( 'indicator__number', 'indicator__name', 'indicator__id').annotate(targets=Sum('targeted'), actuals=Sum('achieved')) getIndicatorCount = Indicator.objects.all().filter( program__id=program_id).count() getIndicatorData = CollectedData.objects.all().filter( indicator__program__id=program_id, achieved__isnull=False).order_by('date_collected') getIndicatorCountData = getIndicatorData.count() getIndicatorCountKPI = Indicator.objects.all().filter( program__id=program_id, key_performance_indicator=1).count() getProgram = Program.objects.all().get(id=program_id) try: getProgramNarrative = ProgramNarratives.objects.get( program_id=program_id) except ProgramNarratives.DoesNotExist: getProgramNarrative = None getProjects = ProjectComplete.objects.all().filter(program_id=program_id) getAllProjects = ProjectAgreement.objects.all().filter( program_id=program_id) getSiteProfile = SiteProfile.objects.all().filter( projectagreement__program__id=program_id) getSiteProfileIndicator = SiteProfile.objects.all().filter( Q(collecteddata__program__id=program_id)) getProjectsCount = ProjectAgreement.objects.all().filter( program__id=program_id).count() getAwaitingApprovalCount = ProjectAgreement.objects.all().filter( program__id=program_id, approval='awaiting approval').count() getApprovedCount = ProjectAgreement.objects.all().filter( program__id=program_id, approval='approved').count() getRejectedCount = ProjectAgreement.objects.all().filter( program__id=program_id, approval='rejected').count() getInProgressCount = ProjectAgreement.objects.all().filter( Q(program__id=program_id) & Q(Q(approval='in progress') | Q(approval=None) | Q(approval=""))).count() nostatus_count = ProjectAgreement.objects.all().filter( Q(program__id=program_id) & Q(Q(approval=None) | Q(approval=""))).count() getNotebooks = JupyterNotebooks.objects.all().filter( program__id=program_id) # get all countires countries = Country.objects.all().filter(program__id=program_id) # Trainings agreement_id_list = [] training_id_list = [] # Indicator Evidence getEvidence = TolaTable.objects.all().filter(country__in=countries) evidence_tables_count = getEvidence.count() evidence_tables = [] try: for table in getEvidence: table.table_data = get_table(table.url) print table.table_data evidence_tables.append(table) except Exception, e: pass
def collecteddata_import(request): """ Import collected data from Tola Tables :param request: :return: """ owner = request.user service = ExternalService.objects.get(name="TolaTables") # add filter to get just the users tables only user_filter_url = service.feed_url + "&owner__username="******"&shared__username="******"Token Not Found" response = requests.get(user_filter_url, headers=headers, verify=False) response2 = requests.get(shared_filter_url, headers=headers, verify=False) user_json = json.loads(response.content) shared_json = json.loads(response2.content) if type(shared_json) is not dict: data = user_json + shared_json else: data = user_json # debug the json data string uncomment dump and print # data2 = json.dumps(data) # json formatted string # print data2 if request.method == 'POST': id = request.POST['service_table'] filter_url = service.feed_url + "&id=" + id token = TolaSites.objects.get(site_id=1) if token.tola_tables_token: headers = { 'content-type': 'application/json', 'Authorization': 'Token ' + token.tola_tables_token } else: headers = {'content-type': 'application/json'} print "Token Not Found" response = requests.get(filter_url, headers=headers, verify=False) get_json = json.loads(response.content) data = get_json # Get Data Info for item in data: name = item['name'] url = item['data'] remote_owner = item['owner']['username'] # loop over the result table and count the number of records for actuals actual_data = get_table(item['data']) count = 0 for item in actual_data: count = count + 1 # get the users country countries = getCountry(request.user) check_for_existence = TolaTable.objects.all().filter(name=name, owner=owner) if check_for_existence: result = "error" else: create_table = TolaTable.objects.create(name=name, owner=owner, remote_owner=remote_owner, table_id=id, url=url, unique_count=count) create_table.country.add(countries[0].id) create_table.save() result = "success" # send result back as json message = result return HttpResponse(json.dumps(message), content_type='application/json') # send the keys and vars from the json data to the template along with submitted feed info and silos for new form return render(request, "indicators/collecteddata_import.html", {'getTables': data})
def collecteddata_import(request): """ Import collected data from Tola Tables :param request: :return: """ owner = request.user service = ExternalService.objects.get(name="TolaTables") # add filter to get just the users tables only user_filter_url = service.feed_url + "&owner__username="******"&shared__username="******"Token Not Found" response = requests.get(user_filter_url, headers=headers, verify=False) response2 = requests.get(shared_filter_url, headers=headers, verify=False) user_json = json.loads(response.content) shared_json = json.loads(response2.content) if type(shared_json) is not dict: data = user_json + shared_json else: data = user_json # debug the json data string uncomment dump and print # data2 = json.dumps(data) # json formatted string # print data2 if request.method == 'POST': id = request.POST['service_table'] filter_url = service.feed_url + "&id=" + id token = TolaSites.objects.get(site_id=1) if token.tola_tables_token: headers = {'content-type': 'application/json', 'Authorization': 'Token ' + token.tola_tables_token} else: headers = {'content-type': 'application/json'} print "Token Not Found" response = requests.get(filter_url, headers=headers, verify=False) get_json = json.loads(response.content) data = get_json # Get Data Info for item in data: name = item['name'] url = item['data'] remote_owner = item['owner']['username'] # loop over the result table and count the number of records for actuals actual_data = get_table(item['data']) count = 0 for item in actual_data: count = count +1 # get the users country countries = getCountry(request.user) check_for_existence = TolaTable.objects.all().filter(name=name,owner=owner) if check_for_existence: result = "error" else: create_table = TolaTable.objects.create(name=name,owner=owner,remote_owner=remote_owner,table_id=id,url=url, unique_count=count) create_table.country.add(countries[0].id) create_table.save() result = "success" # send result back as json message = result return HttpResponse(json.dumps(message), content_type='application/json') # send the keys and vars from the json data to the template along with submitted feed info and silos for new form return render(request, "indicators/collecteddata_import.html", {'getTables': data})