Skip to content

Commit

Permalink
Merge pull request EGCETSII#26 from Decide-Part-Rota/Rota1-002
Browse files Browse the repository at this point in the history
Rota1-002
  • Loading branch information
joseluisps21 authored Nov 24, 2022
2 parents c0d23e4 + 04deb3d commit 748c34b
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 1 deletion.
71 changes: 71 additions & 0 deletions decide/census/templates/census_age.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{% extends "base.html" %}
{% load i18n static %}

{% block extrahead %}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>

<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
{% endblock %}


{% block content %}
<div class="row justify-content-md-center align-items-center">
<div class="col-sm-8 justify-content-center align-items-center">
<h2 class ="justify-content-center align-items-center">Census Groups</h2>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-8">
<h3>Now you can add groups of voters to an specific voting</h3>
<h6>for example, if you select minmun age 22 and maximum age 28, every user who satisfies that requirement will be added to the chosen voting</h6>
</div>
</div>

<div class="row">

</div>

<form class="row gx-3 gy-2 align-items-center" action="age/create" method="POST">
{% csrf_token %}
<div class="row justify-content-md-center">
<div class="col-sm-8">
<label for="specificSizeSelect">Choose a voting</label>
<select class="form-select" id="specificSizeSelect" name="voting-select">
{% for voting in votings %}
<option value="{{voting.id}}">{{voting}}</option>
{%endfor%}
</select>

</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-8">
<label>Choose age</label>
<input type="number" name="minimum-age" max="100" min="0">
<input type="number" name="maximum-age" max="100" min="0">
</div>
</div>
<div class="row justify-content-center submit">
<div class="col col-lg-1">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>

{% if messages %}
<ul class="messages" style="margin-top:2%">
{% for message in messages %}
{% if message.tags == 'error' %}
<li class="{{ message.tags }} alert alert-danger" role="alert">{{ message }}</li>
{% else %}
<li class="{{ message.tags }} alert alert-{{message.tags}}" role="alert">{{ message }}</li>
{% endif %}

{% endfor %}
</ul>

{% endif %}


{% endblock %}
74 changes: 74 additions & 0 deletions decide/census/templates/census_gender.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{% extends "base.html" %}
{% load i18n static %}

{% block extrahead %}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>

<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
{% endblock %}


{% block content %}
<div class="row justify-content-md-center align-items-center">
<div class="col-sm-8 justify-content-center align-items-center">
<h2 class ="justify-content-center align-items-center">Census Groups</h2>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-8">
<h3>Now you can add groups of voters to an specific voting</h3>
<h6>for example, if you select "Male", every user who satisfies that requirement will be added to the chosen voting</h6>
</div>
</div>

<div class="row">

</div>

<form class="row gx-3 gy-2 align-items-center" action="gender/create" method="POST">
{% csrf_token %}
<div class="row justify-content-md-center">
<div class="col-sm-8">
<label for="specificSizeSelect">Choose a voting</label>
<select class="form-select" id="specificSizeSelect" name="voting-select">
{% for voting in votings %}
<option value="{{voting.id}}">{{voting}}</option>
{%endfor%}
</select>

</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-8">
<label for="specificSizeSelect">Choose gender</label>
<select multiple class="form-select" id="specificSizeSelect" name="gender-select">
<!--{% for gender in gender %}
<option value="{{gender}}">{{gender}}</option>
{%endfor%}-->
</select>
</div>
</div>
<div class="row justify-content-center submit">
<div class="col col-lg-1">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>

{% if messages %}
<ul class="messages" style="margin-top:2%">
{% for message in messages %}
{% if message.tags == 'error' %}
<li class="{{ message.tags }} alert alert-danger" role="alert">{{ message }}</li>
{% else %}
<li class="{{ message.tags }} alert alert-{{message.tags}}" role="alert">{{ message }}</li>
{% endif %}

{% endfor %}
</ul>

{% endif %}


{% endblock %}
5 changes: 4 additions & 1 deletion decide/census/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
path('add/add_to_census', views.add_to_census),
path('remove/', views.census_remove, name='census_remove'),
path('remove/remove_from_census', views.remove_from_census),
path('add/by_group/age', views.census_age),
path('add/by_group/age/create', views.add_by_age_to_census),
path('add/by_group/gender', views.census_gender),
path('add/by_group/gender/create', views.add_by_gender_to_census),
path('add/by_group/', views.census_group, name='census_by_group'),
path('add/by_group/maritialStatus', views.census_maritialStatus),
path('add/by_group/nationality', views.census_nationality),
path('add/by_group/maritialStatus/add_by_maritialStatus_to_census', views.add_by_maritialStatus_to_census),
path('add/by_group/nationality/add_by_nationality_to_census', views.add_by_nationality_to_census),

]
90 changes: 90 additions & 0 deletions decide/census/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,97 @@ def add_by_nationality_to_census(request):


return HttpResponse(template.render({}, request), status=status_code)

else:
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({}, request), status=ST_401)

def census_gender(request):
if request.user.is_staff:
template = loader.get_template("census_gender.html")
votings = Voting.objects.all()
try:
genders = set(u.gender for u in User.objects.all())
except BaseException:
genders = set()
context = {
'votings': votings,
'genders': genders,
}
return HttpResponse(template.render(context, request))
else:
template = loader.get_template("result_page.html")
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({}, request), status=ST_401)

def add_by_gender_to_census(request):
template = loader.get_template("result_page.html")
if request.user.is_staff:
voting_id = request.POST['voting-select']
genders = request.POST['gender-select']
users = User.objects.filter(gender in genders)
for user in users:
try:
census_by_voting = Census.objects.get(voting_id=voting_id,voter_id=user.id)
except Census.DoesNotExist:
census_by_voting = None
status_code=404
if census_by_voting == None:
census = Census(voting_id=voting_id, voter_id=user.id)
census.save()
messages.success(request, "User added to the voting correctly")
status_code=ST_201

else:
messages.info(request, "The user was already assigned to the voting")
status_code = 200

return HttpResponse(template.render({}, request), status=status_code)

else:
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({}, request), status=ST_401)

def census_age(request):
if request.user.is_staff:
template = loader.get_template("census_age.html")
votings = Voting.objects.all()
context = {
'votings': votings,
}
return HttpResponse(template.render(context, request))
else:
template = loader.get_template("result_page.html")
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({}, request), status=ST_401)


def add_by_age_to_census(request):
template = loader.get_template("result_page.html")
if request.user.is_staff:
voting_id = request.POST['voting-select']
minAge = request.POST['minimum-age']
maxAge = request.POST['maximum-age']
users = User.objects.filter(age >= minAge and age<=maxAge)
for user in users:
try:
census_by_voting = Census.objects.get(voting_id=voting_id,voter_id=user.id)
except Census.DoesNotExist:
census_by_voting = None
status_code=404
if census_by_voting == None:
census = Census(voting_id=voting_id, voter_id=user.id)
census.save()
messages.success(request, "User added to the voting correctly")
status_code=ST_201

else:
messages.info(request, "The user was already assigned to the voting")
status_code = 200


return HttpResponse(template.render({}, request), status=status_code)

else:
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({}, request), status=ST_401)

0 comments on commit 748c34b

Please sign in to comment.