Skip to content

Commit

Permalink
Add a button to refresh the NGO information
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Oct 3, 2024
1 parent d747d20 commit f018421
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 16 additions & 0 deletions backend/donations/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@
from ..models.jobs import Job, JobStatusChoices
from ..models.main import ALL_NGOS_CACHE_KEY, Ngo
from ..pdf import create_pdf
from ..workers.update_organization import update_organization

logger = logging.getLogger(__name__)


class UpdateFromNgohub(BaseAccountView):
def post(self, request, *args, **kwargs):
redirect_success = redirect(reverse("organization"))
redirect_error = redirect(reverse("organization"))

user = request.user

if not user.ngo or not user.ngo.is_active:
return redirect_error

update_organization(user.ngo.pk)

return redirect_success


class CheckNgoUrl(BaseAccountView):
ngo_url_block_list = (
"",
Expand Down
3 changes: 2 additions & 1 deletion backend/redirectioneaza/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
AdminNgosListByName,
UserAccounts,
)
from donations.views.api import CheckNgoUrl, GetNgoForm, GetNgoForms, GetUploadUrl, NgosApi
from donations.views.api import CheckNgoUrl, GetNgoForm, GetNgoForms, GetUploadUrl, NgosApi, UpdateFromNgohub
from donations.views.cron import CustomExport, NgoExport, NgoRemoveForms, Stats
from donations.views.my_account import (
ArchiveDownloadLinkView,
Expand Down Expand Up @@ -120,6 +120,7 @@
name="error-unknown-user-role",
),
# APIs
path("api/ngohub-refresh/", UpdateFromNgohub.as_view(), name="api-ngohub-refresh"),
path("api/ngo/check-url/<ngo_url>/", CheckNgoUrl.as_view(), name="api-ngo-check-url"),
path("api/ngos/", NgosApi.as_view(), name="api-ngos"),
#
Expand Down
24 changes: 23 additions & 1 deletion backend/templates/v1/components/ngo-details-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@

<h1>Datele organizației</h1>

<div class="col-xs-12">
{% if has_ngohub %}
<div class="col-xs-2">
<button
class="btn btn-link"
type="submit"
formaction="{{ reverse('api-ngohub-refresh') }}"
name="refresh-with-ngohub"
formmethod="post"
>
<i
class="fa fa-refresh fa-5x refresh-button"
aria-hidden="true"
aria-label="Actualizează informațiile cu cele din NGO Hub"
>

</i>

</button>

</div>
{% endif %}

<div class="{% if has_ngohub %}col-xs-10{% else %}col-xs-12{% endif %}">

<p>
Aici poți introduce datele organizației tale. Acestea vor fi folosite pentru a completa formularul de donații.
Expand Down

0 comments on commit f018421

Please sign in to comment.