Skip to content
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
69 changes: 9 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
ABOUT HOPE Country Report
HOPE Country Report
=========================


## Contributing
[![Ci Status](https://github.com/unicef/hope-country-report/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/unicef/hope-country-report/actions/workflows/ci.yml)
[![codecov](https://codecov.io/github/unicef/hope-country-report/graph/badge.svg)](https://codecov.io/github/unicef/hope-country-report)
[![Documentation](https://github.com/unicef/hope-country-report/actions/workflows/docs.yml/badge.svg)](https://unicef.github.io/hope-country-report/)
[![Docker Pulls](https://img.shields.io/docker/pulls/unicef/hope-country-report)](https://hub.docker.com/r/unicef/hope-country-report/tags)

### System Requirements
Hope Country Report (HCR) is a pivotal component within the Hope platform, specifically designed to empower UNICEF country offices with the ability to generate customized reports tailored to their unique requirements.

- python 3.12
- [direnv](https://direnv.net/) - not mandatory but strongly recommended
- [uv](https://docs.astral.sh/uv/)

## Configure development environment
## Documentation

**WARNING**
> HCR implements **security first** policy. It means that configuration default values are "almost" production compliant.
>
> Es. `DEBUG=False` or `SECURE_SSL_REDIRECT=True`.
>
> Be sure to run `./manage.py env --check` and `./manage.py env -g all` to check and display your configuration



### 1. Clone repo and install requirements
git clone https://github.com/unicef/hope-country-report
cd hope-country-report
uv sync

### 2. configure your environment

Uses `./manage.py env` to configure your environment

./manage.py env > .evnvrc

Customize your env for development:

export DEBUG=True
export SESSION_COOKIE_NAME="hcr_test_session"
export SESSION_COOKIE_DOMAIN=""
export SESSION_COOKIE_SECURE=False
export SECURE_HSTS_SECONDS=0
export SECURE_HSTS_PRELOAD=False
export CSRF_COOKIE_SECURE=False
export SECURE_SSL_REDIRECT=False
export CELERY_TASK_ALWAYS_EAGER=True
export AUTHENTICATION_BACKENDS="hope_country_report.utils.tests.backends.AnyUserAuthBackend"
export SIGNING_BACKEND="hope_country_report.utils.signer.DebugSigner"


and check required (and optional) variables to put

./manage.py env --check


### 3. Run upgrade to run migrations and initial setup

./manage.py upgrade

### 4. (Optional) Create some sample data

./manage.py demo

> If `DEBUG=True` and `AUTHENTICATION_BACKENDS="hope_country_report.utils.tests.backends.AnyUserAuthBackend"` you can login using any username/password. Note that:

> - If the username is ADMIN_EMAIL you will be superuser
> - If username starts with `admin` will be created a superuser
> - If username starts with `user` will be created a standard user (no staff, no admin)
- Documentation: https://unicef.github.io/hope-country-report/
- Tutorials : https://unicef.github.io/hope-country-report/tutorials/
2 changes: 1 addition & 1 deletion docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BASE_IMAGE?=hope-contry-report
CHECKSUM?=$(shell sha1sum ../pdm.lock | awk '{print $$1}')
CHECKSUM?=$(shell sha1sum ../uv.lock | awk '{print $$1}')
LOCK_SHA?=$(shell echo ${CHECKSUM} | cut -c 1-8)
COMMIT_SHA?=$(shell git rev-parse --short HEAD)
VERSION?=dev
Expand Down
10 changes: 3 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[project]
name = "hcr"
version = "0.1"
description = ""
description = "Hope Country Report for displaying Hope data"
authors = [
{name = "sax", email = "s.apostolico@gmail.com"},
{name = "stockman", email = "kuristockyrugano@gmail.com"},
]
readme = "README.md"
license = {text = "Private"}
license = {text = "MIT"}
requires-python = ">=3.12"

dependencies = [
Expand Down Expand Up @@ -99,11 +100,8 @@ dependencies = [
select = ["E4", "E7", "E9", "F"]
ignore = ["F403",]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff]
Expand Down Expand Up @@ -131,11 +129,9 @@ exclude = [
"venv",
]

# Same as Black.
line-length = 120
indent-width = 4

# Assume Python 3.12
target-version = "py312"

[tool.isort]
Expand Down
52 changes: 2 additions & 50 deletions src/hope_country_report/apps/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Any, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING

from django import forms
from django.contrib import admin
from django.db.models.fields.json import JSONField
from django.http import HttpRequest
from django.utils.translation import gettext_lazy as _

from admin_extra_buttons.decorators import button
from admin_extra_buttons.mixins import ExtraButtonsMixin
Expand All @@ -27,53 +25,7 @@ class BaseAdmin(DisplayAllMixin, ExtraButtonsMixin, admin.ModelAdmin): # type:

@admin.register(User)
class UserAdmin(_UserAdminPlus): # type: ignore
fieldsets = (
(None, {"fields": (("username", "azure_id"), "password")}),
(
_("Preferences"),
{
"fields": (
(
"language",
"timezone",
),
("date_format", "time_format"),
)
},
),
(
_("Personal info"),
{
"fields": (
(
"first_name",
"last_name",
),
("email", "display_name"),
("job_title",),
)
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)

def get_fieldsets(self, request: HttpRequest, obj: Optional[Any] = None) -> Any:
if not obj:
return self.add_fieldsets
fieldsets = list(_UserAdminPlus.fieldsets)
if request.user.is_superuser:
fieldsets.append(
(
_("Admin"),
{
"fields": (
"is_staff",
"groups",
)
},
)
)
return fieldsets
pass


class UserRoleForm(forms.ModelForm): # type: ignore
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ setenv =
PYTHONPATH={toxinidir}/src

deps =
pdm
uv

allowlist_externals =
mkdir

commands =
pdm install
pdm run pytest tests \
uv sync
uv run pytest tests \
-v \
--create-db \
--echo-version django
Expand All @@ -36,12 +36,12 @@ commands =

[testenv:package]
deps =
pdm
uv

setenv =
DJANGO_SETTINGS_MODULE=hope_country_report.config.settings
SECRET_KEY=super-secret-key

commands =
pdm sync --prod
uv sync
python -c "import django; django.setup(); from pkgutil import walk_packages; [loader.find_module(modname).load_module(modname) for loader, modname, _ in walk_packages(['./src/'])]"