Skip to content

Commit

Permalink
Initial admin interface set-up
Browse files Browse the repository at this point in the history
- add environment callback
- add some Unfold settings
  • Loading branch information
tudoramariei committed Oct 7, 2024
1 parent 3ccc120 commit 9dddf71
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 25 deletions.
36 changes: 31 additions & 5 deletions backend/donations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def queryset(self, request, queryset):

@admin.register(Ngo)
class NgoAdmin(ModelAdmin):
list_display = ("id", "slug", "registration_number", "name")
list_display_links = ("id", "slug", "registration_number", "name")
list_display = ("id", "ngohub_org_id", "slug", "registration_number", "name")
list_display_links = ("id", "ngohub_org_id", "slug", "registration_number", "name")
list_filter = (
"date_created",
"is_verified",
Expand Down Expand Up @@ -112,15 +112,31 @@ class NgoAdmin(ModelAdmin):
),
(
_("Activity"),
{"fields": ("is_verified", "is_active", "is_accepting_forms", "is_social_service_viable")},
{
"fields": (
"is_verified",
"is_active",
"is_accepting_forms",
"is_social_service_viable",
)
},
),
(
_("Logo"),
{"fields": ("logo",)},
),
(
_("Contact"),
{"fields": ("address", "county", "active_region", "phone", "website", "email")},
{
"fields": (
"address",
"county",
"active_region",
"phone",
"website",
"email",
)
},
),
(
_("Details"),
Expand Down Expand Up @@ -217,7 +233,17 @@ class DonorAdmin(ModelAdmin):
),
(
_("Identity"),
{"fields": ("first_name", "last_name", "initial", "county", "city", "email", "phone")},
{
"fields": (
"first_name",
"last_name",
"initial",
"county",
"city",
"email",
"phone",
)
},
),
(
_("Info"),
Expand Down
2 changes: 1 addition & 1 deletion backend/donations/models/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def ngo_id_number_validator(value):
if 2 > len(reg_num) or len(reg_num) > 10:
raise ValidationError(_("The ID number must be between 2 and 10 digits long"))

if not settings.RUN_FULL_CUI_VALIDATION:
if not settings.ENABLE_FULL_CUI_VALIDATION:
return

control_key: str = "753217532"
Expand Down
8 changes: 8 additions & 0 deletions backend/redirectioneaza/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings


def environment_callback(_):
environment = f"{settings.ENVIRONMENT} | {settings.VERSION_SUFFIX}"
log_level = settings.DJANGO_LOG_LEVEL

return environment, log_level
134 changes: 115 additions & 19 deletions backend/redirectioneaza/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from django.templatetags.static import static
from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from localflavor.ro.ro_counties import COUNTIES_CHOICES

# Constants for memory sizes
Expand Down Expand Up @@ -147,7 +148,7 @@
# Google Analytics:
GOOGLE_ANALYTICS_ID=(str, ""),
# App settings
RUN_FULL_CUI_VALIDATION=(bool, True),
ENABLE_FULL_CUI_VALIDATION=(bool, True),
)

