diff --git a/deployment/docker/requirements-dev.txt b/deployment/docker/requirements-dev.txt index 0dba7b10..0817083f 100644 --- a/deployment/docker/requirements-dev.txt +++ b/deployment/docker/requirements-dev.txt @@ -2,7 +2,7 @@ django-nose coverage pep8 pylint -flake8 +flake8==6.0.0 factory_boy django-devserver diff --git a/django_project/core/migrations/0021_alter_sitepreferences_api_config_and_more.py b/django_project/core/migrations/0021_alter_sitepreferences_api_config_and_more.py new file mode 100644 index 00000000..902effa7 --- /dev/null +++ b/django_project/core/migrations/0021_alter_sitepreferences_api_config_and_more.py @@ -0,0 +1,49 @@ +# Generated by Django 4.0.7 on 2023-08-01 06:39 + +import core.models.preferences +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0020_sitepreferences_base_url_help_page'), + ] + + operations = [ + migrations.AlterField( + model_name='sitepreferences', + name='api_config', + field=models.JSONField(blank=True, default=core.models.preferences.default_api_config), + ), + migrations.AlterField( + model_name='sitepreferences', + name='default_admin_emails', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='sitepreferences', + name='default_geometry_checker_params', + field=models.JSONField(blank=True, default=core.models.preferences.default_geometry_checker_params), + ), + migrations.AlterField( + model_name='sitepreferences', + name='default_public_groups', + field=models.JSONField(blank=True, default=core.models.preferences.default_public_groups), + ), + migrations.AlterField( + model_name='sitepreferences', + name='level_names_template', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='sitepreferences', + name='metadata_xml_config', + field=models.JSONField(blank=True, default=core.models.preferences.default_metadata_xml_config), + ), + migrations.AlterField( + model_name='sitepreferences', + name='tile_configs_template', + field=models.JSONField(blank=True, default=list), + ), + ] diff --git a/django_project/core/models/preferences.py b/django_project/core/models/preferences.py index e4fdeff3..4e045f89 100644 --- a/django_project/core/models/preferences.py +++ b/django_project/core/models/preferences.py @@ -5,6 +5,46 @@ from core.models.singleton import SingletonModel +def default_api_config(): + """ + Default value for Preference's api_config. + """ + return {'default_page_size': 50, 'max_page_size': 50} + + +def default_metadata_xml_config(): + """ + Default value for Preference's metadata_xml_config. + """ + return { + 'ContactName': 'GeoRepo', + 'ContactOrg': 'Unicef', + 'ContactPosition': 'Administrator', + 'License': ( + 'Not Specified: The original author ' + 'did not specify a license.' + ) + } + + +def default_public_groups(): + """ + Default value for Preference's public_group. + """ + return ['UNICEF'] + + +def default_geometry_checker_params(): + """ + Default value for Preference's geometry_checker_params. + """ + return { + 'tolerance': 1e-4, + 'overlaps_threshold': 0.01, + 'gaps_threshold': 0.01, + } + + class SitePreferences(SingletonModel): """Preference settings specifically for website. @@ -123,7 +163,7 @@ class SitePreferences(SingletonModel): # JSON template for vector tiling config # ----------------------------------------------- tile_configs_template = models.JSONField( - default=[], + default=list, blank=True ) # ----------------------------------------------- @@ -141,14 +181,14 @@ class SitePreferences(SingletonModel): # JSON template for admin level names # ----------------------------------------------- level_names_template = models.JSONField( - default=[], + default=list, blank=True ) # ----------------------------------------------- # API pagination setting # ----------------------------------------------- api_config = models.JSONField( - default={'default_page_size': 50, 'max_page_size': 50}, + default=default_api_config, blank=True ) # ----------------------------------------------- @@ -166,15 +206,7 @@ class SitePreferences(SingletonModel): # METADATA XML Config # ----------------------------------------------- metadata_xml_config = models.JSONField( - default={ - 'ContactName': 'GeoRepo', - 'ContactOrg': 'Unicef', - 'ContactPosition': 'Administrator', - 'License': ( - 'Not Specified: The original author ' - 'did not specify a license.' - ) - }, + default=default_metadata_xml_config, blank=True ) # ----------------------------------------------- @@ -182,7 +214,7 @@ class SitePreferences(SingletonModel): # new user will be added to this groups # ----------------------------------------------- default_public_groups = models.JSONField( - default=['UNICEF'], + default=default_public_groups, blank=True ) # ----------------------------------------------- @@ -199,11 +231,7 @@ class SitePreferences(SingletonModel): # Default Geometry Checker Parameters # ----------------------------------------------- default_geometry_checker_params = models.JSONField( - default={ - 'tolerance': 1e-4, - 'overlaps_threshold': 0.01, - 'gaps_threshold': 0.01, - }, + default=default_geometry_checker_params, blank=True ) # ----------------------------------------------- @@ -211,7 +239,7 @@ class SitePreferences(SingletonModel): # send email notification from SignUp and Access Request # ----------------------------------------------- default_admin_emails = models.JSONField( - default=[], + default=list, blank=True ) # ----------------------------------------------- diff --git a/django_project/core/settings/base.py b/django_project/core/settings/base.py index 7bd685ca..5601baf8 100644 --- a/django_project/core/settings/base.py +++ b/django_project/core/settings/base.py @@ -107,6 +107,7 @@ 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', 'core.context_processors.global_context.global_context', + 'django.template.context_processors.request' ], }, }, diff --git a/django_project/dashboard/api_views/dataset.py b/django_project/dashboard/api_views/dataset.py index b1abfa40..8ced9f0b 100644 --- a/django_project/dashboard/api_views/dataset.py +++ b/django_project/dashboard/api_views/dataset.py @@ -115,29 +115,21 @@ def get_sort_attribute(self, sort_by, sort_direction): return None, None if sort_direction not in ['asc', 'desc']: return None, None - match sort_by: - case 'id': - return 'gg.id', sort_direction - case 'country': - return 'parent_0.label', sort_direction - case 'level': - return 'gg.level', sort_direction - case 'type': - return 'ge.label', sort_direction - case 'name': - return 'gg.label', sort_direction - case 'default_code': - return 'gg.internal_code', sort_direction - case 'code': - return 'gg.unique_code', sort_direction - case 'cucode': - return 'gg.concept_ucode', sort_direction - case 'updated': - return 'gg.start_date', sort_direction - case 'rev': - return 'gg.revision_number', sort_direction - case 'status': - return 'gg.is_approved', sort_direction + + field_mapping = { + 'id': 'gg.id', + 'country': 'parent_0.label', + 'level': 'gg.level', + 'type': 'gg.type', + 'name': 'gg.label', + 'default_code': 'gg.internal_code', + 'code': 'gg.unique_code', + 'cucode': 'gg.concept_code', + 'updated': 'gg.start_date', + 'rev': 'gg.revision_number', + 'status': 'gg.is_approved' + } + return field_mapping[sort_by], sort_direction def do_run_query( self, diff --git a/django_project/dashboard/migrations/0060_alter_batchreview_processed_ids_and_more.py b/django_project/dashboard/migrations/0060_alter_batchreview_processed_ids_and_more.py new file mode 100644 index 00000000..13170f3f --- /dev/null +++ b/django_project/dashboard/migrations/0060_alter_batchreview_processed_ids_and_more.py @@ -0,0 +1,58 @@ +# Generated by Django 4.0.7 on 2023-08-01 06:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dashboard', '0059_alter_notification_type'), + ] + + operations = [ + migrations.AlterField( + model_name='batchreview', + name='processed_ids', + field=models.JSONField(blank=True, default=list, help_text='List of entity uploads that has been processed', null=True), + ), + migrations.AlterField( + model_name='batchreview', + name='upload_ids', + field=models.JSONField(blank=True, default=list, help_text='List of entity uploads', null=True), + ), + migrations.AlterField( + model_name='entitiesuserconfig', + name='filters', + field=models.JSONField(blank=True, default=dict), + ), + migrations.AlterField( + model_name='entityuploadstatus', + name='admin_level_names', + field=models.JSONField(blank=True, default=dict, help_text='Name of admin levels', null=True), + ), + migrations.AlterField( + model_name='layerconfig', + name='id_fields', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='layerconfig', + name='name_fields', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='layerfile', + name='id_fields', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='layerfile', + name='name_fields', + field=models.JSONField(blank=True, default=list), + ), + migrations.AlterField( + model_name='notification', + name='payload', + field=models.JSONField(blank=True, default=dict), + ), + ] diff --git a/django_project/dashboard/models/batch_review.py b/django_project/dashboard/models/batch_review.py index 959a773d..ebb63fbb 100644 --- a/django_project/dashboard/models/batch_review.py +++ b/django_project/dashboard/models/batch_review.py @@ -50,14 +50,14 @@ class BatchReview(models.Model): upload_ids = models.JSONField( help_text='List of entity uploads', - default=[], + default=list, null=True, blank=True ) processed_ids = models.JSONField( help_text='List of entity uploads that has been processed', - default=[], + default=list, null=True, blank=True ) diff --git a/django_project/dashboard/models/entities_user_config.py b/django_project/dashboard/models/entities_user_config.py index 2d82d746..e8a694d9 100644 --- a/django_project/dashboard/models/entities_user_config.py +++ b/django_project/dashboard/models/entities_user_config.py @@ -35,7 +35,7 @@ class EntitiesUserConfig(models.Model): ) filters = models.JSONField( - default={}, + default=dict, blank=True ) diff --git a/django_project/dashboard/models/entity_upload.py b/django_project/dashboard/models/entity_upload.py index 750cb19d..99cbd367 100644 --- a/django_project/dashboard/models/entity_upload.py +++ b/django_project/dashboard/models/entity_upload.py @@ -117,7 +117,7 @@ class EntityUploadStatus(models.Model): admin_level_names = models.JSONField( help_text='Name of admin levels', - default={}, + default=dict, null=True, blank=True ) diff --git a/django_project/dashboard/models/layer_config.py b/django_project/dashboard/models/layer_config.py index 0a6a67b6..43e782b3 100644 --- a/django_project/dashboard/models/layer_config.py +++ b/django_project/dashboard/models/layer_config.py @@ -54,12 +54,12 @@ class LayerConfig(models.Model): ) id_fields = models.JSONField( - default=[], + default=list, blank=True ) name_fields = models.JSONField( - default=[], + default=list, blank=True ) diff --git a/django_project/dashboard/models/layer_file.py b/django_project/dashboard/models/layer_file.py index b77bfecb..870060df 100644 --- a/django_project/dashboard/models/layer_file.py +++ b/django_project/dashboard/models/layer_file.py @@ -84,12 +84,12 @@ class LayerFile(models.Model): ) id_fields = models.JSONField( - default=[], + default=list, blank=True ) name_fields = models.JSONField( - default=[], + default=list, blank=True ) diff --git a/django_project/dashboard/models/notification.py b/django_project/dashboard/models/notification.py index 2014de9b..26f7b81d 100644 --- a/django_project/dashboard/models/notification.py +++ b/django_project/dashboard/models/notification.py @@ -40,7 +40,7 @@ class Notification(models.Model): ) payload = models.JSONField( - default={}, + default=dict, blank=True )