Skip to content

Commit

Permalink
Implement NGO Details handling
Browse files Browse the repository at this point in the history
- create/display ang NGO's details
  • Loading branch information
tudoramariei committed Jan 4, 2024
1 parent 6d84a16 commit a191c85
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 49 deletions.
17 changes: 17 additions & 0 deletions backend/donations/migrations/0002_alter_ngo_form_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.8 on 2024-01-03 16:20

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("donations", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="ngo",
name="form_url",
field=models.CharField(blank=True, default="", max_length=255, verbose_name="form url"),
),
]
11 changes: 3 additions & 8 deletions backend/donations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,12 @@ class Ngo(models.Model):
is_active = models.BooleanField(verbose_name=_("is active"), db_index=True, default=True)

# url to the ngo's 2% form, that contains only the ngo's details
form_url = models.URLField(verbose_name=_("form url"), blank=True, null=False, default="", max_length=255)

# TODO: Seems unused
# tags = models.CharField(verbose_name=_("tags"),max_length=255, db_index=True, blank=True)
form_url = models.CharField(
verbose_name=_("form url"), blank=True, null=False, default="", max_length=255, unique=True
)

date_created = models.DateTimeField(verbose_name=_("date created"), db_index=True, auto_now_add=timezone.now)

# does the NGO allow the donor to upload the signed document
# TODO: This seems unused
# allow_upload = models.BooleanField(verbose_name=_("allow upload"),db_index=True, default=False)

class Meta:
verbose_name = _("NGO")
verbose_name_plural = _("NGOs")
Expand Down
57 changes: 53 additions & 4 deletions backend/donations/views/my_account.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.shortcuts import render
from django.utils.decorators import method_decorator

from ..models import Ngo
from .base import AccountHandler


Expand All @@ -16,11 +17,59 @@ class MyAccountHandler(AccountHandler):
def get(self, request, *args, **kwargs):
context = {
"user": request.user,
# TODO:
"ngo": None,
"ngo": request.user.ngo if request.user.ngo else None,
}
return render(request, self.template_name, context)


class NgoDetailsHandler(AccountHandler):
pass
template_name = "ngo/ngo-details.html"

def get(self, request, *args, **kwargs):
context = {
"user": request.user,
"ngo": request.user.ngo if request.user.ngo else None,
}

return render(request, self.template_name, context)

def post(self, request, *args, **kwargs):
post = request.POST

ngo: Ngo = request.user.ngo

if not ngo:
ngo = Ngo()
ngo.save()

ngo.is_verified = False
ngo.is_active = True

request.user.ngo = ngo
request.user.save()

ngo.name = post.get("ong-nume")
ngo.description = post.get("ong-descriere")
ngo.phone = post.get("ong-tel")
ngo.email = post.get("ong-email")
ngo.website = post.get("ong-website")
ngo.address = post.get("ong-adresa")
ngo.county = post.get("ong-judet")
ngo.active_region = post.get("ong-activitate")
ngo.form_url = post.get("ong-url")
ngo.registration_number = post.get("ong-cif")
ngo.bank_account = post.get("ong-cont")
ngo.has_special_status = True if post.get("special-status") == "on" else False
ngo.is_accepting_forms = True if post.get("accepts-forms") == "on" else False
ngo.logo_url = post.get("ong-logo-url", "")
ngo.image_url = post.get("ong-logo")
ngo.other_emails = ""

ngo.save()

context = {
"user": request.user,
"ngo": request.user.ngo if request.user.ngo else None,
}

