Skip to content

Commit

Permalink
Merge pull request #518 from mercycorps/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
andrethomas6 authored Feb 9, 2022
2 parents fa9d99c + 1c3a8c8 commit 1c3ffd2
Show file tree
Hide file tree
Showing 85 changed files with 5,161 additions and 2,362 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,5 @@ npm will compile a single global css file at `/path/to/project/tola/static/css/t
5. Suggestions for Frontend coding practices are forthcoming.
## Updating Python libraries
Tola uses [pip-tools](https://github.com/jazzband/pip-tools) to manage Python dependencies. The requirements.in file is where changes to Python libraries should be made. pip-compile can then be used to generate the requirements.txt file. This allows us to list only those libraries we are explicitly adding in requirements.in, with a description of what the library is being used for. pip-tools is then used to handle adding dependencies, installation, and upgrades. See pip-tools documentation for details of use.
2 changes: 2 additions & 0 deletions config/sample-settings.secret.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ SECRET_KEY: 'replace with a suitable key'

LOGFILE: '/path/to/log/file'

REPORTING_YEAR_START_DATE: '2021-07-01'

PROGRAM_API_BASE_URL: 'https://program.api/endpoint/'
PROGRAM_API_TOKEN: 'replace with a program API token'

Expand Down
14 changes: 12 additions & 2 deletions factories/indicators_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Level,
LevelTier,
Objective,
OutcomeTheme,
PeriodicTarget,
StrategicObjective,
PinnedReport,
Expand Down Expand Up @@ -333,9 +334,10 @@ class DisaggregationTypeFactory(DjangoModelFactory):
class Meta:
model = DisaggregationType

standard = False
global_type = DisaggregationType.DISAG_COUNTRY_ONLY
disaggregation_type = Sequence(lambda n: "disagg type {0}".format(n))
country = LazyAttribute(lambda o: None if o.standard else CountryFactory())
country = LazyAttribute(
lambda o: None if o.global_type != DisaggregationType.DISAG_COUNTRY_ONLY else CountryFactory())

@post_generation
def labels(self, create, extracted, **kwargs):
Expand Down Expand Up @@ -373,3 +375,11 @@ class Meta:
frequency = "some reasonable frequency"
description = "a description of how frequent this is"
sort_order = Sequence(lambda n: n)


class OutcomeThemeFactory(DjangoModelFactory):
class Meta:
model = OutcomeTheme

name = Faker('text')
is_active = True
32 changes: 20 additions & 12 deletions indicators/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
Indicator, IndicatorType, Result, StrategicObjective, Objective, Level,
ExternalService, ExternalServiceRecord, DataCollectionFrequency,
DisaggregationType, PeriodicTarget, DisaggregationLabel, ReportingFrequency,
ExternalServiceAdmin,
ExternalServiceRecordAdmin,
PeriodicTargetAdmin,
ExternalServiceAdmin, ExternalServiceRecordAdmin, PeriodicTargetAdmin, OutcomeTheme
)
from workflow.models import Sector, Program, Country
from import_export import resources, fields
from import_export.widgets import ForeignKeyWidget, ManyToManyWidget
from import_export.admin import ImportExportModelAdmin
from simple_history.admin import SimpleHistoryAdmin

DISAG_COUNTRY_ONLY = DisaggregationType.DISAG_COUNTRY_ONLY
DISAG_GLOBAL = DisaggregationType.DISAG_GLOBAL
DISAG_PARTICIPANT_COUNT = DisaggregationType.DISAG_PARTICIPANT_COUNT


class BooleanListFilterWithDefault(admin.SimpleListFilter):
all_value = 'all'
Expand Down Expand Up @@ -200,7 +202,7 @@ def categories(self, instance):

def get_queryset(self, request):
"""annotation (programs using disaggregation) and filter (is or is not global)"""
return super().get_queryset(request).filter(standard=self.STANDARD).annotate(
return super().get_queryset(request).filter(global_type__in=self.GLOBAL_TYPES).annotate(
program_count_annotation=models.Subquery(
Indicator.rf_aware_objects.filter(
disaggregation=models.OuterRef('pk')
Expand All @@ -218,16 +220,15 @@ class Meta:

@admin.register(GlobalDisaggregation)
class GlobalDisaggregationAdmin(DisaggregationAdmin):
list_display = ('disaggregation_type', 'pretty_archived', 'program_count', 'categories')
list_display = ('disaggregation_type', 'global_type', 'pretty_archived', 'program_count', 'categories')
list_filter = (ArchivedFilter,)
sortable_by = ('disaggregation_type', 'program_count')
exclude = ('create_date', 'edit_date', 'country', 'standard')
STANDARD = True # shows only standard (global) disaggregations
exclude = ('create_date', 'edit_date', 'country')
GLOBAL_TYPES = [DISAG_GLOBAL, DISAG_PARTICIPANT_COUNT]
COLUMN_WIDTH = 70 # width of the "categories list" column before truncation

def save_model(self, request, obj, form, change):
"""ensure on save that standard is true and country is blank - this is the global admin"""
obj.standard = True
"""ensure on save that country is blank - this is the global admin"""
obj.country = None
super().save_model(request, obj, form, change)

Expand All @@ -243,12 +244,12 @@ class CountryDisaggregationAdmin(DisaggregationAdmin):
list_display = ('disaggregation_type', 'country', 'pretty_archived', 'program_count', 'categories')
list_filter = (ArchivedFilter, 'country')
sortable_by = ('disaggregation_type', 'program_count', 'country')
exclude = ('create_date', 'edit_date', 'standard',)
STANDARD = False
exclude = ('create_date', 'edit_date', 'global_type',)
GLOBAL_TYPES = [DISAG_COUNTRY_ONLY]
COLUMN_WIDTH = 50

def save_model(self, request, obj, form, change):
obj.standard = False
obj.global_type = DISAG_COUNTRY_ONLY
super().save_model(request, obj, form, change)


Expand Down Expand Up @@ -301,6 +302,12 @@ class ReportingFrequencyAdmin(admin.ModelAdmin):
display = 'Reporting Frequency'


class OutcomeThemeAdmin(admin.ModelAdmin):
list_display = ('name', 'is_active', 'create_date')
display = 'Outcome Theme'
readonly_fields = ('create_date',)


admin.site.register(IndicatorType)
admin.site.register(Indicator, IndicatorAdmin)
admin.site.register(ReportingFrequency)
Expand All @@ -312,3 +319,4 @@ class ReportingFrequencyAdmin(admin.ModelAdmin):
admin.site.register(ExternalServiceRecord, ExternalServiceRecordAdmin)
admin.site.register(DataCollectionFrequency)
admin.site.register(PeriodicTarget, PeriodicTargetAdmin)
admin.site.register(OutcomeTheme, OutcomeThemeAdmin)
Loading

0 comments on commit 1c3ffd2

Please sign in to comment.