Skip to content

Commit

Permalink
Add admin generate-donations archive
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed May 28, 2024
1 parent 03d1f91 commit 2dd899c
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 48 deletions.
38 changes: 36 additions & 2 deletions backend/donations/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import logging
from typing import List

from django.contrib import admin
from django.core.management import call_command
from django.db.models import QuerySet
from django.urls import reverse
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _

from redirectioneaza.common.admin import HasNgoFilter
from .models.jobs import Job
from .models.main import Donor, Ngo
from users.models import User
from .models.jobs import Job, JobStatusChoices
from .models.main import Donor, Ngo

logger = logging.getLogger(__name__)


class NgoPartnerInline(admin.TabularInline):
Expand Down Expand Up @@ -84,6 +91,8 @@ class NgoAdmin(admin.ModelAdmin):

readonly_fields = ("date_created", "date_updated", "get_donations_link")

actions = ("generate_donations_archive",)

fieldsets = (
(
_("Donations"),
Expand Down Expand Up @@ -123,6 +132,31 @@ def get_donations_link(self, obj: Ngo):
f'<a data-popup="yes" id="ngo_donor_list" class="related-widget-wrapper-link" href="{link_url}?ngo_id={obj.id}&_popup=1" target="_blank">{link_name}</a>'
)

@admin.action(description=_("Generate donations archive"))
def generate_donations_archive(self, request, queryset: QuerySet[Ngo]):
ngo_names: List[str] = []

for ngo in queryset:
new_job: Job = Job(ngo=ngo, owner=request.user)
new_job.save()

try:
call_command("download_donations", new_job.id)

ngo_names.append(f"{ngo.id} - {ngo.name}")
except Exception as e:
logger.error(e)

new_job.status = JobStatusChoices.ERROR
new_job.save()

if ngo_names:
message = _("The donations archive has been generated for the following NGOs: ") + ", ".join(ngo_names)
else:
message = _("The donations archive could not be generated for any of the selected NGOs.")

self.message_user(request, message)


@admin.register(Donor)
class DonorAdmin(admin.ModelAdmin):
Expand Down
59 changes: 36 additions & 23 deletions backend/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-23 16:34+0300\n"
"POT-Creation-Date: 2024-05-28 10:06+0300\n"
"PO-Revision-Date: 2024-02-28 15:45+0000\n"
"Last-Translator: Tudor Amariei <[email protected]>\n"
"Language-Team: English <https://translate.commitglobal.org/projects/act4good/"
Expand All @@ -19,85 +19,98 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.3.1\n"

#: donations/admin.py:29
#: donations/admin.py:36
msgid "User Link"
msgstr "User Link"

#: donations/admin.py:33
#: donations/admin.py:40
msgid "User Details"
msgstr "User Details"

#: donations/admin.py:37
#: donations/admin.py:44
msgid "User Permissions"
msgstr "User Permissions"

#: donations/admin.py:45
#: donations/admin.py:52
msgid "User"
msgstr "User"

#: donations/admin.py:52
#: donations/admin.py:59
msgid "Has owner"
msgstr "Has owner"

#: donations/admin.py:56
#: donations/admin.py:63
msgid "Yes"
msgstr "Yes"

#: donations/admin.py:56
#: donations/admin.py:63
msgid "No"
msgstr "No"

#: donations/admin.py:89 donations/admin.py:118
#: donations/admin.py:98 donations/admin.py:127
msgid "Donations"
msgstr "Donations"

#: donations/admin.py:93 donations/admin.py:150 donations/admin.py:190
#: donations/admin.py:102 donations/admin.py:182 donations/admin.py:222
#: donations/models/jobs.py:28 donations/models/main.py:234
#: donations/models/main.py:294 partners/admin.py:11 users/models.py:70
msgid "NGO"
msgstr "NGO"

#: donations/admin.py:97
#: donations/admin.py:106
msgid "Activity"
msgstr "Activity"

#: donations/admin.py:101
#: donations/admin.py:110
msgid "Logo"
msgstr "Logo"

#: donations/admin.py:105
#: donations/admin.py:114
msgid "Contact"
msgstr "Contact"

#: donations/admin.py:109
#: donations/admin.py:118
msgid "Details"
msgstr "Details"

#: donations/admin.py:113 donations/admin.py:166 donations/admin.py:202
#: donations/admin.py:122 donations/admin.py:198 donations/admin.py:234
msgid "Date"
msgstr "Date"

#: donations/admin.py:120
#: donations/admin.py:129
msgid "Open the NGO donor list"
msgstr "Open the NGO donor list"

#: donations/admin.py:154
#: donations/admin.py:135
msgid "Generate donations archive"
msgstr ""

#: donations/admin.py:153
msgid "The donations archive has been generated for the following NGOs: "
msgstr ""

#: donations/admin.py:155
msgid ""
"The donations archive could not be generated for any of the selected NGOs."
msgstr ""

#: donations/admin.py:186
msgid "Identity"
msgstr "Identity"

#: donations/admin.py:158
#: donations/admin.py:190
msgid "Info"
msgstr "Info"

#: donations/admin.py:162 donations/admin.py:198 importer/models.py:28
#: donations/admin.py:194 donations/admin.py:230 importer/models.py:28
msgid "File"
msgstr "File"

#: donations/admin.py:174
#: donations/admin.py:206
msgid "Form"
msgstr "Form"

#: donations/admin.py:194 importer/models.py:24
#: donations/admin.py:226 importer/models.py:24
msgid "Status"
msgstr "Status"

Expand Down Expand Up @@ -470,11 +483,11 @@ msgstr "The IBAN number must contain only letters and digits"
msgid "The IBAN number must start with 'RO'"
msgstr "The IBAN number must start with 'RO'"

#: donations/views/ngo.py:148 donations/views/ngo.py:393
#: donations/views/ngo.py:152 donations/views/ngo.py:397
msgid "Formularul tău de redirecționare"
msgstr "Formularul tău de redirecționare"

#: donations/views/ngo.py:155
#: donations/views/ngo.py:159
msgid "Un nou formular de redirecționare"
msgstr "Un nou formular de redirecționare"

Expand Down
61 changes: 38 additions & 23 deletions backend/locale/ro/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-23 16:34+0300\n"
"POT-Creation-Date: 2024-05-28 10:06+0300\n"
"PO-Revision-Date: 2024-03-07 11:27+0000\n"
"Last-Translator: Tudor Amariei <[email protected]>\n"
"Language-Team: Romanian <https://translate.commitglobal.org/projects/"
Expand All @@ -20,85 +20,100 @@ msgstr ""
"20)) ? 1 : 2;\n"
"X-Generator: Weblate 5.3.1\n"

#: donations/admin.py:29
#: donations/admin.py:36
msgid "User Link"
msgstr "Link utilizator"

#: donations/admin.py:33
#: donations/admin.py:40
msgid "User Details"
msgstr "Detalii utilizator"

#: donations/admin.py:37
#: donations/admin.py:44
msgid "User Permissions"
msgstr "Permisiuni utilizator"

#: donations/admin.py:45
#: donations/admin.py:52
msgid "User"
msgstr "Utilizator"

#: donations/admin.py:52
#: donations/admin.py:59
msgid "Has owner"
msgstr "Are utilizator"

#: donations/admin.py:56
#: donations/admin.py:63
msgid "Yes"
msgstr "Da"

#: donations/admin.py:56
#: donations/admin.py:63
msgid "No"
msgstr "Nu"

#: donations/admin.py:89 donations/admin.py:118
#: donations/admin.py:98 donations/admin.py:127
msgid "Donations"
msgstr "Donații"

#: donations/admin.py:93 donations/admin.py:150 donations/admin.py:190
#: donations/admin.py:102 donations/admin.py:182 donations/admin.py:222
#: donations/models/jobs.py:28 donations/models/main.py:234
#: donations/models/main.py:294 partners/admin.py:11 users/models.py:70
msgid "NGO"
msgstr "ONG"

#: donations/admin.py:97
#: donations/admin.py:106
msgid "Activity"
msgstr "Activitate"

#: donations/admin.py:101
#: donations/admin.py:110
msgid "Logo"
msgstr "Logo"

#: donations/admin.py:105
#: donations/admin.py:114
msgid "Contact"
msgstr "Contact"

#: donations/admin.py:109
#: donations/admin.py:118
msgid "Details"
msgstr "Detalii"

#: donations/admin.py:113 donations/admin.py:166 donations/admin.py:202
#: donations/admin.py:122 donations/admin.py:198 donations/admin.py:234
msgid "Date"
msgstr "Data"

#: donations/admin.py:120
#: donations/admin.py:129
msgid "Open the NGO donor list"
msgstr "Deschide lista de donatori pentru acest ONG"

#: donations/admin.py:154
#: donations/admin.py:135
msgid "Generate donations archive"
msgstr "Generează arhiva de donații"

#: donations/admin.py:153
msgid "The donations archive has been generated for the following NGOs: "
msgstr "Arhiva de donații a fost generată pentru următoarele ONG-uri: "

#: donations/admin.py:155
msgid ""
"The donations archive could not be generated for any of the selected NGOs."
msgstr ""
"Arhiva de donații nu a putut fi generată pentru niciunul dintre ONG-urile "
"selectate."

#: donations/admin.py:186
msgid "Identity"
msgstr "Identitate"

#: donations/admin.py:158
#: donations/admin.py:190
msgid "Info"
msgstr "Info"

#: donations/admin.py:162 donations/admin.py:198 importer/models.py:28
#: donations/admin.py:194 donations/admin.py:230 importer/models.py:28
msgid "File"
msgstr "Fișier"

#: donations/admin.py:174
#: donations/admin.py:206
msgid "Form"
msgstr "Formular"

#: donations/admin.py:194 importer/models.py:24
#: donations/admin.py:226 importer/models.py:24
msgid "Status"
msgstr "Stare"

Expand Down Expand Up @@ -471,11 +486,11 @@ msgstr "IBAN-ul trebuie să conțină doar litere și cifre"
msgid "The IBAN number must start with 'RO'"
msgstr "IBAN-ul trebuie să înceapă cu 'RO'"

#: donations/views/ngo.py:148 donations/views/ngo.py:393
#: donations/views/ngo.py:152 donations/views/ngo.py:397
msgid "Formularul tău de redirecționare"
msgstr "Formularul tău de redirecționare"

#: donations/views/ngo.py:155
#: donations/views/ngo.py:159
msgid "Un nou formular de redirecționare"
msgstr "Un nou formular de redirecționare"

Expand Down

0 comments on commit 2dd899c

Please sign in to comment.