def get(self, request, *args, **kwargs): program_id = int(self.kwargs['program']) project_id = int(self.kwargs['project']) countries = get_country(request.user) if program_id == 0: get_distribution = Distribution.objects.all().filter( program__country__in=countries).values('id', 'distribution_name', 'create_date', 'program') elif program_id != 0 and project_id == 0: get_distribution = Distribution.objects.all().filter( program_id=program_id).values('id', 'distribution_name', 'create_date', 'program') else: get_distribution = Distribution.objects.all().filter( program_id=program_id, initiation_id=project_id).values('id', 'distribution_name', 'create_date', 'program') get_distribution = json.dumps(list(get_distribution), cls=DjangoJSONEncoder) final_dict = {'get_distribution': get_distribution} return JsonResponse(final_dict, safe=False)
def rrima_public_dashboard(request, id=0): """ :param request: :param id: :return: """ # retrieve program model = Program # noqa # program_id = id # get_program = Program.objects.all().filter(id=program_id) # retrieve the coutries the user has data access for countries = get_country(request.user) # retrieve projects for a program # .filter(program__id=1, program__country__in=1) # get_projects = ProjectAgreement.objects.all() page_text = dict() page_text['page_title'] = "Refugee Response and Migration News" page_text['project_summary'] = {} # TODO : Change this variable page_map = [] get_notebooks = JupyterNotebooks.objects.all().filter( very_custom_dashboard="RRIMA") return render( request, 'customdashboard/rrima_dashboard.html', { 'page_text': page_text, 'page_map': page_map, 'countries': countries, 'get_notebooks': get_notebooks })
def get(self, request, *args, **kwargs): program_id = int(self.kwargs['program']) project_id = int(self.kwargs['project']) countries = get_country(request.user) if program_id == 0: get_beneficiaries = Beneficiary.objects.all().filter( Q(training__program__country__in=countries) | Q(distribution__program__country__in=countries)).values( 'id', 'beneficiary_name', 'create_date') elif program_id != 0 and project_id == 0: get_beneficiaries = Beneficiary.objects.all().filter( program__id=program_id).values('id', 'beneficiary_name', 'create_date') else: get_beneficiaries = Beneficiary.objects.all().filter( program__id=program_id, training__project_agreement=project_id).values( 'id', 'beneficiary_name', 'create_date') get_beneficiaries = json.dumps(list(get_beneficiaries), cls=DjangoJSONEncoder) final_dict = {'get_beneficiaries': get_beneficiaries} return JsonResponse(final_dict, safe=False)
def get(self, request, *args, **kwargs): program_id = int(self.kwargs['program']) project_id = int(self.kwargs['project']) countries = get_country(request.user) if int(self.kwargs['program']) == 0: get_training = TrainingAttendance.objects.all().filter( program__country__in=countries).values( 'id', 'create_date', 'training_name', 'project_agreement__project_name') elif program_id != 0 and project_id == 0: get_training = TrainingAttendance.objects.all().filter( program=program_id).values('id', 'create_date', 'training_name', 'project_agreement__project_name') else: get_training = TrainingAttendance.objects.all().filter( program_id=program_id, project_agreement_id=project_id).values( 'id', 'create_date', 'training_name', 'project_agreement__project_name') get_training = json.dumps(list(get_training), cls=DjangoJSONEncoder) final_dict = {'get_training': get_training} return JsonResponse(final_dict, safe=False)
def get_queryset(self): user_countries = get_country(self.request.user) queryset = ActivityTable.objects.filter(country__in=user_countries) table_id = self.request.query_params.get('table_id', None) if table_id is not None: queryset = queryset.filter(table_id=table_id) return queryset
def get(self, request, *args, **kwargs): # retrieve the coutries the user has data access for country = None countries = get_country(request.user) country_list = Country.objects.all().filter(id__in=countries) organization = request.user.activity_user.organization if int(self.kwargs['pk']) == 0: get_program = Program.objects.all().filter( organization=organization) else: get_program = Program.objects.all().filter( country__id=self.kwargs['pk']) country = Country.objects.get(id=self.kwargs['pk']).country program_list = [] for program in get_program: # get the percentage of indicators with data get_indicator_data_count = Indicator.objects.filter( program__id=program.id).exclude( collecteddata__periodic_target=None).count() get_indicator_count = Indicator.objects.filter( program__id=program.id).count() if get_indicator_count > 0 and get_indicator_data_count > 0: get_indicator_data_percent = \ 100 * float(get_indicator_data_count) / float( get_indicator_count) else: get_indicator_data_percent = 0 program.indicator_data_percent = int(get_indicator_data_percent) program.indicator_percent = int(100 - get_indicator_data_percent) # get the percentage of projects with completes (tracking) get_project_agreement_count = ProjectAgreement.objects.filter( program__id=program.id).count() get_project_complete_count = ProjectComplete.objects.filter( program__id=program.id).count() if get_project_agreement_count > 0 and \ get_project_complete_count > 0: project_percent = 100 * \ float(get_project_complete_count) / \ float(get_project_agreement_count) else: project_percent = 0 # append the rounded percentages to the program list program.project_percent = int(project_percent) program.project_agreement_percent = int(100 - project_percent) program_list.append(program) return render( request, self.template_name, { 'get_program': program_list, 'get_country': country_list, 'country': country })
def __init__(self, *args, **kwargs): indicator = kwargs.get('instance', None) self.request = kwargs.pop('request') self.program = kwargs.pop('program') self.organization = kwargs.pop('organization') self.program_id = kwargs.pop('program_id') self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_action = reverse_lazy('indicator_update', kwargs={'pk': indicator.id}) self.helper.form_id = 'indicator_update_form' self.helper.form_error_title = 'Form Errors' self.helper.error_text_inline = True self.helper.help_text_inline = True self.helper.html5_required = True self.helper.form_tag = False super(IndicatorForm, self).__init__(*args, **kwargs) # override the program queryset to use request.user for country countries = get_country(self.request.user) self.fields['program'].queryset = Program.objects.filter( organization=self.request.user.activity_user.organization) self.fields[ 'disaggregation'].queryset = DisaggregationType.objects.filter( country__in=countries).filter(standard=False) self.fields['objectives'].queryset = Objective.objects.filter( program__id=self.program_id) self.fields['approved_by'].queryset = ActivityUser.objects.filter( organization=self.request.user.activity_user.organization ).distinct() self.fields[ 'approval_submitted_by'].queryset = ActivityUser.objects.filter( organization=self.request.user.activity_user.organization ).distinct() self.fields['program'].widget.attrs['readonly'] = "readonly" self.fields['target_frequency_start'].widget.attrs[ 'class'] = 'monthPicker' self.fields[ 'key_performance_indicator'].label = 'Key Performance Indicator for this {}'.format( self.organization.level_1_label) self.fields['objectives'].label = '{} objective'.format( self.organization.level_1_label) self.fields['program'].label = '{}'.format( self.organization.level_1_label) self.fields['level'].queryset = Level.objects.filter().order_by( 'sort', 'id') self.fields['indicator_type'].queryset = IndicatorType.objects.filter( organization=self.request.user.activity_user.organization ).distinct() self.fields[ 'data_collection_frequency'].queryset = DataCollectionFrequency.objects.filter( organization=self.request.user.activity_user.organization ).distinct()
def queryset(self, request, queryset): """ Returns the filtered queryset based on the value provided in the query string and retrievable via `self.value()`. """ # Filter by logged in users allowable countries user_countries = get_country(request.user) # if not request.user.user.is_superuser: return queryset.filter(country__in=user_countries)
def get(self, request, *args, **kwargs): # retrieve program model = Program program_id = int(self.kwargs['pk']) get_program = Program.objects.all().filter(id=program_id) # retrieve the coutries the user has data access for countries = get_country(request.user) # retrieve projects for a program # getProjects = ProjectAgreement.objects.all().filter(program__id=program__id, program__country__in=countries) # retrieve projects for a program getCustomDashboards = CustomDashboard.objects.all().filter(program=program_id) return render(request, self.template_name, {'pk': program_id, 'getCustomDashboards': getCustomDashboards, 'getProgram': get_program})
def rrima_jupyter_view1(request, id=0): """ RRIMA custom dashboard TODO: Migrate this to the existing configurable dashboard :param request: :param id: :return: """ model = Program program_id = 1 # id ##USE TURKEY PROGRAM ID HERE # getProgram = Program.objects.all().filter(id=program_id) # retrieve the coutries the user has data access for countries = get_country(request.user) with open('static/rrima.html') as myfile: data = "\n".join(line for line in myfile) return HttpResponse(data)
def get(self, request, *args, **kwargs): program_id = self.kwargs['program'] countries = get_country(request.user) if program_id != 0: get_agreements = ProjectAgreement.objects.all().filter( program=program_id).values('id', 'project_name') else: pass final_dict = {} if get_agreements: get_agreements = json.dumps(list(get_agreements), cls=DjangoJSONEncoder) final_dict = {'get_agreements': get_agreements} return JsonResponse(final_dict, safe=False)
def get(self, request, *args, **kwargs): project_agreement_id = self.kwargs['pk'] countries = get_country(request.user) get_programs = Program.objects.all().filter( funding_status="Funded", country__in=countries).distinct() if int(self.kwargs['pk']) == 0: get_training = TrainingAttendance.objects.all().filter( program__country__in=countries) else: get_training = TrainingAttendance.objects.all().filter( project_agreement_id=self.kwargs['pk']) return render( request, self.template_name, { 'get_training': get_training, 'project_agreement_id': project_agreement_id, 'get_programs': get_programs })
def get(self, request, *args, **kwargs): program_id = self.kwargs['pk'] countries = get_country(request.user) get_programs = Program.objects.all().filter( funding_status="Funded", country__in=countries).distinct() if int(self.kwargs['pk']) == 0: get_distribution = Distribution.objects.all().filter( program__country__in=countries) else: get_distribution = Distribution.objects.all().filter( program_id=self.kwargs['pk']) return render( request, self.template_name, { 'get_distribution': get_distribution, 'program_id': program_id, 'get_programs': get_programs })
def __init__(self, *args, **kwargs): self.helper = FormHelper() self.request = kwargs.pop('request') self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-2' self.helper.field_class = 'col-sm-6' self.helper.form_error_title = 'Form Errors' self.helper.error_text_inline = True self.helper.help_text_inline = True self.helper.html5_required = True self.helper.add_input(Submit('submit', 'Save')) super(TrainingAttendanceForm, self).__init__(*args, **kwargs) countries = get_country(self.request.user) self.fields[ 'project_agreement'].queryset = ProjectAgreement.objects.filter( program__country__in=countries) self.fields['program'].queryset = Program.objects.filter( country__in=countries)
def get(self, request, *args, **kwargs): project_agreement_id = self.kwargs['pk'] countries = get_country(request.user) get_programs = Program.objects.all().filter( funding_status="Funded", country__in=countries).distinct() if int(self.kwargs['pk']) == 0: get_beneficiaries = Beneficiary.objects.all().filter( Q(training__program__country__in=countries) | Q(distribution__program__country__in=countries)) else: get_beneficiaries = Beneficiary.objects.all().filter( training__id=self.kwargs['pk']) return render( request, self.template_name, { 'get_beneficiaries': get_beneficiaries, 'project_agreement_id': project_agreement_id, 'get_programs': get_programs })
def __init__(self, *args, **kwargs): self.helper = FormHelper() self.request = kwargs.pop('request') self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-2' self.helper.field_class = 'col-sm-6' self.helper.form_error_title = 'Form Errors' self.helper.error_text_inline = True self.helper.help_text_inline = True self.helper.html5_required = True self.helper.add_input(Submit('submit', 'Save')) super(BeneficiaryForm, self).__init__(*args, **kwargs) countries = get_country(self.request.user) self.fields['training'].queryset = TrainingAttendance.objects.filter( program__country__in=countries) self.fields['training'].queryset = TrainingAttendance.objects.filter( program__country__in=countries) self.fields['distribution'].queryset = Distribution.objects.filter( program__country__in=countries) self.fields['site'].queryset = SiteProfile.objects.filter( country__in=countries)
def index(request, selected_countries=None, id=0, sector=0): """ Home page get count of agreements approved and total for dashboard """ program_id = id user_countries = get_country(request.user) if not selected_countries: selected_countries = user_countries selected_countries_list = None selected_countries_label_list = None else: # transform to list if a submitted country selected_countries = [selected_countries] selected_countries_list = Country.objects.all().filter(id__in=selected_countries) selected_countries_label_list = Country.objects.all().filter( id__in=selected_countries).values('country') get_agency_site = ActivitySites.objects.all().filter(id=1) get_sectors = Sector.objects.all().exclude( program__isnull=True).select_related() # limit the programs by the selected sector if int(sector) == 0: get_programs = Program.objects.all().prefetch_related('agreement', 'agreement__office').filter( funding_status="Funded", country__in=selected_countries) # .exclude(agreement__isnull=True) sectors = Sector.objects.all() else: get_programs = Program.objects.all().filter(funding_status="Funded", country__in=selected_countries, sector=sector) sectors = Sector.objects.all().filter(id=sector) filter_for_quantitative_data_sums = { 'indicator__key_performance_indicator': True, 'periodic_target__isnull': False, 'achieved__isnull': False, } # get data for just one program or all programs if int(program_id) == 0: get_filtered_name = None filter_for_quantitative_data_sums['indicator__program__country__in'] = selected_countries # filter by all programs then filter by sector if found if int(sector) > 0: filter_for_quantitative_data_sums['agreement__sector__in'] = sectors get_site_profile = SiteProfile.objects.all().prefetch_related('country', 'district', 'province').filter( Q(Q(projectagreement__sector__in=sectors)), country__in=selected_countries).filter(status=1) get_site_profile_indicator = SiteProfile.objects.all().prefetch_related( 'country', 'district', 'province').filter( Q(collecteddata__program__country__in=selected_countries)).filter(status=1) agreement_total_count = ProjectAgreement.objects.all().filter( sector__in=sectors, program__country__in=selected_countries).count() complete_total_count = ProjectComplete.objects.all().filter( project_agreement__sector__in=sectors, program__country__in=selected_countries).count() agreement_approved_count = ProjectAgreement.objects.all().filter( approval='approved', sector__in=sectors, program__country__in=selected_countries).count() complete_approved_count = ProjectComplete.objects.all().filter( approval='approved', project_agreement__sector__in=sectors, program__country__in=selected_countries).count() agreement_awaiting_count = ProjectAgreement.objects.all().filter( approval='awaiting approval', sector__in=sectors, program__country__in=selected_countries).count() complete_awaiting_count = ProjectComplete.objects.all().filter( approval='awaiting approval', project_agreement__sector__in=sectors, program__country__in=selected_countries).count() agreement_open_count = ProjectAgreement.objects.all().filter(Q(Q(approval='open') | Q(approval="") | Q( approval=None)), sector__id__in=sectors, program__country__in=selected_countries).count() complete_open_count = ProjectComplete.objects.all().filter( Q(Q(approval='open') | Q(approval="") | Q(approval=None)), project_agreement__sector__in=sectors, program__country__in=selected_countries).count() agreement_wait_count = ProjectAgreement.objects.all().filter( Q(approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval="")), sector__in=sectors, program__country__in=selected_countries).count() complete_wait_count = ProjectComplete.objects.all().filter( Q(approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval="")), project_agreement__sector__in=sectors, program__country__in=selected_countries).count() else: get_site_profile = SiteProfile.objects.all().prefetch_related( 'country', 'district', 'province').filter(country__in=selected_countries).filter(status=1) get_site_profile_indicator = SiteProfile.objects.all().prefetch_related( 'country', 'district', 'province').filter( Q(collecteddata__program__country__in=selected_countries)).filter(status=1) agreement_total_count = ProjectAgreement.objects.all().filter( program__country__in=selected_countries).count() complete_total_count = ProjectComplete.objects.all().filter( program__country__in=selected_countries).count() agreement_approved_count = ProjectAgreement.objects.all().filter( approval='approved', program__country__in=selected_countries).count() complete_approved_count = ProjectComplete.objects.all().filter( approval='approved', program__country__in=selected_countries).count() agreement_awaiting_count = ProjectAgreement.objects.all().filter( approval='awaiting approval', program__country__in=selected_countries).count() complete_awaiting_count = ProjectComplete.objects.all().filter( approval='awaiting approval', program__country__in=selected_countries).count() agreement_open_count = ProjectAgreement.objects.all().filter(Q(Q(approval='open') | Q( approval="") | Q(approval=None)), program__country__in=selected_countries).count() complete_open_count = ProjectComplete.objects.all().filter(Q(Q(approval='open') | Q( approval="") | Q(approval=None)), program__country__in=selected_countries).count() agreement_wait_count = ProjectAgreement.objects.all().filter( Q(approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval="")), program__country__in=selected_countries).count() complete_wait_count = ProjectComplete.objects.all().filter( Q(approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval="")), program__country__in=selected_countries).count() else: filter_for_quantitative_data_sums['indicator__program__id'] = program_id get_filtered_name = Program.objects.get(id=program_id) agreement_total_count = ProjectAgreement.objects.all().filter(program__id=program_id).count() complete_total_count = ProjectComplete.objects.all().filter(program__id=program_id).count() agreement_approved_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='approved').count() complete_approved_count = ProjectComplete.objects.all().filter( program__id=program_id, approval='approved').count() agreement_open_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='open').count() complete_open_count = ProjectComplete.objects.all().filter( Q(Q(approval='open') | Q(approval="")), program__id=program_id).count() agreement_wait_count = ProjectAgreement.objects.all().filter(Q(program__id=program_id), Q( approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval=""))).count() complete_wait_count = ProjectComplete.objects.all().filter(Q(program__id=program_id), Q( approval='in progress') & Q(Q(approval='in progress') | Q(approval=None) | Q(approval=""))).count() get_site_profile = SiteProfile.objects.all().prefetch_related( 'country', 'district', 'province').filter(projectagreement__program__id=program_id).filter(status=1) get_site_profile_indicator = SiteProfile.objects.all().prefetch_related( 'country', 'district', 'province').filter(Q(collecteddata__program__id=program_id)).filter(status=1) agreement_awaiting_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='awaiting approval').count() complete_awaiting_count = ProjectComplete.objects.all().filter( program__id=program_id, approval='awaiting approval').count() get_quantitative_data_sums = CollectedData.objects.all()\ .filter(**filter_for_quantitative_data_sums)\ .exclude(achieved=None, periodic_target=None, program__funding_status="Archived")\ .order_by('indicator__program', 'indicator__number')\ .values('indicator__lop_target', 'indicator__program__id', 'indicator__program__name', 'indicator__number', 'indicator__name', 'indicator__id')\ .annotate(targets=Sum('periodic_target'), actuals=Sum('achieved')) # Evidence and Objectives are for the global leader dashboard items and are the same every time count_evidence = CollectedData.objects.all().filter(indicator__isnull=False)\ .values("indicator__program__country__country").annotate( evidence_count=Count('evidence', distinct=True) + Count('activity_table', distinct=True), indicator_count=Count('pk', distinct=True)).order_by('-evidence_count') get_objectives = CollectedData.objects.filter( indicator__strategic_objectives__isnull=False, indicator__program__country__in=selected_countries)\ .exclude( achieved=None, periodic_target=None)\ .order_by('indicator__strategic_objectives__name')\ .values('indicator__strategic_objectives__name')\ .annotate( indicators=Count('indicator__pk', distinct=True), targets=Sum('periodic_target__target'), actuals=Sum('achieved')) # print(".............................%s............................" % getObjectives.query ) table = IndicatorDataTable(get_quantitative_data_sums) table.paginate(page=request.GET.get('page', 1), per_page=20) count_program = Program.objects.all().filter( country__in=selected_countries, funding_status='Funded').count() approved_by = ActivityUser.objects.get(user_id=request.user) user_pending_approvals = ProjectAgreement.objects.filter( approved_by=approved_by).exclude(approval='approved') count_program_agreement = ProjectAgreement.objects.all().filter( program__country__in=selected_countries, program__funding_status='Funded').values('program').distinct().count() count_indicator = Indicator.objects.all().filter( program__country__in=selected_countries, program__funding_status='Funded').values('program').distinct().count() count_evidence_adoption = CollectedData.objects.all().filter( indicator__isnull=False, indicator__program__country__in=selected_countries)\ .values("indicator__program__country__country")\ .annotate(evidence_count=Count('evidence', distinct=True) + Count('activity_table', distinct=True), indicator_count=Count('pk', distinct=True)).order_by('-evidence_count') count_program = int(count_program) count_program_agreement = int(count_program_agreement) green = "#5CB85C" yellow = "#E89424" red = "#B30838" # 66% or higher = Green above 25% below %66 is Orange and below %25 is Red if count_program_agreement >= float(count_program/1.5): workflow_adoption = green elif count_program/1.5 > count_program_agreement > count_program/4: workflow_adoption = yellow elif count_program_agreement <= count_program/4: workflow_adoption = red if count_indicator >= float(count_program/1.5): indicator_adoption = green elif count_program/1.5 > count_indicator > count_program/4: indicator_adoption = yellow elif count_indicator <= count_program/4: indicator_adoption = red total_evidence_adoption_count = 0 total_indicator_data_count = 0 for country in count_evidence_adoption: total_evidence_adoption_count = total_evidence_adoption_count + \ country['evidence_count'] total_indicator_data_count = total_indicator_data_count + \ country['indicator_count'] if total_evidence_adoption_count >= float(total_indicator_data_count/1.5): evidence_adoption = green elif total_indicator_data_count/1.5 > total_evidence_adoption_count > total_indicator_data_count/4: evidence_adoption = yellow elif total_evidence_adoption_count <= total_indicator_data_count/4: evidence_adoption = red return render(request, "index.html", {'agreement_total_count': agreement_total_count, 'agreement_approved_count': agreement_approved_count, 'agreement_open_count': agreement_open_count, 'agreement_wait_count': agreement_wait_count, 'agreement_awaiting_count': agreement_awaiting_count, 'complete_open_count': complete_open_count, 'complete_approved_count': complete_approved_count, 'complete_total_count': complete_total_count, 'complete_wait_count': complete_wait_count, 'complete_awaiting_count': complete_awaiting_count, 'programs': get_programs, 'getSiteProfile': get_site_profile, 'countries': user_countries, 'selected_countries': selected_countries, 'getFilteredName': get_filtered_name, 'getSectors': get_sectors, 'sector': sector, 'table': table, 'getQuantitativeDataSums': get_quantitative_data_sums, 'count_evidence': count_evidence, 'getObjectives': get_objectives, 'selected_countries_list': selected_countries_list, 'getSiteProfileIndicator': get_site_profile_indicator, 'getAgencySite': get_agency_site, 'workflow_adoption': workflow_adoption, 'count_program': count_program, 'count_program_agreement': count_program_agreement, 'indicator_adoption': indicator_adoption, 'count_indicator': count_indicator, 'evidence_adoption': evidence_adoption, 'count_evidence_adoption': total_evidence_adoption_count, 'count_indicator_data': total_indicator_data_count, 'selected_countries_label_list': selected_countries_label_list, 'user_pending_approvals': user_pending_approvals, })
def __init__(self, *args, **kwargs): # get the user object to check permissions with # print("..................%s..............." % kwargs.get('targets_sum', 'no targets sum found!!!!') ) indicator = kwargs.get('instance', None) self.request = kwargs.pop('request') self.program = kwargs.pop('program') self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_action = reverse_lazy( 'indicator_update', kwargs={'pk': indicator.id}) self.helper.form_id = 'indicator_update_form' self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-4' self.helper.field_class = 'col-sm-6' self.helper.form_error_title = 'Form Errors' self.helper.error_text_inline = True self.helper.help_text_inline = True self.helper.html5_required = True self.helper.form_tag = False self.helper.layout = Layout( TabHolder( Tab('Summary', Fieldset('', 'program', 'sector', 'objectives', 'strategic_objectives', ), HTML(""" {% if getExternalServiceRecord %} <div class='panel panel-default'> <div class='panel-heading'>External Indicator Service</div> <table class="table"> <tr> <th>Service Name</th> <th>View Guidance</th> </tr> {% for item in getExternalServiceRecord %} <tr> <td>{{ item.external_service.name }}</td> <td><a target="_new" href='{{ item.full_url }}'>View</a> </tr> {% endfor %} </table> </div> {% endif %} """), ), Tab('Performance', Fieldset('', 'name', 'level', 'number', 'source', 'definition', 'justification', 'disaggregation', 'indicator_type', PrependedText('key_performance_indicator', False))), Tab('Targets', Fieldset('', 'unit_of_measure', 'lop_target', 'rationale_for_target', Field('baseline', template="indicators/crispy.html"), 'baseline_na', 'target_frequency', 'target_frequency_start', 'target_frequency_custom', 'target_frequency_num_periods' ), Fieldset('', HTML(""" <div id="div_id_create_targets_btn" class="form-group"> <div class="controls col-sm-offset-4 col-sm-6"> <button type="button" id="id_create_targets_btn" class="btn btn-primary">Create targets</button> <button type="button" id="id_delete_targets_btn" class="btn btn-link">Remove all targets</button> </div> </div> """)), Fieldset('', HTML(""" <div id="id_div_periodic_tables_placeholder"> {% if periodic_targets and indicator.target_frequency != 1%} <div class="container-fluid" style="background-color: #F5F5F5; margin: 0px -30px 0px -30px;"> <div class="row"> <div class="col-sm-offset-2 col-sm-8" style="padding-left: 1px; margin-top: 30px;"> <h4>{{ indicator.get_target_frequency_label }} targets</h4> </div> </div> <div class="row"> <div id="periodic-targets-tablediv" class="col-sm-offset-2 col-sm-8"> <table class="table table-condensed" id="periodic_targets_table" style="margin-bottom: 1px;"> <tbody> {% for pt in periodic_targets %} <tr id="{{pt.pk}}" data-collected-count="{{pt.num_data}}" class="periodic-target"> <td style="width:50px; vertical-align: middle; border: none;"> <a href="{% url 'pt_delete' pt.id %}" id="deleteLastPT" class="detelebtn" style="text-align: center; margin: 3px 10px 0px 10px; color:red; display:{% if forloop.last and indicator.target_frequency != 2 or indicator.target_frequency == 8 %} block{% else %}none{% endif %}"> <span class="glyphicon glyphicon-remove"></span> </a> </td> <td style="padding:1px; border:none; vertical-align:middle;"> {% if indicator.target_frequency == 8 %} <div class="controls border-1px"> <input type="text" name="{{ pt.period }}" value="{{ pt.period }}" class="form-control input-text"> <span style="margin:0px;" class="help-block"> </span> </div> {% else %} <div style="line-height:1;"><strong>{{ pt.period }}</strong></div> <div style="line-height:1; margin-top:3px;">{{ pt.start_date_formatted }} {% if pt.start_date %} - {% endif %} {{ pt.end_date_formatted }}</div> {% endif %} </td> <td align="right" style="padding:1px; border:none; vertical-align: middle; width: 150px"> <div class="controls border-1px"> <input type="number" id="pt-{{ pt.id }}" name="{{ pt.period }}" value="{{ pt.target|floatformat:"-2" }}" data-start-date="{{pt.start_date|date:"M d, Y"|default:''}}" data-end-date="{{pt.end_date|date:"M d, Y"|default:''}}" placeholder="Enter target" class="form-control input-value"> <span id="hint_id_pt_{{pt.pk}}" style="margin:0px;" class="help-block"> </span> </div> </td> </tr> {% if forloop.last %} <tr id="pt_sum_targets"> <td class="pt-delete-row" style="border: none;"> </td> <td align="left" style="padding-left:0px; border:none; vertical-align: middle;"> <strong>Sum of targets</strong> </td> <td align="right" style="border:none; vertical-align: middle;"> <div style="margin: 5px 10px;"> <strong><span id="id_span_targets_sum">{{targets_sum|floatformat:"-2"}} </span></strong> </div> </td> </tr> {% endif %} {% endfor %} <tr style="background-color:#F5F5F5"> <td class="pt-delete-row" style="border: none;"> </td> <td align="left" style="padding-left:0px; border:none; vertical-align: middle;"> <strong>Life of Program (LoP) target</strong> </td> <td align="right" style="border:none; vertical-align: middle;"> <div style="margin: 5px 10px;"> <strong>{{indicator.lop_target|floatformat:"-2"}}</strong> </div> </td> </tr> </tbody> <tfoot> <tr style="background-color:#F5F5F5"> <td colspan="3" style="color:red; padding: 0px" id="id_pt_errors"></td> </tr> </tfoot> </table> </div> </div> {% if indicator.target_frequency != 2 %} <div class="row"> <div class="col-sm-offset-2 col-sm-8" style="padding-left: 1px; margin-top:10px; margin-bottom:40px;"> <a href="#" id="addNewPeriodicTarget" style="padding-left: 1px;" class="button btn-lg btn-link"> <span class=" glyphicon glyphicon-plus-sign"></span> Add a target</a> </div> </div> {% else %} <div class="row" style="height: 30px; margin-bottom: 15px"></div> {% endif %} </div> {% endif %} </div> """), ), ), Tab('Data Acquisition', Fieldset('', 'means_of_verification', 'data_collection_method', 'data_collection_frequency', 'data_points', 'responsible_person', ), ), Tab('Analysis and Reporting', Fieldset('', 'method_of_analysis', 'information_use', 'reporting_frequency', 'quality_assurance', 'data_issues', 'indicator_changes', 'comments', 'notes' ), ), Tab('Approval', Fieldset('', 'approval_submitted_by', 'approved_by', ), ), ), # HTML("""<hr/>"""), # FormActions( # Submit('submit', 'Save', css_class='btn-default'), # Reset('reset', 'Reset', css_class='btn-default') # ) ) super(IndicatorForm, self).__init__(*args, **kwargs) # override the program queryset to use request.user for country countries = get_country(self.request.user) self.fields['program'].queryset = Program.objects.filter( funding_status="Funded", country__in=countries) self.fields['disaggregation'].queryset = DisaggregationType.objects.filter( country__in=countries).filter(standard=False) self.fields['objectives'].queryset = Objective.objects.all().filter( program__id__in=self.program) self.fields['strategic_objectives'].queryset = StrategicObjective.objects.filter( country__in=countries) self.fields['approved_by'].queryset = ActivityUser.objects.filter( country__in=countries).distinct() self.fields['approval_submitted_by'].queryset = ActivityUser.objects.filter( country__in=countries).distinct() self.fields['program'].widget.attrs['readonly'] = "readonly" self.fields['baseline'].widget.attrs['class'] = 'col-sm-4' # self.fields['target_frequency_start'].widget = DatePicker.DateInput() # self.fields['target_frequency_start'].help_text = 'This field is required' # self.fields['target_frequency'].required = False self.fields['target_frequency_start'].widget.attrs['class'] = 'monthPicker' if self.instance.target_frequency and self.instance.target_frequency != Indicator.LOP: self.fields['target_frequency'].widget.attrs['readonly'] = "readonly"
def __init__(self, *args, **kwargs): instance = kwargs.get('instance', None) self.helper = FormHelper() self.request = kwargs.pop('request') self.program = kwargs.pop('program') self.indicator = kwargs.pop('indicator', None) self.activity_table = kwargs.pop('activity_table') self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-sm-4' self.helper.field_class = 'col-sm-6' self.helper.form_error_title = 'Form Errors' self.helper.form_action = reverse_lazy('collecteddata_update' if instance else 'collecteddata_add', kwargs={ 'pk': instance.id} if instance else {'program': self.program, 'indicator': self.indicator}) self.helper.form_id = 'collecteddata_update_form' self.helper.error_text_inline = True self.helper.help_text_inline = True self.helper.html5_required = True self.helper.form_tag = True self.helper.layout = Layout( HTML("""<br/>"""), Fieldset('Collected Data', 'program', 'program2', 'indicator', 'indicator2', 'target_frequency', 'site', 'date_collected', 'periodic_target', 'achieved', 'description', ), Fieldset('Evidence', 'complete', 'evidence', 'activity_table', 'update_count_activity_table', HTML("""<a class="output" data-toggle="modal" data-target="#activitytablemodal" href="/indicators/collecteddata_import/">Import Evidence From Activity Tables</a>"""), ), Div( HTML("""<br/> {% if getDisaggregationLabelStandard and not getDisaggregationValueStandard %} <div class='panel panel-default'> <!-- Default panel contents --> <div class='panel-heading'>Standard Disaggregations</div> <!-- Table --> <table class="table"> <tr> <th>Disaggregation Level</th> <th>Actuals</th> </tr> {% for item in getDisaggregationLabelStandard %} <tr> <td>{{ item.label }}</td> <td><input type="text" name="{{ item.id }}" value=""></td> </tr> {% endfor %} </table> </div> {% else %} {% if not getDisaggregationValueStandard %} <h4>Standard Disaggregation Levels Not Entered</h4> <p>Standard disaggregations are entered in the administrator for the entire organizations. If you are not seeing any here, please contact your system administrator.</p> {% endif %} {% endif %} {% if getDisaggregationLabel and not getDisaggregationValue %} <div class='panel panel-default'> <!-- Default panel contents --> <div class='panel-heading'>New Disaggregations</div> <!-- Table --> <table class="table"> <tr> <th>Disaggregation Level</th> <th>Actuals</th> </tr> {% for item in getDisaggregationLabel %} <tr> <td>{{ item.label }}</td> <td><input type="text" name="{{ item.id }}" value=""></td> </tr> {% endfor %} </table> </div> {% else %} {% if not getDisaggregationValue %} <h4>Disaggregation Levels Not Entered For This Indicator</h4> <a href="/indicators/indicator_update/{{ indicator_id }}">Add a Disaggregation</a> {% endif %} {% endif %} {% if getDisaggregationValue %} <div class='panel panel-default'> <!-- Default panel contents --> <div class='panel-heading'>Existing Disaggregations</div> <!-- Table --> <table class="table"> <tr> <th>Disaggregation Level</th> <th>Actuals</th> </tr> {% for item in getDisaggregationValue %} <tr> <td>{{ item.disaggregation_label.label }}</td> <td><input type="text" name="{{ item.disaggregation_label.id }}" value="{{ item.value }}"></td> </tr> {% endfor %} </table> </div> {% endif %} {% if getDisaggregationValueStandard %} <div class='panel panel-default'> <!-- Default panel contents --> <div class='panel-heading'>Existing Standard Disaggregations</div> <!-- Table --> <table class="table"> <tr> <th>Disaggregation Level</th> <th>Actuals</th> </tr> {% for item in getDisaggregationValueStandard %} <tr> <td>{{ item.disaggregation_label.label }}</td> <td><input type="text" name="{{ item.disaggregation_label.id }}" value="{{ item.value }}"></td> </tr> {% endfor %} </table> </div> {% endif %} """)), HTML("""<br/>"""), FormActions( Submit('submit', 'Save', css_class='btn-default'), Reset('reset', 'Reset', css_class='btn-warning') ) ) super(CollectedDataForm, self).__init__(*args, **kwargs) # override the program queryset to use request.user for country self.fields['evidence'].queryset = Documentation.objects.filter( program=self.program) # override the program queryset to use request.user for country self.fields['complete'].queryset = ProjectComplete.objects.filter( program=self.program) self.fields['complete'].label = "Project" # override the program queryset to use request.user for country countries = get_country(self.request.user) # self.fields['program'].queryset = Program.objects.filter(funding_status="Funded", # country__in=countries).distinct() try: int(self.program) self.program = Program.objects.get(id=self.program) except TypeError: pass self.fields['periodic_target'].queryset = PeriodicTarget.objects.filter( indicator=self.indicator).order_by('customsort', 'create_date', 'period') self.fields['program2'].initial = self.program self.fields['program2'].label = "Program" try: int(self.indicator) self.indicator = Indicator.objects.get(id=self.indicator) except TypeError as e: pass self.fields['indicator2'].initial = self.indicator.name self.fields['indicator2'].label = "Indicator" self.fields['program'].widget = forms.HiddenInput() self.fields['indicator'].widget = forms.HiddenInput() self.fields['target_frequency'].initial = self.indicator.target_frequency self.fields['target_frequency'].widget = forms.HiddenInput() # override the program queryset to use request.user for country self.fields['site'].queryset = SiteProfile.objects.filter( country__in=countries) # self.fields['indicator'].queryset = Indicator.objects.filter(name__isnull=False, # program__country__in=countries) self.fields['activity_table'].queryset = ActivityTable.objects.filter( Q(owner=self.request.user) | Q(id=self.activity_table)) self.fields['periodic_target'].label = 'Measure against target*' self.fields['achieved'].label = 'Actual value' self.fields['date_collected'].help_text = ' '
def rrima_public_dashboard(request, id=0): """ :param request: :param id: :return: """ # retrieve program model = Program program_id = id getProgram = Program.objects.all().filter(id=program_id) # retrieve the coutries the user has data access for countries = get_country(request.user) # retrieve projects for a program # .filter(program__id=1, program__country__in=1) getProjects = ProjectAgreement.objects.all() page_text = dict() page_text['pageTitle'] = "Refugee Response and Migration News" page_text['projectSummary'] = {} # TODO : Change this variable page_map = [{ "latitude": 39.9334, "longitude": 32.8597, "location_name": "Ankara", "site_contact": "Sonal Shinde, Migration Response Director, [email protected]", "site_description": "Migration Response Coordination", "region_name": "Turkey" }, { "latitude": 38.4237, "longitude": 27.1428, "location_name": "Izmir", "site_contact": "Tracy Lucas, Emergency Program Manager, ECHO Aegean Response, [email protected]", "site_description": "Cash, Information Dissemination, Youth, Protection", "region_name": "Turkey" }, { "latitude": 37.0660, "longitude": 37.3781, "location_name": "Gaziantep", "site_contact": "Jihane Nami, Director of Programs Turkey, [email protected]", "site_description": "Cash, NFI, Shelter, Protection, Information Dissemination", "region_name": "Turkey" }, { "latitude": 39.2645, "longitude": 26.2777, "location_name": "Lesvos", "site_contact": "Chiara Bogoni, Island Emergency Program Manager, [email protected]", "site_description": "Cash, Youth Programs, Food", "region_link": "Greece" }, { "latitude": 37.9838, "longitude": 23.7275, "location_name": "Athens", "site_contact": "Josh Kreger, Team Leader - Greece, [email protected] and Kaja Wislinska, " + "Team Leader - Athens and Mainland, [email protected]", "site_description": "Cash, Youth Psychosocial Support, Legal Support", "region_link": "Greece" }, { "latitude": 44.7866, "longitude": 20.4489, "location_name": "Belgrade", "site_contact": "", "site_description": "RRIMA (In partnership with IRC) ", "region_name": "Balkans" }] # Borrowed data for bar graph colorPalettes = { 'bright': [ '#82BC00', '#C8C500', '#10A400', '#CF102E', '#DB5E11', '#A40D7A', '#00AFA8', '#1349BB', '#FFD200 ', '#FF7100', '#FFFD00', '#ABABAB', '#7F7F7F', '#7B5213', '#C18A34' ], 'light': [ '#BAEE46', '#FDFB4A', '#4BCF3D', '#F2637A', '#FFA268', '#C451A4', '#4BC3BE', '#5B7FCC', '#9F54CC', '#FFE464', '#FFA964', '#FFFE64', '#D7D7D7', '#7F7F7F', '#D2A868', '#FFD592' ] } get_notebooks = JupyterNotebooks.objects.all().filter( very_custom_dashboard="RRIMA") return render( request, 'customdashboard/rrima_dashboard.html', { 'page_text': page_text, 'page_map': page_map, 'countries': countries, 'get_notebooks': get_notebooks })
def list(self, request): user_countries = get_country(request.user) queryset = CollectedData.objects.all().filter( program__country__in=user_countries) serializer = self.get_serializer(queryset, many=True) return Response(serializer.data)
def default_custom_dashboard(request, id=0, status=0): """ This is used as the workflow program dashboard # of agreements, approved, rejected, waiting, archived and total for dashboard http://127.0.0.1:8000/customdashboard/65/ """ program_id = id countries = get_country(request.user) # transform to list if a submitted country selected_countries_list = Country.objects.all().filter( program__id=program_id) get_quantitative_data_sums = CollectedData.objects.filter( indicator__program__id=program_id, achieved__isnull=False, indicator__key_performance_indicator=True) \ .exclude(achieved=None).order_by( 'indicator__number').values('indicator__number', 'indicator__name', 'indicator__id') \ .annotate(targets=Sum('periodic_target__target'), actuals=Sum('achieved')).exclude(achieved=None) total_targets = get_quantitative_data_sums.aggregate(Sum('targets')) total_actuals = get_quantitative_data_sums.aggregate(Sum('actuals')) get_filtered_name = Program.objects.get(id=program_id) get_projects_count = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries).count() get_budget_estimated = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries).annotate( estimated=Sum('total_estimated_budget')) get_awaiting_approval_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='awaiting approval', program__country__in=countries).count() get_approved_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='approved', program__country__in=countries).count() get_rejected_count = ProjectAgreement.objects.all().filter( program__id=program_id, approval='rejected', program__country__in=countries).count() get_in_progress_count = ProjectAgreement.objects.all().filter( program__id=program_id).filter( Q(Q(approval='in progress') | Q(approval=None)), program__country__in=countries).count() no_status_count = ProjectAgreement.objects.all().filter( program__id=program_id).filter(Q(Q(approval=None) | Q(approval=""))).count() get_site_profile = SiteProfile.objects.all().filter( Q(projectagreement__program__id=program_id) | Q(collecteddata__program__id=program_id)) get_site_profile_indicator = SiteProfile.objects.all().filter( Q(collecteddata__program__id=program_id)) if status == 'Approved': get_projects = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries, approval='approved').prefetch_related('projectcomplete') elif status == 'Rejected': get_projects = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries, approval='rejected').prefetch_related('projectcomplete') elif status == 'In Progress': get_projects = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries, approval='in progress').prefetch_related('projectcomplete') elif status == 'Awaiting Approval': get_projects = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries, approval='awaiting approval').prefetch_related('projectcomplete') else: get_projects = ProjectAgreement.objects.all().filter( program__id=program_id, program__country__in=countries) get_project_completed = [] total_budgetted = 0.00 total_actual = 0.00 get_projects_complete = ProjectComplete.objects.all() for project in get_projects: for complete in get_projects_complete: if complete.actual_budget is not None: if project.id == complete.project_agreement_id: total_budgetted = float(total_budgetted) + float( project.total_estimated_budget) total_actual =\ float(total_actual) + float(complete.actual_budget) get_project_completed.append(project) return render( request, "customdashboard/customdashboard/visual_dashboard.html", { 'get_site_profile': get_site_profile, 'get_budget_estimated': get_budget_estimated, 'get_quantitative_data_sums': get_quantitative_data_sums, 'country': countries, 'get_awaiting_approval_count': get_awaiting_approval_count, 'get_filtered_name': get_filtered_name, 'get_projects': get_projects, 'get_approved_count': get_approved_count, 'get_rejected_count': get_rejected_count, 'get_in_progress_count': get_in_progress_count, 'nostatus_count': no_status_count, 'get_projects_count': get_projects_count, 'selected_countries_list': selected_countries_list, 'get_site_profile_indicator': get_site_profile_indicator, 'get_project_completed': get_project_completed, 'total_actuals': total_actuals, 'total_targets': total_targets, 'total_budgetted': total_budgetted, 'total_actual': total_actual })
def list(self, request): user_countries = get_country(request.user) queryset = DisaggregationValue.objects.all().filter( country__in=user_countries) serializer = self.get_serializer(queryset, many=True) return Response(serializer.data)