Procházet zdrojové kódy

Added QuickSeum form

Denis Merigoux před 9 roky
rodič
revize
c2783d6d66

+ 19 - 9
counter/templates/baseTemplate.html

@@ -7,7 +7,7 @@
7 7
 	<meta name="keywords" content="seum compteur" />
8 8
 	<meta name="description" content="Ça fout le seum" />
9 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 11
 	<title>SeumBook™ – {% block title %}{% endblock %}</title>
12 12
 
13 13
 	{# Load the tag library #} {% load bootstrap3 %} {# Load CSS and JavaScript #} {% bootstrap_css %} {# Display django.contrib.messages as Bootstrap alerts #} {% bootstrap_messages %}
@@ -22,6 +22,13 @@
22 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 32
 		.timeline {
26 33
 			height: 125px;
27 34
 		}
@@ -29,14 +36,18 @@
29 36
 		.graphs {
30 37
 			overflow-y: hidden;
31 38
 		}
32
-		.graphs > div {
39
+
40
+		.graphs>div {
33 41
 			display: block;
34 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 52
 	</style>
42 53
 
@@ -47,10 +58,9 @@
47 58
 		});
48 59
 
49 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 65
 	</script>
56 66
 </head>

+ 50 - 17
counter/templates/homeTemplate.html

@@ -4,7 +4,7 @@
4 4
 </div>
5 5
 <div class="container-fluid">
6 6
 	<div class="row" id="my-counter">
7
-		<div class="col-sm-12">
7
+		<div class="col-sm-6">
8 8
 			<div class="panel panel-primary">
9 9
 				<div class="panel-heading">
10 10
 					<a class="counter-link" href="{% url 'counter' id_counter=myCounter.id %}">
@@ -13,35 +13,68 @@
13 13
 						</h2>
14 14
 					</a>
15 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 22
 						{% if myCounter.lastReset.selfSeum %}
22 23
 						J'ai eu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
23 24
 						{% else %}
24 25
 						{{myCounter.lastReset.who.trigramme}} m'a foutu le seum il y a {{ myCounter.lastReset.formatted_delta }}.
25 26
 						{% endif %}
26 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 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 58
 						{% csrf_token %}
35 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 75
 						</div>
39 76
 						<input type="hidden" name="counter" value="{{myCounter.id}}"></input>
40 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 78
 					</form>
46 79
 				</div>
47 80
 			</div>

+ 14 - 2
counter/views.py

@@ -241,13 +241,25 @@ def resetCounter(request):
241 241
     if (request.method == 'POST'):
242 242
         # create a form instance and populate it with data from the request:
243 243
         data = dict(request.POST)
244
+
244 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 253
         reset = Reset()
247 254
         reset.counter = counter
248 255
         reset.who = who
249 256
         reset.reason = data['reason'][0]
250 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 263
         reset.save()
252 264
         # We send the emails only to those who want
253 265
         emails = [u.email for u in Counter.objects.all()
@@ -269,7 +281,7 @@ def resetCounter(request):
269 281
             text_of_email,
270 282
             'SeumMan <seum@merigoux.ovh>', emails, [],
271 283
             reply_to=emails)
272
-    email_to_send.send(fail_silently=True)
284
+        email_to_send.send(fail_silently=True)
273 285
 
274 286
     return HttpResponseRedirect(data['redirect'][0])
275 287