Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWPF-1473 Update python packages #496

Merged
merged 6 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- uses: actions/setup-node@v4
with:
Expand All @@ -34,8 +34,8 @@ jobs:
- name: Collect static
run: make collectstatic

- name: Run Flake8
run: make flake8
- name: Run ruff
run: make ruff

- name: Run isort
run: make isort-check
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 20.11.1
python 3.10.13
python 3.12.2
64 changes: 40 additions & 24 deletions chartofaccountDIT/exportcsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,36 @@ def _export_nac_iterator(queryset):
obj.natural_account_code_description,
] + l5_field_obj(obj.account_L5_code) + [
obj.used_for_budget,
obj.expenditure_category.NAC_category.NAC_category_description
if obj.expenditure_category
else "-",
obj.expenditure_category.grouping_description
if obj.expenditure_category
else "-",
obj.commercial_category.commercial_category
if obj.commercial_category
else "N/A",
obj.expenditure_category.op_del_category.operating_delivery_description
if obj.expenditure_category and obj.expenditure_category.op_del_category
else "N/A",
obj.expenditure_category.linked_budget_code.natural_account_code
if obj.expenditure_category
else "-",
obj.expenditure_category.NAC_category.get_pay_nonpay_display()
if obj.expenditure_category
else "N/A",
(
obj.expenditure_category.NAC_category.NAC_category_description
if obj.expenditure_category
else "-"
),
(
obj.expenditure_category.grouping_description
if obj.expenditure_category
else "-"
),
(
obj.commercial_category.commercial_category
if obj.commercial_category
else "N/A"
),
(
obj.expenditure_category.op_del_category.operating_delivery_description
if obj.expenditure_category and obj.expenditure_category.op_del_category
else "N/A"
),
(
obj.expenditure_category.linked_budget_code.natural_account_code
if obj.expenditure_category
else "-"
),
(
obj.expenditure_category.NAC_category.get_pay_nonpay_display()
if obj.expenditure_category
else "N/A"
),
obj.get_cash_non_cash_display(),
obj.get_gross_income_display(),
obj.active,
Expand Down Expand Up @@ -81,9 +93,11 @@ def _export_historical_nac_iterator(queryset):
obj.natural_account_code,
obj.natural_account_code_description,
obj.used_for_budget,
obj.expenditure_category.grouping_description
if obj.expenditure_category
else "-",
(
obj.expenditure_category.grouping_description
if obj.expenditure_category
else "-"
),
obj.NAC_category,
obj.commercial_category,
obj.account_L5_code,
Expand Down Expand Up @@ -117,9 +131,11 @@ def _export_exp_cat_iterator(queryset):
obj.further_description,
obj.linked_budget_code.natural_account_code,
obj.linked_budget_code.natural_account_code_description,
obj.op_del_category.operating_delivery_description
if obj.op_del_category
else "-",
(
obj.op_del_category.operating_delivery_description
if obj.op_del_category
else "-"
),
]


Expand Down
42 changes: 21 additions & 21 deletions chartofaccountDIT/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)


class Analysis1Factory(factory.DjangoModelFactory):
class Analysis1Factory(factory.django.DjangoModelFactory):
"""
Define Analysis1 Factory
"""
Expand All @@ -37,12 +37,12 @@ class Meta:
active = True


class HistoricalAnalysis1Factory(factory.DjangoModelFactory):
class HistoricalAnalysis1Factory(factory.django.DjangoModelFactory):
class Meta:
model = ArchivedAnalysis1


class Analysis2Factory(factory.DjangoModelFactory):
class Analysis2Factory(factory.django.DjangoModelFactory):
"""
Define Analysis2 Factory
"""
Expand All @@ -53,12 +53,12 @@ class Meta:
active = True


class HistoricalAnalysis2Factory(factory.DjangoModelFactory):
class HistoricalAnalysis2Factory(factory.django.DjangoModelFactory):
class Meta:
model = ArchivedAnalysis2


class NACCategoryFactory(factory.DjangoModelFactory):
class NACCategoryFactory(factory.django.DjangoModelFactory):
"""
Define NACCategory Factory
"""
Expand All @@ -69,7 +69,7 @@ class Meta:
NAC_category_description = factory.Faker("name")


class OperatingDeliveryCategoryFactory(factory.DjangoModelFactory):
class OperatingDeliveryCategoryFactory(factory.django.DjangoModelFactory):
"""
Define OperatingDeliveryCategory Factory
"""
Expand All @@ -78,7 +78,7 @@ class Meta:
model = OperatingDeliveryCategory


class ExpenditureCategoryFactory(factory.DjangoModelFactory):
class ExpenditureCategoryFactory(factory.django.DjangoModelFactory):
"""
Define ExpenditureCategory Factory
"""
Expand All @@ -90,14 +90,14 @@ class Meta:
model = ExpenditureCategory


class HistoricalExpenditureCategoryFactory(factory.DjangoModelFactory):
class HistoricalExpenditureCategoryFactory(factory.django.DjangoModelFactory):
grouping_description = "Test Archived Budget Category"

class Meta:
model = ArchivedExpenditureCategory


class CommercialCategoryFactory(factory.DjangoModelFactory):
class CommercialCategoryFactory(factory.django.DjangoModelFactory):
"""
Define CommercialCategory Factory
"""
Expand All @@ -108,14 +108,14 @@ class Meta:
model = CommercialCategory


class HistoricalCommercialCategoryFactory(factory.DjangoModelFactory):
class HistoricalCommercialCategoryFactory(factory.django.DjangoModelFactory):
active = True

class Meta:
model = ArchivedCommercialCategory


