Browse Source

Module notifications (suite)

omassot 7 years ago
parent
commit
0ae7aa7e70
4 changed files with 69 additions and 10 deletions
  1. 1 1
      main/models.py
  2. 45 0
      main/static/css/custom.css
  3. 10 8
      main/templates/_layout.html
  4. 13 1
      main/views.py

+ 1 - 1
main/models.py

@@ -132,7 +132,7 @@ class Epic(BaseModel):
         
 class Sprint(BaseModel):
     class Meta:
-        verbose_name_plural = "sprint"
+        verbose_name = "sprint"
         verbose_name_plural = "sprints"
         ordering = ('-date_start', )
     date_start = models.DateField()

+ 45 - 0
main/static/css/custom.css

@@ -230,6 +230,51 @@ select[multiple] option {
 /* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
 .show {display:block;} 
 
+/* Notifications */
+.notif-list {
+	max-height: 400px; 
+	overflow: auto;
+	margin-bottom: 0.5em;
+}
+
+.notif {
+	margin: 0.5em;
+	line-height: 2em;
+}
+
+.notif-head {
+	display: flex;
+	flex-direction: row;
+	text-align: left;
+}
+
+.notif-head a {
+	color: #a6a6a6;
+	padding: 0.1 em 0.2em;
+}
+
+.notif-content {
+	display: flex;
+	flex-direction: row;
+	justify-content: space-around;
+}
+
+.notif-content a {
+	color: #4183c4;
+	margin: 0;
+	padding: 0;
+}
+
+.notif-footer {
+	line-height: 1.5em;
+	margin-bottom: 1em;
+}
+
+.notif-footer a {
+	color: #4183c4;
+}
+
+
 /* Main */
 
 #main-pannel {

+ 10 - 8
main/templates/_layout.html

@@ -64,20 +64,22 @@
 	        			</a>
 	        		
 						<div id="notif-dropdown" class="dropdown-content">
-							<ul class="alt notif-list" style="margin-bottom: 0.5em;">
+							<ul class="alt notif-list" style="">
 							{% for notification in request.user.notifications.unread %}
 								<li class="notif">
-									<span class="flex-row" style="line-height: 2em;">
-										<i class="flex-extend"style="text-align:left; margin-left: 0.5em; padding: 3px;">Il y a {{ notification.timesince }}</i>
-										<a href="" class="notif-seen"><i class="fa fa-check"></i> Vu</a>
+									<span class="notif-head">
+										<i class="flex-extend">Il y a {{ notification.timesince }}</i>
+										<a href="" class="notif-seen"><i class="fa fa-times"></i></a>
+									</span>
+									<span class="notif-content">
+										<span>{{ notification.verb|safe }}</span>
 									</span>
-									<span class="flex-row flex-space-around" style="padding: 0 1em;line-height: 2em;">{{ notification.description }}</span>
 								</li>
 							{% endfor %}
-								<li class="flex-row flex-space-around" style="line-height: 2em;padding:0;">
-									<a href="" class="notif-all-seen">Tout marquer comme vu</a>
-								</li>
 							</ul>
+							<div class="notif-footer">
+								<a href="" class="notif-all-seen">Marquer tout comme vu</a>
+							</div>
 						</div>
 					</div>
 	        		

+ 13 - 1
main/views.py

@@ -7,6 +7,7 @@ from django.contrib.auth.models import User
 from django.core.paginator import Paginator
 from django.http.response import HttpResponse
 from django.shortcuts import render, get_object_or_404, redirect
+from django.urls.base import reverse
 from notifications.signals import notify
 
 from main.forms import StoryForm, EpicForm, RegisterForm, ProfileForm, \
@@ -303,8 +304,19 @@ def comment_post(request):
     form = CommentForm(request.POST)
     if form.is_valid():
         comment = form.save(commit=False)
-        comment.author = get_object_or_404(User, username=request.user)
+        comment.author = request.user
         comment.save()
+        
+        obj = comment.content_object
+        notify.send(request.user, 
+                    recipient=obj.contributors(), 
+                    action_object = obj,
+                    verb="{} a commenté <a href='{}#a-comment-{}'>{} #{}</a>".format(request.user.username, 
+                                                                        reverse('{}_details'.format(obj.model_name().lower()), args=(obj.id,)),
+                                                                        comment.id,
+                                                                        obj.model_name(), 
+                                                                        obj.id))
+        
         return redirect(request.META['HTTP_REFERER'].split("#")[0] + "#a-comment-{}".format(comment.id))
     else:
         return redirect(request.META['HTTP_REFERER'])