Skip to content

Commit 365429d

Browse files
authored
Merge pull request EGCETSII#32 from Decide-Part-Rota/Rota1-003
Rota1-003
2 parents 9c21e2a + 1832ec2 commit 365429d

File tree

5 files changed

+320
-3
lines changed

5 files changed

+320
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{% extends "base.html" %}
2+
{% load i18n static %}
3+
4+
{% block extrahead %}
5+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
6+
<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>
7+
8+
<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
9+
{% endblock %}
10+
11+
12+
{% block content %}
13+
<div class="row justify-content-md-center align-items-center">
14+
<div class="col-sm-8 justify-content-center align-items-center">
15+
<h2>Census Groups</h2>
16+
</div>
17+
</div>
18+
<div class="row justify-content-md-center">
19+
<div class="col-sm-8">
20+
<h4>Select which type of grouping you want to apply</h4>
21+
</div>
22+
</div>
23+
24+
<div class="row">
25+
26+
</div>
27+
28+
<div class="row justify-content-center submit">
29+
<div class="col col-lg-2">
30+
<a href="maritialStatus"><button type="button" class="btn btn-primary group-button">Maritial Status</button></a>
31+
</div>
32+
<div class="col col-lg-2">
33+
<a href="nationality"><button type="button" class="btn btn-primary group-button">Nationality</button></a>
34+
</div>
35+
<div class="col col-lg-2">
36+
<a href="age"><button type="button" class="btn btn-primary group-button">Age</button></a>
37+
</div>
38+
<div class="col col-lg-2">
39+
<a href="gender"><button type="button" class="btn btn-primary group-button">Gender</button></a>
40+
</div>
41+
</div>
42+
43+
{% if messages %}
44+
<ul class="messages" style="margin-top:2%">
45+
{% for message in messages %}
46+
{% if message.tags == 'error' %}
47+
<li class="{{ message.tags }} alert alert-danger" role="alert">{{ message }}</li>
48+
{% else %}
49+
<li class="{{ message.tags }} alert alert-{{message.tags}}" role="alert">{{ message }}</li>
50+
{% endif %}
51+
52+
{% endfor %}
53+
</ul>
54+
55+
{% endif %}
56+
57+
58+
{% endblock %}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{% extends "base.html" %}
2+
{% load i18n static %}
3+
4+
{% block extrahead %}
5+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
6+
<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>
7+
8+
<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
9+
{% endblock %}
10+
11+
12+
{% block content %}
13+
<div class="row justify-content-md-center align-items-center">
14+
<div class="col-sm-8 justify-content-center align-items-center">
15+
<h2 class ="justify-content-center align-items-center">Census Groups</h2>
16+
</div>
17+
</div>
18+
<div class="row justify-content-md-center">
19+
<div class="col-sm-8">
20+
<h3>Now you can add groups of voters to an specific voting</h3>
21+
<h6>for example, if you select Single, every user who satisfies that requirement will be added to the chosen voting</h6>
22+
</div>
23+
</div>
24+
25+
<div class="row">
26+
27+
</div>
28+
29+
<form class="row gx-3 gy-2 align-items-center" action="maritialStatus/add_by_maritialStatus_to_census" method="POST">
30+
{% csrf_token %}
31+
<div class="row justify-content-md-center">
32+
<div class="col-sm-8">
33+
<label for="specificSizeSelect">Choose a voting</label>
34+
<select class="form-select" id="specificSizeSelect" name="voting-select">
35+
{% for voting in votings %}
36+
<option value="{{voting.id}}">{{voting}}</option>
37+
{%endfor%}
38+
</select>
39+
40+
</div>
41+
</div>
42+
<div class="row justify-content-md-center">
43+
<div class="col-sm-8">
44+
<label for="specificSizeSelect">Maritial Status</label>
45+
<select multiple class="form-select" id="specificSizeSelect" name="maritialStatus-select">
46+
<!--{% for maritialstatus in maritialStatus %}
47+
<option value="{{maritialstatus}}">{{maritialstatus}}</option>
48+
{%endfor%}-->
49+
</select>
50+
</div>
51+
</div>
52+
<div class="row justify-content-center submit">
53+
<div class="col col-lg-1">
54+
<button type="submit" class="btn btn-primary">Submit</button>
55+
</div>
56+
</div>
57+
</form>
58+
59+
{% if messages %}
60+
<ul class="messages" style="margin-top:2%">
61+
{% for message in messages %}
62+
{% if message.tags == 'error' %}
63+
<li class="{{ message.tags }} alert alert-danger" role="alert">{{ message }}</li>
64+
{% else %}
65+
<li class="{{ message.tags }} alert alert-{{message.tags}}" role="alert">{{ message }}</li>
66+
{% endif %}
67+
68+
{% endfor %}
69+
</ul>
70+
71+
{% endif %}
72+
73+
74+
{% endblock %}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{% extends "base.html" %}
2+
{% load i18n static %}
3+
4+
{% block extrahead %}
5+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
6+
<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>
7+
8+
<link type="text/css" rel="stylesheet" href="{% static 'style.css' %}" />
9+
{% endblock %}
10+
11+
12+
{% block content %}
13+
<div class="row justify-content-md-center align-items-center">
14+
<div class="col-sm-8 justify-content-center align-items-center">
15+
<h2 class ="justify-content-center align-items-center">Census Groups</h2>
16+
</div>
17+
</div>
18+
<div class="row justify-content-md-center">
19+
<div class="col-sm-8">
20+
<h3>Now you can add groups of voters to an specific voting</h3>
21+
<h6>for example, if you select Spain, every spanish user will be added to the chosen voting</h6>
22+
</div>
23+
</div>
24+
25+
<div class="row">
26+
27+
</div>
28+
29+
<form class="row gx-3 gy-2 align-items-center" action="nationality/add_by_nationality_to_census" method="POST">
30+
{% csrf_token %}
31+
<div class="row justify-content-md-center">
32+
<div class="col-sm-8">
33+
<label for="specificSizeSelect">Choose a voting</label>
34+
<select class="form-select" id="specificSizeSelect" name="voting-select">
35+
{% for voting in votings %}
36+
<option value="{{voting.id}}">{{voting}}</option>
37+
{%endfor%}
38+
</select>
39+
</div>
40+
</div>
41+
<div class="row justify-content-md-center">
42+
<div class="col-sm-8">
43+
<label for="specificSizeSelect">Nationality</label>
44+
<select multiple class="form-select" id="specificSizeSelect" name="nationality-select">
45+
<select multiple class="form-select" id="specificSizeSelect" name="maritialStatus-select">
46+
<!--{% for nation in nationality %}
47+
<option value="{{nation}}">{{nation}}</option>
48+
{%endfor%}-->
49+
</select>
50+
</div>
51+
</div>
52+
<div class="row justify-content-center submit">
53+
<div class="col col-lg-1">
54+
<button type="submit" class="btn btn-primary">Submit</button>
55+
</div>
56+
</div>
57+
</form>
58+
59+
{% if messages %}
60+
<ul class="messages" style="margin-top:2%">
61+
{% for message in messages %}
62+
{% if message.tags == 'error' %}
63+
<li class="{{ message.tags }} alert alert-danger" role="alert">{{ message }}</li>
64+
{% else %}
65+
<li class="{{ message.tags }} alert alert-{{message.tags}}" role="alert">{{ message }}</li>
66+
{% endif %}
67+
68+
{% endfor %}
69+
</ul>
70+
71+
{% endif %}
72+
73+
74+
{% endblock %}