class NaturalCodeFactory(factory.DjangoModelFactory):
class NaturalCodeFactory(factory.django.DjangoModelFactory):
"""
Define NaturalCode Factory
"""
Expand All @@ -130,7 +130,7 @@ class Meta:
used_for_budget = False


class HistoricalNaturalCodeFactory(factory.DjangoModelFactory):
class HistoricalNaturalCodeFactory(factory.django.DjangoModelFactory):

active = True
natural_account_code = 87654321
Expand All @@ -141,7 +141,7 @@ class Meta:
model = ArchivedNaturalCode


class ProgrammeCodeFactory(factory.DjangoModelFactory):
class ProgrammeCodeFactory(factory.django.DjangoModelFactory):
"""
Define ProgrammeCode Factory
"""
Expand All @@ -156,7 +156,7 @@ class Meta:
budget_type = factory.Iterator(BudgetType.objects.all())


class HistoricalProgrammeCodeFactory(factory.DjangoModelFactory):
class HistoricalProgrammeCodeFactory(factory.django.DjangoModelFactory):
"""
Define ArchivedProgrammeCode Factory
"""
Expand All @@ -170,7 +170,7 @@ class Meta:
model = ArchivedProgrammeCode


class InterEntityL1Factory(factory.DjangoModelFactory):
class InterEntityL1Factory(factory.django.DjangoModelFactory):
"""
Define InterEntityL1 Factory
"""
Expand All @@ -179,7 +179,7 @@ class Meta:
model = InterEntityL1


class InterEntityFactory(factory.DjangoModelFactory):
class InterEntityFactory(factory.django.DjangoModelFactory):
"""
Define InterEntity Factory
"""
Expand All @@ -191,14 +191,14 @@ class Meta:
model = InterEntity


class HistoricalInterEntityFactory(factory.DjangoModelFactory):
class HistoricalInterEntityFactory(factory.django.DjangoModelFactory):
active = True

class Meta:
model = ArchivedInterEntity


class ProjectCodeFactory(factory.DjangoModelFactory):
class ProjectCodeFactory(factory.django.DjangoModelFactory):
"""
Define ProjectCode Factory
"""
Expand All @@ -212,7 +212,7 @@ class Meta:
project_description = "Project Description"


class HistoricalProjectCodeFactory(factory.DjangoModelFactory):
class HistoricalProjectCodeFactory(factory.django.DjangoModelFactory):
"""
Define ArchivedProjectCode Factory
"""
Expand All @@ -225,7 +225,7 @@ class Meta:
model = ArchivedProjectCode


class FCOMappingFactory(factory.DjangoModelFactory):
class FCOMappingFactory(factory.django.DjangoModelFactory):
"""
Define FCOMapping Factory
"""
Expand All @@ -238,7 +238,7 @@ class Meta:
model = FCOMapping


class HistoricalFCOMappingFactory(factory.DjangoModelFactory):
class HistoricalFCOMappingFactory(factory.django.DjangoModelFactory):
"""
Define ArchivedFCOMapping Factory
"""
Expand Down
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
BASE_DIR = Path(__file__).resolve().parent.parent.parent

env = environ.Env()
env.read_env()
environ.Env.read_env(BASE_DIR / ".env")

DEBUG = env.bool("DEBUG", default=False)

Expand Down
5 changes: 1 addition & 4 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": CELERY_BROKER_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "cache_",
}
}
Expand Down
5 changes: 1 addition & 4 deletions config/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": CELERY_BROKER_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "cache_",
}
}
Expand Down
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.conf import settings
from django.contrib import admin
from django.urls import include, path
Expand Down
27 changes: 18 additions & 9 deletions core/import_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def add_position(d, h):
dictionary inside"""
c = {}
for k, v in d.items():
if type(v) is dict:
if isinstance(v, dict):
c[k] = add_position(v, h)
else:
if type(v) is str:
if isinstance(v, str):
v = v.lower()
if v in h:
c[k] = h[v]
Expand Down Expand Up @@ -145,7 +145,7 @@ def read_csv_from_dict(d, row, year):

default_list = {}
for k, v in d[IMPORT_CSV_FIELDLIST_KEY].items():
if type(v) is dict:
if isinstance(v, dict):
default_list[k], errormsg = read_csv_from_dict(v, row, year)
else:
default_list[k] = get_value_from_field(
Expand Down Expand Up @@ -185,8 +185,8 @@ def get_col_from_obj_key(obj_key):
if IMPORT_CSV_IS_FK in obj_key:
header_list.append(obj_key[IMPORT_CSV_IS_FK])
if IMPORT_CSV_FIELDLIST_KEY in obj_key:
for k, v in obj_key[IMPORT_CSV_FIELDLIST_KEY].items():
if type(v) is dict:
for _, v in obj_key[IMPORT_CSV_FIELDLIST_KEY].items():
if isinstance(v, dict):
header_list = header_list + get_col_from_obj_key(v)
else:
header_list.append(v)
Expand Down Expand Up @@ -254,13 +254,22 @@ class ImportInfo:

def __init__(
self,
key={},
key=None,
title="",
h_list=[],
h_list=None,
special_import_func=None,
filter=[],
filter=None,
extra_func=None,
):
if key is None:
key = {}

if h_list is None:
h_list = []

if filter is None:
filter = []

self.key = key
self.special_func = special_import_func
if bool(key):
Expand Down Expand Up @@ -328,7 +337,7 @@ def get_field_name(obj_key, prefix):
field_list.append(prefix + model._meta.pk.name)
if IMPORT_CSV_FIELDLIST_KEY in obj_key:
for k, v in obj_key[IMPORT_CSV_FIELDLIST_KEY].items():
if type(v) is dict:
if isinstance(v, dict):
field_list = field_list + get_field_name(v, prefix + k + "__")
else:
field_list.append(prefix + k)
Expand Down
Loading