Skip to content

Commit

Permalink
Fixing some bugs (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
tudoramariei authored Jul 4, 2024
1 parent 12d0e80 commit 0f53f8e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions backend/civil_society_vote/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ def show_toolbar(request):
)


# Flag necessary if the elections require support from other members
GLOBAL_SUPPORT_ENABLED = env("GLOBAL_SUPPORT_ENABLED")


Expand Down
2 changes: 1 addition & 1 deletion backend/hub/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def send_confirm_email_to_committee(request, candidate, to_email):
current_site = get_current_site(request)
protocol = "https" if request.is_secure() else "http"

confirmation_link_path = reverse("candidate-detail", args=(candidate.pk,))
confirmation_link_path = reverse("candidate-status-confirm", args=(candidate.pk,))
confirmation_link = f"{protocol}://{current_site.domain}{confirmation_link_path}"

utils.send_email(
Expand Down
20 changes: 10 additions & 10 deletions backend/hub/templates/candidate/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@

</div>

{% if not user.is_superuser and GLOBAL_SUPPORT_ENABLED and CANDIDATE_SUPPORTING_ENABLED and "support_candidate" in user_permissions and candidate.is_proposed %}
{% if not user.is_superuser and candidate.org.STATUS and GLOBAL_SUPPORT_ENABLED and CANDIDATE_SUPPORTING_ENABLED and "support_candidate" in user_permissions and candidate.is_proposed %}
<div class="buttons">
{% if candidate.org != request.user.orgs.first %}
{% if user|already_supported:candidate %}
<a href="{% url 'candidate-support' candidate.id %}" class="button is-danger">Retrage susținerea</a>
{% else %}
<a href="{% url 'candidate-support' candidate.id %}" class="button is-success">Susține</a>
{% endif %}
{% if user|already_supported:candidate %}
<a href="{% url 'candidate-support' candidate.id %}" class="button is-danger">Retrage susținerea</a>
{% else %}
<a href="{% url 'candidate-support' candidate.id %}" class="button is-success">Susține</a>
{% endif %}
{% endif %}
<span style="width: 100%; padding: 10px;">Susținători: {% supporters candidate.id %}</span>
</div>
Expand All @@ -88,13 +88,13 @@
{% if not user.is_superuser and CANDIDATE_VOTING_ENABLED and not CANDIDATE_SUPPORTING_ENABLED and not CANDIDATE_REGISTRATION_ENABLED and "vote_candidate" in user_permissions and candidate.status == 'accepted' %}

{% if user|cant_vote:candidate %}
<span class="tag is-danger">Nu poți vota la această rundă de alegeri.</span>
<span class="tag is-danger">Nu poți vota la această rundă de alegeri.</span>
{% elif user|can_vote_candidate:candidate %}
<a href="{% url 'candidate-vote' candidate.id %}" class="button is-success">Votează</a>
<a href="{% url 'candidate-vote' candidate.id %}" class="button is-success">Votează</a>
{% elif user|already_voted_candidate:candidate %}
<span class="tag is-success">✔ VOTAT</span>
<span class="tag is-success">✔ VOTAT</span>
{% else %}
<span class="tag is-warning">Ai utilizat toate voturile alocate pentru acest domeniu.</span>
<span class="tag is-warning">Ai utilizat toate voturile alocate pentru acest domeniu.</span>
{% endif %}

{% endif %}
Expand Down
13 changes: 13 additions & 0 deletions backend/hub/templatetags/hub_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ def can_vote_candidate(user, candidate):
return True


@register.filter
def can_support_candidate(user):
orgs = Organization.objects.filter(user=user)

if not orgs:
return False

if any(org.status == "accepted" for org in orgs):
return True
else:
return False


@register.filter
def already_voted_candidate(user, candidate):
if CandidateVote.objects.filter(user=user, candidate=candidate).exists():
Expand Down

0 comments on commit 0f53f8e

Please sign in to comment.