Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ django-debug-toolbar==2.2
Faker==4.0.2

pytest==5.4.1
ipython==7.14.0
34 changes: 17 additions & 17 deletions ro_help/hub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ class NGOAdmin(admin.ModelAdmin):
form = NGOForm

list_display = ("name", "contact_name", "county", "city", "accepts_transfer", "accepts_mobilpay", "created")
list_filter = (
"city",
"county",
)
list_filter = ("county",)
search_fields = ("name", "email")
autocomplete_fields = ["city"]
inlines = [NGOAccountInline]

def get_queryset(self, request):
Expand All @@ -102,14 +100,17 @@ def get_queryset(self, request):
return qs

def get_readonly_fields(self, request, obj=None):
readonly_fields = []
if not obj:
return []
return readonly_fields

user = request.user
if not user.groups.filter(name=ADMIN_GROUP_NAME).exists():
return ["users"]
readonly_fields.append("users")

return []
readonly_fields.extend(["city_old", "county"])

return readonly_fields

def has_accounts(self, request, no_accounts):
for account_idx in range(no_accounts):
Expand Down Expand Up @@ -202,7 +203,7 @@ class NGONeedAdmin(admin.ModelAdmin):

list_display = ("title", "ngo", "urgency", "kind", "created", "responses", "resolved_on", "closed_on")
list_filter = (NGOFilter, ActiveNGONeedFilter, "urgency", "kind", "ngo__city", "ngo__county")
readonly_fields = ["resolved_on", "closed_on"]
readonly_fields = ["resolved_on", "closed_on", "city_old", "county"]
inlines = [NGOHelperInline]
actions = ["resolve_need", "close_need"]
search_fields = (
Expand All @@ -212,6 +213,7 @@ class NGONeedAdmin(admin.ModelAdmin):
"ngo__name",
"ngo__email",
)
autocomplete_fields = ["city"]

class Media:
pass
Expand Down Expand Up @@ -331,10 +333,11 @@ class RegisterNGORequestAdmin(admin.ModelAdmin):
"get_statute",
]
actions = ["create_account", "close_request"]
readonly_fields = ["active", "resolved_on", "registered_on", "get_avatar"]
readonly_fields = ["active", "resolved_on", "registered_on", "get_avatar", "city_old", "county"]
list_filter = ("city", "county", "registered_on", "closed")
inlines = [RegisterNGORequestVoteInline]
search_fields = ("name",)
autocomplete_fields = ["city"]