environ.Env.read_env(ENV_FILE_PATH)
Expand Down Expand Up @@ -248,6 +249,7 @@
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.humanize",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
Expand Down Expand Up @@ -295,7 +297,10 @@
{
# New templates for v2
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.abspath(os.path.join(BASE_DIR, "templates", "v2"))],
"DIRS": [
os.path.abspath(os.path.join(BASE_DIR, "templates", "v2")),
os.path.abspath(os.path.join(BASE_DIR, "templates", "v3")),
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down Expand Up @@ -615,10 +620,94 @@

CONTACT_EMAIL_ADDRESS = env.str("CONTACT_EMAIL_ADDRESS")


# Unfold Admin settings
# https://unfoldadmin.com/docs/configuration/settings/
# Supported icon set: https://fonts.google.com/icons

SIDEBAR_NAVIGATION = [
# Supported icon set: https://fonts.google.com/icons
{
"title": _("Donations"),
"items": [
{
"title": _("NGOs"),
"icon": "foundation",
"link": reverse_lazy("admin:donations_ngo_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Donations"),
"icon": "edit_document",
"link": reverse_lazy("admin:donations_donor_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Partners"),
"icon": "handshake",
"link": reverse_lazy("admin:partners_partner_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Donation exports"),
"icon": "file_copy",
"link": reverse_lazy("admin:donations_job_changelist"),
"permission": lambda request: request.user.is_superuser,
},
],
},
{
"title": _("Users"),
"items": [
{
"title": _("Users"),
"icon": "person",
"link": reverse_lazy("admin:users_user_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Groups"),
"icon": "group",
"link": reverse_lazy("admin:users_groupproxy_changelist"),
"permission": lambda request: request.user.is_superuser,
},
],
},
{
"title": _("Django Q"),
"items": [
{
"title": _("Failed tasks"),
"icon": "assignment_late",
"link": reverse_lazy("admin:django_q_failure_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Queued tasks"),
"icon": "assignment_add",
"link": reverse_lazy("admin:django_q_ormq_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Scheduled tasks"),
"icon": "assignment",
"link": reverse_lazy("admin:django_q_schedule_changelist"),
"permission": lambda request: request.user.is_superuser,
},
{
"title": _("Successful tasks"),
"icon": "assignment_turned_in",
"link": reverse_lazy("admin:django_q_success_changelist"),
"permission": lambda request: request.user.is_superuser,
},
],
},
]

UNFOLD = {
# https://unfoldadmin.com/docs/configuration/settings/
# Site configuration
"ENVIRONMENT": "redirectioneaza.callbacks.environment_callback",
# Site customization
"SITE_HEADER": f"Admin | {VERSION_LABEL}",
"SITE_TITLE": TITLE,
"SITE_ICON": lambda request: static("images/logo-smaller.png"),
"SITE_LOGO": lambda request: static("images/logo-smaller.png"),
Expand Down Expand Up @@ -659,10 +748,16 @@
950: "#745E06",
},
},
# Sidebar settings
"SIDEBAR": {
"show_search": True,
"show_all_applications": False,
"navigation": SIDEBAR_NAVIGATION,
},
}

# Django Q2
# https://django-q2.readthedocs.io/en/stable/configure.html#configuration

# Django Q2 — https://django-q2.readthedocs.io/en/stable/configure.html#configuration

Q_CLUSTER_WORKERS: int = env.int("DJANGO_Q_WORKERS_COUNT")
Q_CLUSTER_RECYCLE: int = env.int("DJANGO_Q_RECYCLE_RATE")
Expand Down Expand Up @@ -692,7 +787,8 @@
IMPORT_USE_BATCHES = env.bool("IMPORT_USE_BATCHES")
IMPORT_BATCH_SIZE = env.int("IMPORT_BATCH_SIZE")

# reCAPTCHA
# reCAPTCHA & Analytics settings
GOOGLE_ANALYTICS_ID = env.str("GOOGLE_ANALYTICS_ID")

RECAPTCHA_PUBLIC_KEY = env.str("CAPTCHA_PUBLIC_KEY")
RECAPTCHA_PRIVATE_KEY = env.str("CAPTCHA_PRIVATE_KEY")
Expand All @@ -706,23 +802,29 @@
if DEBUG or not RECAPTCHA_ENABLED:
SILENCED_SYSTEM_CHECKS = ["django_recaptcha.recaptcha_test_key_error"]

ENABLE_FORMS_DOWNLOAD = env.bool("ENABLE_FORMS_DOWNLOAD", True)
TIMEDELTA_FORMS_DOWNLOAD_MINUTES = env.int("TIMEDELTA_FORMS_DOWNLOAD_MINUTES")


# encryption
# Encryption settings
ENCRYPT_KEY = env.str("ENCRYPT_KEY", "%INVALID%")
if len(ENCRYPT_KEY) != 32 or ENCRYPT_KEY == "%INVALID%":
raise Exception("ENCRYPT_KEY must be exactly 32 characters long")
FERNET_OBJECT = Fernet(urlsafe_b64encode(ENCRYPT_KEY.encode("utf-8")))


GOOGLE_ANALYTICS_ID = env.str("GOOGLE_ANALYTICS_ID")

# Feature flags
ENABLE_FLAG_CONTACT = env.bool("ENABLE_FLAG_CONTACT", False)

# Configurations for the NGO Hub integration
UPDATE_ORGANIZATION_METHOD = env("UPDATE_ORGANIZATION_METHOD")

# Other settings
ENABLE_FULL_CUI_VALIDATION = env.bool("ENABLE_FULL_CUI_VALIDATION")

