Skip to content

Commit

Permalink
Merge pull request #5 from unicef-drp/feature/826-Remove-Django-Warnings
Browse files Browse the repository at this point in the history
Feature/826 remove django warnings
  • Loading branch information
danangmassandy authored Aug 2, 2023
2 parents 1fac11c + 9372d5d commit 6812b8f
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 52 deletions.
2 changes: 1 addition & 1 deletion deployment/docker/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ django-nose
coverage
pep8
pylint
flake8
flake8==6.0.0
factory_boy

django-devserver
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
66 changes: 47 additions & 19 deletions django_project/core/models/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -123,7 +163,7 @@ class SitePreferences(SingletonModel):
# JSON template for vector tiling config
# -----------------------------------------------
tile_configs_template = models.JSONField(
default=[],
default=list,
blank=True
)
# -----------------------------------------------
Expand All @@ -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
)
# -----------------------------------------------
Expand All @@ -166,23 +206,15 @@ 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
)
# -----------------------------------------------
# Default Group Name (Public)
# new user will be added to this groups
# -----------------------------------------------
default_public_groups = models.JSONField(
default=['UNICEF'],
default=default_public_groups,
blank=True
)
# -----------------------------------------------
Expand All @@ -199,19 +231,15 @@ 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
)
# -----------------------------------------------
# Default Admin Email Addresses
# send email notification from SignUp and Access Request
# -----------------------------------------------
default_admin_emails = models.JSONField(
default=[],
default=list,
blank=True
)
# -----------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions django_project/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
},
},
Expand Down
38 changes: 15 additions & 23 deletions django_project/dashboard/api_views/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
4 changes: 2 additions & 2 deletions django_project/dashboard/models/batch_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion django_project/dashboard/models/entities_user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EntitiesUserConfig(models.Model):
)

filters = models.JSONField(
default={},
default=dict,
blank=True
)

Expand Down
2 changes: 1 addition & 1 deletion django_project/dashboard/models/entity_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions django_project/dashboard/models/layer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions django_project/dashboard/models/layer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion django_project/dashboard/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Notification(models.Model):
)

payload = models.JSONField(
default={},
default=dict,
blank=True
)

Expand Down

1 comment on commit 6812b8f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for django_project/dashboard

St.
Category Percentage Covered / Total
🔴 Statements 5.9% 392/6641
🔴 Branches 0.93% 34/3671
🔴 Functions 2.94% 50/1700
🔴 Lines 5.94% 387/6511

Test suite run success

12 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from 6812b8f

Please sign in to comment.