Explorar o código

Added QuickSeum form

Denis Merigoux %!s(int64=9) %!d(string=hai) anos
pai
achega
c2783d6d66
Modificáronse 3 ficheiros con 83 adicións e 28 borrados
  1. 19 9
      counter/templates/baseTemplate.html
  2. 50 17
      counter/templates/homeTemplate.html
  3. 14 2
      counter/views.py

+ 19 - 9
counter/templates/baseTemplate.html

7
 	<meta name="keywords" content="seum compteur" />
7
 	<meta name="keywords" content="seum compteur" />
8
 	<meta name="description" content="Ça fout le seum" />
8
 	<meta name="description" content="Ça fout le seum" />
9
 	<meta name="viewport" content="width=device-width, initial-scale=1.0">
9
 	<meta name="viewport" content="width=device-width, initial-scale=1.0">
10
-	<link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico"/>
10
+	<link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico" />
11
 	<title>SeumBook™ – {% block title %}{% endblock %}</title>
11
 	<title>SeumBook™ – {% block title %}{% endblock %}</title>
12
 
12
 
13
 	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
13
 	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
22
 			overflow: auto;
22
 			overflow: auto;
23
 		}
23
 		}
24
 
24
 
25
+		.primary-counter {
26
+			height: 215px;
27
+			overflow: auto;
28
+			display: flex;
29
+			align-items: center;
30
+		}
31
+
25
 		.timeline {
32
 		.timeline {
26
 			height: 125px;
33
 			height: 125px;
27
 		}
34
 		}
29
 		.graphs {
36
 		.graphs {
30
 			overflow-y: hidden;
37
 			overflow-y: hidden;
31
 		}
38
 		}
32
-		.graphs > div {
39
+
40
+		.graphs>div {
33
 			display: block;
41
 			display: block;
34
 			margin: 0 auto;
42
 			margin: 0 auto;
35
 		}
43
 		}
36
 
44
 
37
-		.counter-link, .counter-link:hover {
38
-  			color: inherit; /* blue colors for links too */
39
-  			text-decoration: inherit; /* no underline */
45
+		.counter-link,
46
+		.counter-link:hover {
47
+			color: inherit;
48
+			/* blue colors for links too */
49
+			text-decoration: inherit;
50
+			/* no underline */
40
 		}
51
 		}
41
 	</style>
52
 	</style>
42
 
53
 
47
 		});
58
 		});
48
 
59
 
49
 		function revealSeumForm(counterID) {
60
 		function revealSeumForm(counterID) {
50
-			document.getElementById('counter'+counterID).style.display='inline';
51
-			document.getElementById('button'+counterID).style.display='none';
52
-			document.getElementById('reason'+counterID).focus();
53
-			document.getElementById('container'+counterID).style.height='200px';
61
+			document.getElementById('counter' + counterID).style.display = 'inline';
62
+			document.getElementById('button' + counterID).style.display = 'none';
63
+			document.getElementById('reason' + counterID).focus();
54
 		}
64
 		}
55
 	</script>
65
 	</script>
56
 </head>
66
 </head>

+ 50 - 17
counter/templates/homeTemplate.html

4
 </div>
4
 </div>
5
 <div class="container-fluid">
5
 <div class="container-fluid">
6
 	<div class="row" id="my-counter">
6
 	<div class="row" id="my-counter">
7
-		<div class="col-sm-12">
7
+		<div class="col-sm-6">
8
 			<div class="panel panel-primary">
8
 			<div class="panel panel-primary">
9
 				<div class="panel-heading">
9
 				<div class="panel-heading">
10
 					<a class="counter-link" href="{% url 'counter' id_counter=myCounter.id %}">
10
 					<a class="counter-link" href="{% url 'counter' id_counter=myCounter.id %}">
13
 						</h2>
13
 						</h2>
14
 					</a>
14
 					</a>
15
 				</div>
15
 				</div>
16
-				<div class="seum-counter panel-body" id="container{{myCounter.id}}" style="height:125px">
17
-					{% if myCounter.lastReset.noSeum %}
18
-					<strong>N'a pas encore eu le seum.</strong>
19
-					<br> {% else %}
20
-					<strong>
16
+				<div class="primary-counter panel-body" id="container{{myCounter.id}}">
17
+					<div style="width:100%;">
18
+						{% if myCounter.lastReset.noSeum %}
19
+						<strong>N'a pas encore eu le seum.</strong>
20
+						<br> {% else %}
21
+						<strong>
21
 						{% if myCounter.lastReset.selfSeum %}
22
 						{% if myCounter.lastReset.selfSeum %}
22
 						J'ai eu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
23
 						J'ai eu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
23
 						{% else %}
24
 						{% else %}
24
 						{{myCounter.lastReset.who.trigramme}} m'a foutu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
25
 						{{myCounter.lastReset.who.trigramme}} m'a foutu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
25
 						{% endif %}
26
 						{% endif %}
26
 					</strong>
27
 					</strong>
27
-					<br> {% endif %}
28
+						<br> {% endif %}
28
 
29
 