return render(request, self.template_name, context)
4 changes: 2 additions & 2 deletions backend/templates/v1/all-ngos.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>Asociații pentru care poți redirecționa 3.5%</h1>
<div class="col-xs-6 col-sm-4 col-md-3">
<div class="ong-panel panel panel-default">
<a href="{{ ngo.key.id() }}">
{% set logo = ngo.logo if ngo.logo else DEFAULT_NGO_LOGO %}
{% set logo = ngo.logo_url if ngo.logo_url else DEFAULT_NGO_LOGO %}
<div class="ong-logo">
<img src="{{ logo }}" class="img-responsive center-block" alt="{{ ngo.name }} logo" />
</div>
Expand All @@ -48,4 +48,4 @@ <h1>Asociații pentru care poți redirecționa 3.5%</h1>
{% block scripts %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script>
<script src="{{ static('/js/search.js') }}"></script>
{% endblock %}
{% endblock %}
56 changes: 28 additions & 28 deletions backend/templates/v1/components/ngo-details-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,48 @@
<legend>Datele asociației:</legend>
<div class="form-group">
<div class="col-xs-12">
<input class="form-control" type="text" id="ong-nume" name="ong-nume" placeholder="Numele Asociatiei" value="{{ ngo.name }}" required maxlength="150" />
<input class="form-control" type="text" id="ong-nume" name="ong-nume" placeholder="Numele Asociației" value="{{ ngo.name if ngo }}" required maxlength="150" />
</div>
</div>
<div class="form-group">
<div class="col-xs-4 text-center">
<div id="upload-logo" class="{{ 'hidden' if ngo.logo }}">
<div id="upload-logo" class="{{ 'hidden' if ngo.logo_url }}">
<label for="ong-logo">
<i class="glyphicon glyphicon-picture upload-file-icon"></i>
<p>Logo-ul asociației</p>
</label>
<input type="file" id="ong-logo" class="hidden" accept="image/*" name="ong-logo" />
</div>
<div id="display-logo" class="text-center {{ 'hidden' if not ngo.logo }}">
<img id="ngo-logo" src="{{ ngo.logo }}" class="img-responsive center-block" />
<span id="delete-ngo-logo" class="text-danger">Sterge</span>
<input type="hidden" id="ong-logo-url" name="ong-logo-url" value="{{ ngo.logo }}" />
<div id="display-logo" class="text-center {{ 'hidden' if not ngo.logo_url }}">
<img id="ngo-logo" src="{{ ngo.logo_url if ngo }}" class="img-responsive center-block" />
<span id="delete-ngo-logo" class="text-danger">Șterge</span>
<input type="hidden" id="ong-logo-url" name="ong-logo-url" value="{{ ngo.logo_url if ngo }}" />
</div>
</div>
<div class="col-xs-8">
<textarea class="form-control" name="ong-descriere" placeholder="O scurta descriere" rows="3" required >{{ ngo.description }}</textarea>
<textarea class="form-control" name="ong-descriere" placeholder="O scurta descriere" rows="3" required >{{ ngo.description if ngo }}</textarea>
</div>
</div>
<div class="form-group">
<div class="col-xs-4">
<input class="form-control" type="text" name="ong-tel" placeholder="telefon (optional)" value="{{ ngo.tel if ngo.tel }}" maxlength="20" />
<input class="form-control" type="text" name="ong-tel" placeholder="telefon (optional)" value="{{ ngo.phone if ngo and ngo.phone }}" maxlength="20" />
</div>
<div class="col-xs-4">
<input class="form-control" type="email" name="ong-email" placeholder="email (optional)" value="{{ ngo.email if ngo.email }}" maxlength="100" />
<input class="form-control" type="email" name="ong-email" placeholder="email (optional)" value="{{ ngo.email if ngo and ngo.email }}" maxlength="100" />
</div>
<div class="col-xs-4">
<input class="form-control" type="text" name="ong-website" placeholder="website (optional)" value="{{ ngo.website if ngo.website }}" maxlength="100" />
<input class="form-control" type="text" name="ong-website" placeholder="website (optional)" value="{{ ngo.website if ngo and ngo.website }}" maxlength="100" />
</div>
</div>
<div class="form-group">
<div class="col-xs-8">
<input class="form-control" type="text" name="ong-adresa" placeholder="Adresa Asociatiei" value="{{ ngo.address }}" required maxlength="100" />
<input class="form-control" type="text" name="ong-adresa" placeholder="Adresa Asociației" value="{{ ngo.address if ngo }}" required maxlength="100" />
</div>
<div class="col-xs-4">
<select class="form-control" id="ong-judet" name="ong-judet" required x-moz-errormessage="Judetul este obligatoriu" title="Judetul este obligatoriu">
<select class="form-control" id="ong-judet" name="ong-judet" required x-moz-errormessage="Județul este obligatoriu" title="Județul este obligatoriu">
<option value="">Județul</option>
<option value="RO" {{ "selected" if county == ngo.county }}>Toata tara</option>
<optgroup label="Bucuresti">
<option value="RO" {{ "selected" if county == ngo.county }}>Toată țara</option>
<optgroup label="București">
{% for number in range(1, 7) %}
<option value="{{ number }}" {{ "selected" if number|string == ngo.county }}>Sector {{ number }}</option>
{% endfor %}
Expand All @@ -63,7 +63,7 @@
<select class="form-control" id="ong-activitate" name="ong-activitate" required x-moz-errormessage="Zona de activitate este obligatorie" title="Zona de activitate este obligatorie">
<option value="">Zona de activitate</option>
<option value="RO" {{ "selected" if county == ngo.active_region }}>National</option>
<optgroup label="Bucuresti">
<optgroup label="București">
{% for number in range(1, 7) %}
<option value="{{ number }}" {{ "selected" if number|string == ngo.active_region }}>Sector {{ number }}</option>
{% endfor %}
Expand All @@ -76,14 +76,14 @@
</div>
<div class="form-group choose-url-group">
<div class="col-xs-12">
<div>Poti alege un url personalizat pentru asociatia ta:</div>
<div>Poți alege un url personalizat pentru asociația ta:</div>
<p class="text-muted">(acesta nu va mai putea fi schimbat ulterior)</p>
{# this div is only used to contain the two and to add the has-warning class #}
<div>
<label for="ong-url" class="control-label">redirectioneaza.ro/</label>
<input id="ong-url" class="form-control" type="text" name="ong-url" placeholder="url-ul asociatiei" value="{{ ngo.key.id() if ngo.key }}" required maxlength="150" {{ "readonly" if not is_admin and ngo.key }} />
<input id="ong-url" class="form-control" type="text" name="ong-url" placeholder="url-ul asociației" value="{{ ngo.form_url if ngo }}" required maxlength="150" {{ "readonly" if not is_admin and ngo.key }} />
</div>
</div>
</div>
</div>
</fieldset>
<fieldset>
Expand All @@ -92,40 +92,40 @@
<div class="form-group">
<label for="ong-cif" class="col-xs-4 control-label">Codul Cif:</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="ong-cif" value="{{ ngo.cif }}" name="ong-cif" placeholder="Codul Cif" x-moz-errormessage="Codul Cif" title="Codul Cif" required maxlength="12" />
<input type="text" class="form-control" id="ong-cif" value="{{ ngo.registration_number if ngo }}" name="ong-cif" placeholder="Codul Cif" x-moz-errormessage="Codul Cif" title="Codul Cif" required maxlength="12" />
</div>
</div>
<div class="form-group">
<label for="ong-cont" class="col-xs-4 control-label">Codul IBAN al contului:</label>
<div class="col-xs-8">
<input type="text" class="form-control" id="ong-cont" value="{{ ngo.account }}" name="ong-cont" placeholder="Codul IBAN" x-moz-errormessage="Codul IBAN" title="Codul IBAN" required maxlength="40" />
<input type="text" class="form-control" id="ong-cont" value="{{ ngo.bank_account if ngo }}" name="ong-cont" placeholder="Codul IBAN" x-moz-errormessage="Codul IBAN" title="Codul IBAN" required maxlength="40" />
</div>
</div>
<div class="form-group special-status">
<div class="col-xs-4 text-right">
<input id="special-status" name="special-status" type="checkbox" {{ "checked" if ngo.special_status }}>
<input id="special-status" name="special-status" type="checkbox" {{ "checked" if ngo and ngo.has_special_status }}>
</div>
<label for="special-status" class="col-xs-8">
Asociatie inregistrata ca furnizor autorizat de servicii sociale
Asociație înregistrată ca furnizor autorizat de servicii sociale
</label>
</div>
<div class="form-group special-status">
<div class="col-xs-4 text-right">
<input id="accepts-forms" name="accepts-forms" type="checkbox" {{ "checked" if ngo.accepts_forms }}>
<input id="accepts-forms" name="accepts-forms" type="checkbox" {{ "checked" if ngo and ngo.is_accepting_forms }}>
</div>
<label for="accepts-forms" class="col-xs-8">
Doresc sa primesc formularele completate pe email <br>
<span class="explanation">
Selectand aceasta optiune confirm ca ONG-ul are cont SPV pentru a depune formularele
Selectând aceasta opțiune confirm ca ONG-ul are cont SPV pentru a depune formularele
</span>
</label>
</div>

</fieldset>
{% if is_admin %}
<fieldset>
<legend>Admin</legend>
<input id="old-ong-url" type="hidden" name="old-ong-url" value="{{ ngo.key.id() if ngo.key }}" />
<input id="old-ong-url" type="hidden" name="old-ong-url" value="{{ ngo.form_url if ngo }}" />
<div class="form-group">
<div class="col-xs-12">
<label for="ong-activ" class="col-xs-3">Activ:</label>
Expand Down Expand Up @@ -159,7 +159,7 @@
</div>
<div class="panel-body">
<p>
Daca vrei sa schimbi cine detine aces ONG, adauga mai jos adresa de email a noul cont:
Daca vrei sa schimbi cine deține aces ONG, adaugă mai jos adresa de email a noul cont:
</p>
<input class="form-control" type="text" name="new-ngo-owner" placeholder="Adresa de email" />
</div>
Expand All @@ -172,7 +172,7 @@

<div class="form-group">
<div class="col-xs-12">
<button type="submit" class="btn btn-primary margin-top">Salveaza</button>
<button type="submit" class="btn btn-primary margin-top">Salvează</button>
</div>
</div>
</form>
Expand Down
6 changes: 3 additions & 3 deletions backend/templates/v1/components/ngo-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<div class="col-xs-12 col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6">
<div class="media ngo-details" itemscope itemtype ="http://schema.org/NGO" >
<div class="media-left">
{% if ngo.logo %}
<img class="media-object" itemprop="logo" src="{{ ngo.logo }}" />
{% if ngo.logo_url %}
<img class="media-object" itemprop="logo" src="{{ ngo.logo_url }}" />
{% endif %}
</div>
<div class="media-body">
Expand Down Expand Up @@ -41,4 +41,4 @@ <h1>
</div>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion backend/templates/v1/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h4>
<div class="col-xs-6 col-sm-4 col-md-3">
<div class="ong-panel panel panel-default">
<a href="{{ ngo.key.id() }}">
{% set logo = ngo.logo if ngo.logo else DEFAULT_NGO_LOGO %}
{% set logo = ngo.logo_url if ngo.logo_url else DEFAULT_NGO_LOGO %}
<div class="ong-logo">
<img src="{{ logo }}" class="img-responsive center-block" alt="{{ ngo.name }} logo" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions backend/templates/v1/twopercent.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
{% block additional_headers %}
<meta property="og:title" content="{{ ngo.name }}" />
<meta property="og:description" content="{{ ngo.description }}" />
{% if ngo.logo %}
<meta property="og:image" content="{{ ngo.logo }}" />
<meta property="og:image:secure_url" content="{{ ngo.logo }}" />
{% if ngo.logo_url %}
<meta property="og:image" content="{{ ngo.logo_url }}" />
<meta property="og:image:secure_url" content="{{ ngo.logo_url }}" />
{% endif %}

<meta property="og:type" content="website" />
Expand Down

0 comments on commit a191c85

Please sign in to comment.