Skip to content

Commit

Permalink
updates workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
saxix committed Oct 7, 2024
1 parent 7f32410 commit 8abdbf6
Show file tree
Hide file tree
Showing 274 changed files with 33,472 additions and 1,745 deletions.
1,584 changes: 0 additions & 1,584 deletions pdm.lock

This file was deleted.

36 changes: 15 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = {text = "MIT"}

dependencies = [
"celery>=5.4.0",
"deepdiff>=8.0.1",
"django-admin-extra-buttons>=1.5.8",
"django-adminactions>=2.3.0",
"django-adminfilters>=2.4.3",
Expand All @@ -24,9 +25,10 @@ dependencies = [
"django-regex>=0.5.0",
"django-select2",
"django-smart-admin>=2.6.0",
"django-stubs-ext",
"django-smart-env>=0.1.0",
"django-storages[azure]>=1.14.4",
"django>=5.0.6",
"django-stubs-ext",
"django>=5.1",
"djangorestframework>=3.15.1",
"hope-flex-fields @ git+https://github.com/unicef/hope-flex-fields@release/0.1rc",
"psycopg2-binary>=2.9.9",
Expand All @@ -36,34 +38,26 @@ dependencies = [
"social-auth-app-django",
"unicef-security>=1.5.1",
"uwsgi",
"django-smart-env>=0.1.0",
]

[tool.pdm]
distribution = false

[tool.pdm.dev-dependencies]
dev = [
"pytest-selenium>=4.1.0",
"selenium>=4.25.0",
]
[tool.uv]
dev-dependencies = [
"pytest>=8.2.2",
"pytest-celery>=1.0.0",
"pytest-django>=4.8.0",
"pytest-echo>=1.7.3",
"freezegun>=1.5.1",
"factory-boy>=3.3.0",
"black>=24.4.2",
"isort>=5.13.2",
"django-webtest>=1.9.11",
"factory-boy>=3.3.0",
"flake8>=7.1.0",
"freezegun>=1.5.1",
"isort>=5.13.2",
"pdbpp>=0.10.3",
"pre-commit>=3.7.1",
"pytest-celery>=1.0.0",
"pytest-coverage>=0.0",
"responses>=0.25.3",
"pytest-django>=4.8.0",
"pytest-echo>=1.7.3",
"pytest-factoryboy>=2.7.0",
"django-webtest>=1.9.11",
"pre-commit>=3.7.1",
"pytest-selenium>=4.1.0",
"pytest>=8.2.2",
"responses>=0.25.3",
]

[tool.black]
Expand Down
2 changes: 1 addition & 1 deletion src/country_workspace/admin/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@admin.register(Household)
class HouseholdAdmin(admin.ModelAdmin):
list_display = ("name", "country_office")
list_filter = ("country_office",)
list_filter = ("country_office", "program")
readonly_fields = ("country_office",)
search_fields = ("name",)
1 change: 1 addition & 0 deletions src/country_workspace/admin/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
class ProgramAdmin(admin.ModelAdmin):
list_display = ("name",)
search_fields = ("name",)
list_filter = ("country_office",)
2 changes: 1 addition & 1 deletion src/country_workspace/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Config(AppConfig):
name = __name__.rpartition(".")[0]
verbose_name = "Workspaces"
verbose_name = "Country Workspace"

def ready(self):
from .utils import flags # noqa
1 change: 1 addition & 0 deletions src/country_workspace/config/fragments/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ANALYST_GROUP_NAME = "Analyst"
NEW_USER_DEFAULT_GROUP = "Default"

TENANT_TENANT_MODEL = "country_workspace.CountryOffice"
TENANT_HQ = "= HQ ="
36 changes: 21 additions & 15 deletions src/country_workspace/config/fragments/constance.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"
from ..settings import NEW_USER_DEFAULT_GROUP

CONSTANCE_CONFIG = {
"NEW_USER_IS_STAFF": (False, "Set any new user as staff", bool),
"NEW_USER_DEFAULT_GROUP": (
"Default",
"Group to assign to any new user",
str,
),
}
CONSTANCE_BACKEND = "constance.backends.database.DatabaseBackend"


CONSTANCE_CONFIG_FIELDSETS = {
"User settings": {
"fields": ("NEW_USER_IS_STAFF", "NEW_USER_DEFAULT_GROUP"),
"collapse": False,
}
}
# CONSTANCE_CONFIG_FIELDSETS = {
# "User settings": {
# "fields": ("NEW_USER_IS_STAFF", "NEW_USER_DEFAULT_GROUP"),
# "collapse": False,
# }
# }

CONSTANCE_ADDITIONAL_FIELDS = {
"email": [
"django.forms.EmailField",
{},
],
"group_select": [
"country_workspace.utils.constance.GroupSelect",
{"initial": NEW_USER_DEFAULT_GROUP},
],
}

CONSTANCE_CONFIG = {
"NEW_USER_IS_STAFF": (False, "Set NEW_USER_DEFAULT_GROUP new user as staff", bool),
"NEW_USER_DEFAULT_GROUP": (
NEW_USER_DEFAULT_GROUP,
"Group to assign to any new user",
"group_select",
),
}
4 changes: 3 additions & 1 deletion src/country_workspace/config/fragments/debug_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
def show_ddt(request: "HttpRequest") -> bool: # pragma: no-cover
from flags.state import flag_enabled

if request.path in RegexList(("/api/.*", "/dal/.*", "/healthcheck/")):
if request.path in RegexList(
("/api/.*", "/dal/.*", "/healthcheck/", "/autocomplete/")
):
return False
return flag_enabled("DEVELOP_DEBUG_TOOLBAR", request=request)

Expand Down
3 changes: 2 additions & 1 deletion src/country_workspace/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
from .fragments.rest_framework import * # noqa
from .fragments.root import * # noqa
from .fragments.sentry import * # noqa
from .fragments.smart_admin import * # noqa

# from .fragments.smart_admin import * # noqa
from .fragments.social_auth import * # noqa
from .fragments.spectacular import * # noqa
1 change: 1 addition & 0 deletions src/country_workspace/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

urlpatterns = [
path(r"admin/", admin.site.urls),
# path(r"", admin.site.urls),
path(r"", workspace.urls),
path(r"security/", include("unicef_security.urls", namespace="security")),
path(r"social/", include("social_django.urls", namespace="social")),
Expand Down
132 changes: 132 additions & 0 deletions src/country_workspace/management/commands/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.core.management import BaseCommand
from django.utils.text import slugify

from hope_flex_fields.models import DataChecker

from country_workspace.models import Household, Individual
from country_workspace.models.program import Program

Expand Down Expand Up @@ -71,3 +73,133 @@ def handle(self, *args: Any, **options: Any) -> None:
full_name=faker.name(),
flex_fields={},
)
# Create HH Validator
from django import forms

from hope_flex_fields.models import FieldDefinition, Fieldset, FlexField

bool_field = FieldDefinition.objects.get(name="BooleanField")
char_field = FieldDefinition.objects.get(name="CharField")
date_field = FieldDefinition.objects.get(field_type=forms.DateField)
# choice_field = FieldDefinition.objects.get(
# name="ChoiceField", field_type=forms.ChoiceField
# )
gender_field, __ = FieldDefinition.objects.get_or_create(
name="Gender",
attrs={"choices": [["FEMALE", "FEMALE"], ["MALE", "MALE"]]},
field_type=forms.ChoiceField,
)

hh_fs, __ = Fieldset.objects.get_or_create(name="household")
FlexField.objects.get_or_create(
name="household_id", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="consent_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="country_origin_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="country_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="admin1_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="admin2_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="size_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="hh_latrine_h_f", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="hh_electricity_h_f", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="registration_method_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="collect_individual_data_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="name_enumerator_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="org_enumerator_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="consent_sharing_h_c", fieldset=hh_fs, field=char_field
)
FlexField.objects.get_or_create(
name="first_registration_date_h_c", fieldset=hh_fs, field=char_field
)

ind_fs, __ = Fieldset.objects.get_or_create(name="individual")
FlexField.objects.get_or_create(
name="household_id", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="relationship_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="full_name_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="given_name_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="middle_name_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="family_name_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="photo_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="gender_i_c", fieldset=ind_fs, field=gender_field
)

FlexField.objects.get_or_create(
name="birth_date_i_c", fieldset=ind_fs, field=date_field
)
FlexField.objects.get_or_create(
name="estimated_birth_date_i_c", fieldset=ind_fs, field=bool_field
)
FlexField.objects.get_or_create(
name="national_id_no_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="national_id_photo_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="national_id_issuer_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="phone_no_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="primary_collector_id", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="alternate_collector_id", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="first_registration_date_i_c", fieldset=ind_fs, field=char_field
)
FlexField.objects.get_or_create(
name="disability_i_c",
fieldset=ind_fs,
field=FieldDefinition.objects.get(name="ChoiceField"),
attrs={
"choices": [["not disabled", "not disabled"], ["disabled", "disabled"]]
},
)

ds, __ = DataChecker.objects.get_or_create(name="Base Household")
ds.fieldsets.add(hh_fs)
ds, __ = DataChecker.objects.get_or_create(name="Base Individual")
ds.fieldsets.add(ind_fs)
10 changes: 3 additions & 7 deletions src/country_workspace/management/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from typing import TYPE_CHECKING, Any

from django.conf import settings
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
from django.core.management import BaseCommand, call_command
from django.core.management.base import CommandError, SystemCheckError
from django.core.validators import validate_email
from django.utils.text import slugify

from country_workspace.config import env
from country_workspace.utils import get_or_create_defaults_group
from country_workspace.security.utils import setup_workspace_group

if TYPE_CHECKING:
from argparse import ArgumentParser
Expand Down Expand Up @@ -163,9 +162,8 @@ def handle(self, *args: Any, **options: Any) -> None: # noqa
interactive=False,
)

echo("Create default group")
Group.objects.get_or_create(name=settings.ANALYST_GROUP_NAME)
echo("Sync Country Offices")
echo("Setup base security")
setup_workspace_group()
CountryOffice.objects.get_or_create(
slug=slugify(
settings.TENANT_HQ,
Expand All @@ -179,8 +177,6 @@ def handle(self, *args: Any, **options: Any) -> None: # noqa
style_func=self.style.ERROR,
)
echo("Upgrade completed", style_func=self.style.SUCCESS)

get_or_create_defaults_group()
except ValidationError as e:
self.halt(Exception("\n- ".join(["Wrong argument(s):", *e.messages])))
except (CommandError, SystemCheckError) as e:
Expand Down
Loading

0 comments on commit 8abdbf6

Please sign in to comment.