Skip to content

Commit

Permalink
Implement the My Account page
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Jan 4, 2024
1 parent 568dcf4 commit f2280b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
22 changes: 20 additions & 2 deletions backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from collections import OrderedDict

from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.db.models import Q, QuerySet
from django.shortcuts import render
from django.utils import timezone
from django.utils.decorators import method_decorator

from ..models import Ngo
from ..models import Donor, Ngo
from .base import AccountHandler


Expand Down Expand Up @@ -31,9 +36,22 @@ class MyAccountHandler(AccountHandler):
template_name = "ngo/my-account.html"

def get(self, request, *args, **kwargs):
user_ngo: Ngo = request.user.ngo if request.user.ngo else None
donors: QuerySet[Donor] = Donor.objects.filter(Q(ngo=user_ngo)).order_by("-date_created")

years = range(timezone.now().year, settings.START_YEAR, -1)

grouped_donors = OrderedDict()
for donor in donors:
index = donor.date_created.year
if index in years:
grouped_donors[index].append(donor)

context = {
"user": request.user,
"ngo": request.user.ngo if request.user.ngo else None,
"limit": settings.DONATIONS_LIMIT,
"ngo": user_ngo,
"donors": grouped_donors,
}
return render(request, self.template_name, context)

Expand Down
2 changes: 1 addition & 1 deletion backend/templates/v1/components/ngo-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<div class="media-body">
<h1>
<a href="/{{ ngo.key.id() }}">
<a href="/{{ ngo.form_url }}">
<span itemprop="name" >{{ ngo.name }}</span>
</a>
</h1>
Expand Down
2 changes: 1 addition & 1 deletion backend/templates/v1/ngo/donations-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div id="donation-table" class="col-xs-12 col-md-8 col-md-offset-2">
<p>Mai jos găsești o listă cu toate persoanele care au completat formularul de redirectionare:</p>

{% for key, value in donors.iteritems() %}
{% for key, value in donors.items() %}

{% if value or key == current_year %}
<p>{{ key }}</p>
Expand Down
2 changes: 1 addition & 1 deletion backend/templates/v1/ngo/my-account.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<div class="col-xs-12 col-md-6 col-md-offset-3">
<div data-toggle="popover" data-placement="bottom" data-content="Apasa CTRL+C pentru a copia adresa">
<label for="url-ngo">URL:</label>
<input id="url-ngo" class="ngo-copy-url form-control" value="{{ ngo_url }}" readonly />
<input id="url-ngo" class="ngo-copy-url form-control" value="{{ ngo.form_url if ngo }}" readonly />
</div>
</div>
</div>
Expand Down

0 comments on commit f2280b0

Please sign in to comment.