def votes_count(self, obj):
return obj.votes_count
Expand Down Expand Up @@ -555,16 +558,17 @@ class CityAdmin(admin.ModelAdmin):
At this moment, only the superadmin is allowed to import new cities and
change existing ones.
"""

list_display = ["city", "county"]
list_filter = ["county", "is_county_residence"]
search_fields = ["city"]

def get_urls(self):
urls = super().get_urls()
urls += [
custom_url = [
url("import-cities", self.import_cities, name="import_cities"),
]
return urls
return custom_url + urls

def has_add_permission(self, request):
return False
Expand Down Expand Up @@ -598,11 +602,7 @@ def import_cities(self, request):
if (row["Judet"], row["Localitate"]) in COUNTY_RESIDENCE:
is_county_residence = True

city = City(
city=row["Localitate"],
county=row["Judet"],
is_county_residence=is_county_residence
)
city = City(city=row["Localitate"], county=row["Judet"], is_county_residence=is_county_residence)
batch.append(city)

if len(batch) == batch_size:
Expand All @@ -614,7 +614,7 @@ def import_cities(self, request):
City.objects.bulk_create(batch, batch_size=len(batch), ignore_conflicts=True)

self.message_user(request, _("CSV file imported"), level=messages.INFO)
return redirect(".")
return redirect("..")

form = ImportCitiesForm()
context = {
Expand Down
8 changes: 8 additions & 0 deletions ro_help/hub/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings


def hub_settings(context):
return {
"DEBUG": settings.DEBUG,
"ANALYTICS_ENABLED": settings.ANALYTICS_ENABLED,
}
19 changes: 18 additions & 1 deletion ro_help/hub/forms.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from django import forms
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from django_crispy_bulma.widgets import EmailInput

from hub import models
from captcha.fields import ReCaptchaField
from captcha.widgets import ReCaptchaV3

from hub import models


class NGOHelperForm(forms.ModelForm):
captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={"required_score": 0.3, "action": "help"}), label="")
Expand Down Expand Up @@ -73,12 +75,27 @@ class Meta:
]
widgets = {
"email": EmailInput(),
"city": forms.Select(attrs={"data-url": reverse_lazy("city-autocomplete"),}),
# # "has_netopia_contract": forms.CheckboxInput(),
# "avatar": AdminResubmitImageWidget,
# "last_balance_sheet": AdminResubmitFileWidget,
# "statute": AdminResubmitFileWidget,
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["city"].queryset = models.City.objects.none()

if "city" not in self.data:
self.fields["city"].widget.attrs.update({"disabled": "true"})

if "county" in self.data:
try:
county = self.data.get("county")
self.fields["city"].queryset = models.City.objects.filter(county__iexact=county)
except (ValueError, TypeError):
pass # invalid input, fallback to empty queryset


class RegisterNGORequestVoteForm(forms.ModelForm):
class Meta:
Expand Down
54 changes: 34 additions & 20 deletions ro_help/hub/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import requests
from faker import Faker

from django.conf import settings
from django.contrib.auth.models import User, Group, Permission
from django.core.management.base import BaseCommand
from django.utils import timezone
Expand All @@ -24,6 +23,7 @@
DSU_GROUP_NAME,
FFC_GROUP_NAME,
NGOReportItem,
City,
)
from mobilpay.models import PaymentOrder

Expand All @@ -35,7 +35,7 @@ def random_avatar():
try:
image = requests.get("https://source.unsplash.com/random", allow_redirects=False)
return image.headers["Location"]
except:
except Exception:
return "https://source.unsplash.com/random"


Expand All @@ -45,31 +45,31 @@ def random_avatar():
"name": "Habitat for Humanity",
"email": "habitat@habitat.ro",
"description": """
O locuință decentă poate rupe cercul sărăciei. Credem cu tărie în acest lucru din 1976, de când lucrăm pentru
O locuință decentă poate rupe cercul sărăciei. Credem cu tărie în acest lucru din 1976, de când lucrăm pentru
viziunea noastră: o lume în care toți oamenii au posibilitatea să locuiască decent. Cu sprijinul nostru,
peste 6 milioane de oameni din peste 70 de țări au un loc mai bun în care să trăiască, o casă nouă sau una
complet renovată.Suntem o asociație creștină, non-profit, ce lucrăm alături de oameni de pretutindeni,
complet renovată.Suntem o asociație creștină, non-profit, ce lucrăm alături de oameni de pretutindeni,
din toate păturile sociale, rasele, religiile și naționalitățile pentru a elimina locuirea precară.
""",
"phone": "+40722644394",
"address": "Str. Naum Râmniceanu, nr. 45 A, et.1, ap. 3, sector 1, Bucureşti 011616",
"city": "Bucureşti",
"county": "Sector 1",
"address": "Str. Naum Râmniceanu, nr. 45 A, et.1, ap. 3, sector 1, Bucuresti 011616",
"city": "Bucuresti",
"county": "Bucuresti",
"avatar": "http://www.habitat.ro/wp-content/uploads/2014/11/logo.png",
},
{
"name": "Crucea Roșie",
"email": "matei@crucearosie.ro",
"description": """
Crucea Rosie Romana asista persoanele vulnerabile in situatii de dezastre si de criza. Prin programele si
Crucea Rosie Romana asista persoanele vulnerabile in situatii de dezastre si de criza. Prin programele si
activitatile sale in beneficiul societatii, contribuie la prevenirea si alinarea suferintei sub toate formele,
protejeaza sanatatea si viata, promoveaza respectul fata de demnitatea umana, fara nicio discriminare bazata
protejeaza sanatatea si viata, promoveaza respectul fata de demnitatea umana, fara nicio discriminare bazata
pe nationalitate, rasa, sex, religie, varsta, apartenenta sociala sau politica.
""",
"phone": "+40213176006",
"address": "Strada Biserica Amzei, nr. 29, Sector 1, Bucuresti",
"city": "Bucuresti",
"county": "Sector 1",
"county": "Bucuresti",
"avatar": "https://crucearosie.ro/themes/redcross/images/emblema_crr_desktop.png",
"accepts_transfer": True,
"donations_description": "Monedă RON: RO44BRDE410SV20462054100 (Banca: BRD - Piata Romana)",
Expand All @@ -78,19 +78,19 @@ def random_avatar():
"name": "MKBT: Make Better",
"email": "contact@mkbt.ro",
"description": """
MKBT: Make Better has been working for urban development and regeneration in Romania since April 2014.
That is to say that we are drafting, validating and coordinating processes for local development and urban
MKBT: Make Better has been working for urban development and regeneration in Romania since April 2014.
That is to say that we are drafting, validating and coordinating processes for local development and urban
regeneration in order to help as many cities become their best possible version and the best home for their inhabitants.
As a local development advisor, we assist both public and private entities.
We substantiate our work on a thorough understanding of local needs and specificities of the communities we
work with. We acknowledge, at the same time, the global inter-connectivity of local challenges. Our proposed
We substantiate our work on a thorough understanding of local needs and specificities of the communities we
work with. We acknowledge, at the same time, the global inter-connectivity of local challenges. Our proposed
solutions are therefore grounded in international best practice, while at the same time capitalizing – in a
sustainable and harmonious manner – on local know how and resources.
""",
"phone": "+40213176006",
"address": "Str. Popa Petre, Nr. 23, Sector 2, 020802, Bucharest, Romania.",
"city": "Bucuresti",
"county": "Sector 2",
"county": "Bucuresti",
"avatar": "http://mkbt.ro/wp-content/uploads/2015/08/MKBT-logo-alb.png",
},
]
Expand All @@ -101,11 +101,11 @@ def random_avatar():
"description": fake.text(),
"phone": fake.phone_number(),
"address": fake.address(),
"city": random.choice(["Arad", "Timisoara", "Oradea", "Cluj", "Bucuresti"]),
"county": random.choice(["ARAD", "TIMIS", "BIHOR", "CLUJ", "SECTOR 1", "SECTOR 2"]),
"city": ["Arad", "Timisoara", "Oradea", "Cluj-Napoca", "Bucuresti"][i],
"county": ["Arad", "Timis", "Bihor", "Cluj", "Bucuresti"][i],
"avatar": random_avatar(),
}
for _ in range(2)
for i in range(5)
]
)

Expand Down Expand Up @@ -205,7 +205,20 @@ def handle(self, *args, **kwargs):

NGONeed.objects.filter(kind="money").exclude(ngo__name__in=["Code4Romania", "Crucea Roșie"]).delete()

cities = [
{"city": "Arad", "county": "Arad"},
{"city": "Timisoara", "county": "Timis"},
{"city": "Oradea", "county": "Bihor"},
{"city": "Cluj-Napoca", "county": "Cluj"},
{"city": "Bucuresti", "county": "Bucuresti"},
]
for city_data in cities:
City.objects.get_or_create(**city_data)

for details in NGOS:
details["city"] = City.objects.get(city=details["city"], county=details["county"])
details["county"] = details["county"].upper()

ngo, _ = NGO.objects.get_or_create(**details)

owner = random.choice([ngo_user, admin_user, None])
Expand All @@ -214,6 +227,7 @@ def handle(self, *args, **kwargs):
ngo.save()

for _ in range(20):
random_city = City.objects.order_by("?").first()
need = NGONeed.objects.create(
**{
"ngo": ngo,
Expand All @@ -222,8 +236,8 @@ def handle(self, *args, **kwargs):
"description": fake.text(),
"title": fake.text(),
"resolved_on": random.choice([None, timezone.now()]),
"city": random.choice(["Arad", "Timisoara", "Oradea", "Cluj", "Bucuresti"]),
"county": random.choice(["ARAD", "TIMIS", "BIHOR", "CLUJ", "SECTOR 1", "SECTOR 2"]),
"city": random_city,
"county": random_city.county.upper(),
}
)

Expand Down
Loading