29
-					<p>{{ myCounter.lastReset.reason }}</p>
30
-					<div class="text-center" id="button{{myCounter.id}}">
31
-						<button class="btn btn-default btn-danger" type="button" onclick="revealSeumForm({{myCounter.id}})">Remettre à zéro</button>
30
+						<p>{{ myCounter.lastReset.reason }}</p>
31
+						<div class="text-center" id="button{{myCounter.id}}">
32
+							<button class="btn btn-default btn-danger" type="button" onclick="revealSeumForm({{myCounter.id}})">Remettre à zéro</button>
33
+						</div>
34
+						<form style="display:none" id="counter{{myCounter.id}}" action="{% url 'reset-counter' %}" method="post">
35
+							{% csrf_token %}
36
+							<div class="form-group">
37
+								<label for="reason">Motif du seum</label>
38
+								<input id="reason{{myCounter.id}}" type="text" class="form-control" name="reason"></input>
39
+							</div>
40
+							<input type="hidden" name="counter" value="{{myCounter.id}}"></input>
41
+							<input type="hidden" name="redirect" value="{% url 'home' %}"></input>
42
+							<input type="hidden" name="who" value="{{myCounter.id}}"></input>
43
+							<div class="text-center">
44
+								<button type="submit" class="btn btn-default btn-success">J'ai le seum</button>
45
+							</div>
46
+						</form>
32
 					</div>
47
 					</div>
33
-					<form style="display:none" id="counter{{myCounter.id}}" action="{% url 'reset-counter' %}" method="post">
48
+				</div>
49
+			</div>
50
+		</div>
51
+		<div class="col-sm-6">
52
+			<div class="panel panel-primary">
53
+				<div class="panel-heading">
54
+					<h2 class="panel-title">QuickSeum™ <small>Brise le mur du seum</small></h2>
55
+				</div>
56
+				<div class="primary-counter panel-body">
57
+					<form class="form-horizontal" action="{% url 'reset-counter'%}" method="POST">
34
 						{% csrf_token %}
58
 						{% csrf_token %}
35
 						<div class="form-group">
59
 						<div class="form-group">
36
-							<label for="reason">Motif du seum :</label>
37
-							<input id="reason{{myCounter.id}}" type="text" class="form-control" name="reason"></input>
60
+							<label for="id_quicktrigramme" class="col-sm-3 control-label">Trigramme</label>
61
+							<div class="col-sm-9">
62
+								<input id="id_quicktrigramme" maxlength="3" type="text" class="form-control text-uppercase" name="trigramme" onkeyup="this.value=this.value.toUpperCase();" required />
63
+							</div>
64
+						</div>
65
+						<div class="form-group">
66
+							<label for="id_quickreason" class="col-sm-3 control-label">Motif</label>
67
+							<div class="col-sm-9">
68
+								<input type="text" class="form-control" id="id_quickreason" name="reason" />
69
+							</div>
70
+						</div>
71
+						<div class="form-group">
72
+							<div class="col-sm-offset-3 col-sm-9">
73
+								<button type="submit" class="btn btn-danger">Foutre le seum</button>
74
+							</div>
38
 						</div>
75
 						</div>
39
 						<input type="hidden" name="counter" value="{{myCounter.id}}"></input>
76
 						<input type="hidden" name="counter" value="{{myCounter.id}}"></input>
40
 						<input type="hidden" name="redirect" value="{% url 'home' %}"></input>
77
 						<input type="hidden" name="redirect" value="{% url 'home' %}"></input>
41
-						<input type="hidden" name="who" value="{{myCounter.id}}"></input>
42
-						<div class="text-center">
43
-							<button type="submit" class="btn btn-default btn-success">J'ai le seum</button>
44
-						</div>
45
 					</form>
78
 					</form>
46
 				</div>
79
 				</div>
47
 			</div>
80
 			</div>

+ 14 - 2
counter/views.py

241
     if (request.method == 'POST'):
241
     if (request.method == 'POST'):
242
         # create a form instance and populate it with data from the request:
242
         # create a form instance and populate it with data from the request:
243
         data = dict(request.POST)
243
         data = dict(request.POST)
244
+
244
         counter = Counter.objects.get(pk=int(data['counter'][0]))
245
         counter = Counter.objects.get(pk=int(data['counter'][0]))
245
-        who = Counter.objects.get(pk=int(data['who'][0]))
246
+        if 'who' in data.keys():
247
+            who = Counter.objects.get(pk=int(data['who'][0]))
248
+        else:
249
+            try:
250
+                who = Counter.objects.get(trigramme=data['trigramme'][0])
251
+            except Counter.DoesNotExist:
252
+                return HttpResponseRedirect(data['redirect'][0])
246
         reset = Reset()
253
         reset = Reset()
247
         reset.counter = counter
254
         reset.counter = counter
248
         reset.who = who
255
         reset.who = who
249
         reset.reason = data['reason'][0]
256
         reset.reason = data['reason'][0]
250
         reset.timestamp = datetime.now()
257
         reset.timestamp = datetime.now()
258
+
259
+        # we check that the seumer is the autenticated user
260
+        if reset.counter.id != request.user.id:
261
+            return HttpResponseRedirect(data['redirect'][0])
262
+
251
         reset.save()
263
         reset.save()
252
         # We send the emails only to those who want
264
         # We send the emails only to those who want
253
         emails = [u.email for u in Counter.objects.all()
265
         emails = [u.email for u in Counter.objects.all()
269
             text_of_email,
281
             text_of_email,
270
             'SeumMan <seum@merigoux.ovh>', emails, [],
282
             'SeumMan <seum@merigoux.ovh>', emails, [],
271
             reply_to=emails)
283
             reply_to=emails)
272
-    email_to_send.send(fail_silently=True)
284
+        email_to_send.send(fail_silently=True)
273
 
285
 
274
     return HttpResponseRedirect(data['redirect'][0])
286
     return HttpResponseRedirect(data['redirect'][0])
275
 
287