Skip to content

Commit

Permalink
Merge pull request EGCETSII#32 from Decide-Part-Rota/Rota1-003
Browse files Browse the repository at this point in the history
Rota1-003
  • Loading branch information
rafestorn authored Nov 24, 2022
2 parents 9c21e2a + 1832ec2 commit 365429d
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 3 deletions.
58 changes: 58 additions & 0 deletions decide/census/templates/census_by_group.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% 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>Census Groups</h2>
</div>
</div>
<div class="row justify-content-md-center">
<div class="col-sm-8">
<h4>Select which type of grouping you want to apply</h4>
</div>
</div>

<div class="row">

</div>

<div class="row justify-content-center submit">
<div class="col col-lg-2">
<a href="maritialStatus"><button type="button" class="btn btn-primary group-button">Maritial Status</button></a>
</div>
<div class="col col-lg-2">
<a href="nationality"><button type="button" class="btn btn-primary group-button">Nationality</button></a>
</div>
<div class="col col-lg-2">
<a href="age"><button type="button" class="btn btn-primary group-button">Age</button></a>
</div>
<div class="col col-lg-2">
<a href="gender"><button type="button" class="btn btn-primary group-button">Gender</button></a>
</div>
</div>

{% 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_maritialStatus.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 Single, 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="maritialStatus/add_by_maritialStatus_to_census" 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">Maritial Status</label>
<select multiple class="form-select" id="specificSizeSelect" name="maritialStatus-select">
<!--{% for maritialstatus in maritialStatus %}
<option value="{{maritialstatus}}">{{maritialstatus}}</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 %}
74 changes: 74 additions & 0 deletions decide/census/templates/census_nationality.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 Spain, every spanish user 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="nationality/add_by_nationality_to_census" 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">Nationality</label>
<select multiple class="form-select" id="specificSizeSelect" name="nationality-select">
<select multiple class="form-select" id="specificSizeSelect" name="maritialStatus-select">
<!--{% for nation in nationality %}
<option value="{{nation}}">{{nation}}</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 %}
7 changes: 6 additions & 1 deletion decide/census/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +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/', 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),
path('export/', views.export_census),
path('export/exporting_census/', views.exporting_census),
path('import/', views.import_census),
path('import/importing_census/', views.importing_census)
path('import/importing_census/', views.importing_census),
]
110 changes: 108 additions & 2 deletions decide/census/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,86 @@ def export_census(request):
return HttpResponse(template.render({'export': True}, request), status=ST_401)


def census_group(request):
if request.user.is_staff:
template = loader.get_template("census_by_group.html")
users = User.objects.all()
votings = Voting.objects.all()
context = {
'votings': votings,
'users': users
}
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 census_maritialStatus(request):
if request.user.is_staff:
template = loader.get_template("census_maritialStatus.html")
votings = Voting.objects.all()
try:
maritialStatus = set(u.maritialStatus for u in User.objects.all())
except BaseException:
maritialStatus = set()
context = {
'votings': votings,
'maritialStatus': maritialStatus,
}
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_maritialStatus_to_census(request):
template = loader.get_template("result_page.html")
if request.user.is_staff:
voting_id = request.POST['voting-select']
maritialStatus = request.POST['maritialStatus-select']
users = User.objects.filter(maritial_status in maritialStatus)
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_nationality(request):
if request.user.is_staff:
template = loader.get_template("census_nationality.html")
votings = Voting.objects.all()
try:
nationality = set(u.nationality for u in User.objects.all())
except BaseException:
nationality = set()
context = {
'votings': votings,
'nationality': nationality,
}
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")

def exporting_census(request):
if request.user.is_staff:
Expand Down Expand Up @@ -198,8 +278,35 @@ def import_census(request):
template = loader.get_template("result_page.html")
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({'export': True}, request), status=ST_401)


def add_by_nationality_to_census(request):
template = loader.get_template("result_page.html")
if request.user.is_staff:
voting_id = request.POST['voting-select']
nation = request.POST['nationality-select']
users = User.objects.filter(nationality in nation)
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 importing_census(request):
if request.user.is_staff:
Expand Down Expand Up @@ -228,4 +335,3 @@ def importing_census(request):
template = loader.get_template("result_page.html")
messages.error(request, "You must be a staff member to access this page")
return HttpResponse(template.render({'import': True}, request), status=ST_401)

0 comments on commit 365429d

Please sign in to comment.