decide/census/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
path('add/add_to_census', views.add_to_census),
1010
path('remove/', views.census_remove, name='census_remove'),
1111
path('remove/remove_from_census', views.remove_from_census),
12+
path('add/by_group/', views.census_group, name='census_by_group'),
13+
path('add/by_group/maritialStatus', views.census_maritialStatus),
14+
path('add/by_group/nationality', views.census_nationality),
15+
path('add/by_group/maritialStatus/add_by_maritialStatus_to_census', views.add_by_maritialStatus_to_census),
16+
path('add/by_group/nationality/add_by_nationality_to_census', views.add_by_nationality_to_census),
1217
path('export/', views.export_census),
1318
path('export/exporting_census/', views.exporting_census),
1419
path('import/', views.import_census),
15-
path('import/importing_census/', views.importing_census)
20+
path('import/importing_census/', views.importing_census),
1621
]

decide/census/views.py

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,86 @@ def export_census(request):
158158
return HttpResponse(template.render({'export': True}, request), status=ST_401)
159159

160160

161+
def census_group(request):
162+
if request.user.is_staff:
163+
template = loader.get_template("census_by_group.html")
164+
users = User.objects.all()
165+
votings = Voting.objects.all()
166+
context = {
167+
'votings': votings,
168+
'users': users
169+
}
170+
return HttpResponse(template.render(context, request))
171+
else:
172+
template = loader.get_template("result_page.html")
173+
messages.error(request, "You must be a staff member to access this page")
174+
return HttpResponse(template.render({}, request), status=ST_401)
175+
176+
def census_maritialStatus(request):
177+
if request.user.is_staff:
178+
template = loader.get_template("census_maritialStatus.html")
179+
votings = Voting.objects.all()
180+
try:
181+
maritialStatus = set(u.maritialStatus for u in User.objects.all())
182+
except BaseException:
183+
maritialStatus = set()
184+
context = {
185+
'votings': votings,
186+
'maritialStatus': maritialStatus,
187+
}
188+
return HttpResponse(template.render(context, request))
189+
else:
190+
template = loader.get_template("result_page.html")
191+
messages.error(request, "You must be a staff member to access this page")
192+
return HttpResponse(template.render({}, request), status=ST_401)
193+
194+
195+
def add_by_maritialStatus_to_census(request):
196+
template = loader.get_template("result_page.html")
197+
if request.user.is_staff:
198+
voting_id = request.POST['voting-select']
199+
maritialStatus = request.POST['maritialStatus-select']
200+
users = User.objects.filter(maritial_status in maritialStatus)
201+
for user in users:
202+
try:
203+
census_by_voting = Census.objects.get(voting_id=voting_id,voter_id=user.id)
204+
except Census.DoesNotExist:
205+
census_by_voting = None
206+
status_code=404
207+
if census_by_voting == None:
208+
census = Census(voting_id=voting_id, voter_id=user.id)
209+
census.save()
210+
messages.success(request, "User added to the voting correctly")
211+
status_code=ST_201
212+
213+
else:
214+
messages.info(request, "The user was already assigned to the voting")
215+
status_code = 200
216+
217+
218+
return HttpResponse(template.render({}, request), status=status_code)
219+
220+
else:
221+
messages.error(request, "You must be a staff member to access this page")
222+
return HttpResponse(template.render({}, request), status=ST_401)
223+
224+
225+
def census_nationality(request):
226+
if request.user.is_staff:
227+
template = loader.get_template("census_nationality.html")
228+
votings = Voting.objects.all()
229+
try:
230+
nationality = set(u.nationality for u in User.objects.all())
231+
except BaseException:
232+
nationality = set()
233+
context = {
234+
'votings': votings,
235+
'nationality': nationality,
236+
}
237+
return HttpResponse(template.render(context, request))
238+
else:
239+
template = loader.get_template("result_page.html")
240+
messages.error(request, "You must be a staff member to access this page")
161241

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

