Skip to content

Commit

Permalink
fixes to translations and broken pages
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei committed Jan 15, 2025
1 parent bbfd687 commit 4e9032d
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 260 deletions.
10 changes: 3 additions & 7 deletions backend/donations/views/ngo_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get(self, request: HttpRequest, *args, **kwargs):
)

ngo_url = ""
if user_ngo:
if user_ngo and user_ngo.slug:
ngo_url = request.build_absolute_uri(reverse("twopercent", kwargs={"ngo_url": user_ngo.slug}))

ngo_jobs = user_ngo.jobs.all()[:10] if user_ngo else None
Expand Down Expand Up @@ -259,14 +259,10 @@ def get_context_data(self, **kwargs):
ngo: Ngo = context["ngo"]

ngo_url = ""
if ngo:
if ngo and ngo.slug:
ngo_url = self.request.build_absolute_uri(reverse("twopercent", kwargs={"ngo_url": ngo.slug}))

context.update(
{
"ngo_url": ngo_url,
}
)
context["ngo_url"] = ngo_url

return context

Expand Down
85 changes: 40 additions & 45 deletions backend/donations/views/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings
from django.db.models import QuerySet
from django.http import HttpResponse
from django.shortcuts import render
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.views.generic import TemplateView
Expand All @@ -14,17 +13,14 @@
from redirectioneaza.common.cache import cache_decorator

from ..models.donors import Donor
from ..models.ngos import ALL_NGO_IDS_CACHE_KEY, FRONTPAGE_NGOS_KEY, FRONTPAGE_STATS_KEY, Ngo
from ..models.ngos import FRONTPAGE_NGOS_KEY, FRONTPAGE_STATS_KEY, Ngo
from .base import BaseVisibleTemplateView
from .common import SearchMixin


class HomePage(TemplateView):
class HomePage(BaseVisibleTemplateView):
template_name = "public/home.html"

@staticmethod
@cache_decorator(timeout=settings.TIMEOUT_CACHE_LONG, cache_key_prefix=ALL_NGO_IDS_CACHE_KEY)
def _get_list_of_ngo_ids() -> list:
return list(Ngo.active.values_list("id", flat=True))
title = "redirectioneaza.ro"

@cache_decorator(timeout=settings.TIMEOUT_CACHE_SHORT, cache_key_prefix=FRONTPAGE_STATS_KEY)
def _get_stats(self, now: datetime = None, ngo_queryset: QuerySet = None) -> List[Dict[str, Union[str, int]]]:
Expand All @@ -50,15 +46,25 @@ def _get_stats(self, now: datetime = None, ngo_queryset: QuerySet = None) -> Lis
},
]

def get(self, request, *args, **kwargs):
@cache_decorator(timeout=settings.TIMEOUT_CACHE_SHORT, cache_key_prefix=FRONTPAGE_NGOS_KEY)
def _get_random_ngos(self, ngo_queryset: QuerySet, num_ngos: int):
all_ngo_ids = list(Ngo.active.values_list("id", flat=True))
return ngo_queryset.filter(id__in=random.sample(all_ngo_ids, num_ngos))

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

request = self.request
now = timezone.now()

context = {
"title": "redirectioneaza.ro",
"limit": settings.DONATIONS_LIMIT,
"month_limit": settings.DONATIONS_LIMIT_MONTH_NAME,
"current_year": now.year,
}
context.update(
{
"title": "redirectioneaza.ro",
"limit": settings.DONATIONS_LIMIT,
"month_limit": settings.DONATIONS_LIMIT_MONTH_NAME,
"current_year": now.year,
}
)

if partner := request.partner:
partner_ngos = partner.ngos.all()
Expand All @@ -84,20 +90,12 @@ def get(self, request, *args, **kwargs):
context["stats"] = self._get_stats(now, ngo_queryset)
context["ngos"] = self._get_random_ngos(ngo_queryset, num_ngos=min(4, ngo_queryset.count()))

return render(request, self.template_name, context)

@cache_decorator(timeout=settings.TIMEOUT_CACHE_SHORT, cache_key_prefix=FRONTPAGE_NGOS_KEY)
def _get_random_ngos(self, ngo_queryset: QuerySet, num_ngos: int):
all_ngo_ids = self._get_list_of_ngo_ids()
return ngo_queryset.filter(id__in=random.sample(all_ngo_ids, num_ngos))
return context


class AboutHandler(TemplateView):
class AboutHandler(BaseVisibleTemplateView):
template_name = "public/about.html"

def get(self, request, *args, **kwargs):
context = {"title": "Despre redirectioneaza.ro"}
return render(request, self.template_name, context)
title = _("About redirectioneaza.ro")


class NgoListHandler(SearchMixin):
Expand Down Expand Up @@ -126,34 +124,31 @@ def get_context_data(self, **kwargs):
return context


class NoteHandler(TemplateView):
class NoteHandler(BaseVisibleTemplateView):
template_name = "public/note.html"
title = _("Information notice")

def get(self, request, *args, **kwargs):
context = {
"title": "Notă de informare",
"contact_email": settings.CONTACT_EMAIL_ADDRESS,
}
return render(request, self.template_name, context)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["contact_email"] = settings.CONTACT_EMAIL_ADDRESS

return context

class PolicyHandler(TemplateView):
template_name = "public/policy.html"

def get(self, request, *args, **kwargs):
context = {"title": "Politica de confidențialitate"}
return render(request, self.template_name, context)
class PolicyHandler(BaseVisibleTemplateView):
template_name = "public/policy.html"
title = _("Privacy policy")


class TermsHandler(TemplateView):
class TermsHandler(BaseVisibleTemplateView):
template_name = "public/terms.html"
title = _("Terms & conditions")

def get(self, request, *args, **kwargs):
context = {
"title": "Termeni și condiții",
"contact_email": settings.CONTACT_EMAIL_ADDRESS,
}
return render(request, self.template_name, context)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["contact_email"] = settings.CONTACT_EMAIL_ADDRESS

return context


class HealthCheckHandler(TemplateView):
Expand Down
Loading

0 comments on commit 4e9032d

Please sign in to comment.