# Form download settings
ENABLE_FORMS_DOWNLOAD = env.bool("ENABLE_FORMS_DOWNLOAD", True)
TIMEDELTA_FORMS_DOWNLOAD_MINUTES = env.int("TIMEDELTA_FORMS_DOWNLOAD_MINUTES")


# Login & Auth settings
LOGIN_URL = reverse_lazy("login")
LOGIN_REDIRECT_URL = reverse_lazy("home")
LOGOUT_REDIRECT_URL = reverse_lazy("home")
Expand Down Expand Up @@ -769,9 +871,3 @@
NGOHUB_ROLE_SUPER_ADMIN = "super-admin"
NGOHUB_ROLE_NGO_ADMIN = "admin"
NGOHUB_ROLE_NGO_EMPLOYEE = "employee"

# Configurations for the NGO Hub integration
UPDATE_ORGANIZATION_METHOD = env("UPDATE_ORGANIZATION_METHOD")

# Other settings
RUN_FULL_CUI_VALIDATION = env.bool("RUN_FULL_CUI_VALIDATION")
24 changes: 24 additions & 0 deletions backend/templates/v3/admin/announcements/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load i18n %}

<div class="flex flex-col gap-4 lg:flex-row lg:items-center">
<div class="flex flex-col">
<strong class="block font-semibold">
{% block announcement_title %}{% endblock %}
</strong>

<p class="leading-relaxed max-w-3xl mt-2">
{% block announcement_description %}{% endblock %}
</p>
</div>

{% block announcement_cta %}
<div class="lg:ml-auto">
<a
href="{% block announcement_cta_url %}{% endblock %}"
class="bg-white shadow-sm block border border-transparent font-semibold px-3 py-2 rounded-md text-sm text-center text-blue-700 w-full whitespace-nowrap lg:w-auto dark:bg-blue-500/20 dark:text-white"
target="_blank">
{% block announcement_cta_text %}{% endblock %}
</a>
</div>
{% endblock %}
</div>
15 changes: 15 additions & 0 deletions backend/templates/v3/admin/announcements/work_in_progress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "admin/announcements/base.html" %}

{% load i18n %}

{% block announcement_title %}
{% trans "Work in progress" %}
{% endblock %}

{% block announcement_description %}
{% trans "The site is still a work in progress. If you have any feedback, please let us know" %}
{% endblock %}

{% block announcement_cta_url %}mailto:{{ contact_email }}{% endblock %}

{% block announcement_cta_text %}{% trans "Contact us" %}{% endblock %}
25 changes: 25 additions & 0 deletions backend/templates/v3/admin/base_admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'admin/base.html' %}

{% load cache humanize i18n %}

{% block breadcrumbs %}{{ block.super }}{% endblock %}

{% block title %}
{% if subtitle %}
{{ subtitle }} |
{% endif %}

{{ title }} | {{ site_title|default:_('Django site admin') }}
{% endblock %}

{% block branding %}
<h1 id="site-name">
<a href="{% url 'admin:index' %}">
{{ site_header|default:_('Django administration') }}
</a>
</h1>
{% endblock %}

{% block content %}
{% include "unfold/helpers/messages.html" %}
{% endblock %}
38 changes: 38 additions & 0 deletions backend/templates/v3/admin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends 'admin/base_admin.html' %}

{% load unfold i18n %}

{% block content %}
{% component "unfold/components/container.html" %}

{% component "unfold/components/flex.html" with class="gap-4" %}
{% component "unfold/components/navigation.html" with items=navigation %}{% endcomponent %}

{% component "redirect/components/dropdown_navigation.html" with class="ml-auto" items=filters title="AAAAA" %}{% endcomponent %}
{% endcomponent %}

{% component "unfold/components/flex.html" with class="gap-8 mb-8 flex-col lg:flex-row" %}
{% for stat in stats %}
{% component "redirect/components/card.html" with class="lg:w-1/3" label=stat.label footer=stat.footer footer_class=stat.footer_class %}
{% component "unfold/components/title.html" %}
{{ stat.metric }}
{% endcomponent %}

{% component "unfold/components/text.html" %}
{{ stat.title }}
{% endcomponent %}
{% endcomponent %}
{% endfor %}
{% endcomponent %}

{% endcomponent %}


<h2>
{{ page_title }}
</h2>
<p>
{{ page_description }}
</p>

{% endblock %}
Loading

0 comments on commit 9dddf71

Please sign in to comment.