282+
def add_by_nationality_to_census(request):
283+
template = loader.get_template("result_page.html")
284+
if request.user.is_staff:
285+
voting_id = request.POST['voting-select']
286+
nation = request.POST['nationality-select']
287+
users = User.objects.filter(nationality in nation)
288+
for user in users:
289+
try:
290+
census_by_voting = Census.objects.get(voting_id=voting_id,voter_id=user.id)
291+
except Census.DoesNotExist:
292+
census_by_voting = None
293+
status_code=404
294+
if census_by_voting == None:
295+
census = Census(voting_id=voting_id, voter_id=user.id)
296+
census.save()
297+
messages.success(request, "User added to the voting correctly")
298+
status_code=ST_201
299+
300+
else:
301+
messages.info(request, "The user was already assigned to the voting")
302+
status_code = 200
303+
304+
305+
return HttpResponse(template.render({}, request), status=status_code)
306+
307+
else:
308+
messages.error(request, "You must be a staff member to access this page")
309+
return HttpResponse(template.render({}, request), status=ST_401)
203310

204311
def importing_census(request):
205312
if request.user.is_staff:
@@ -228,4 +335,3 @@ def importing_census(request):
228335
template = loader.get_template("result_page.html")
229336
messages.error(request, "You must be a staff member to access this page")
230337
return HttpResponse(template.render({'import': True}, request), status=ST_401)
231-

0 commit comments

Comments
 (0)