Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
42dd7983
authored
Feb 26, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: get notifications with ajax
parent
e62d7a9b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
29 deletions
+16
-29
circle/dashboard/static/dashboard/dashboard.js
+1
-12
circle/dashboard/templates/dashboard/_notifications-timeline.html
+5
-0
circle/dashboard/templates/dashboard/index.html
+2
-2
circle/dashboard/views.py
+8
-15
No files found.
circle/dashboard/static/dashboard/dashboard.js
View file @
42dd7983
...
@@ -212,19 +212,8 @@ $(function () {
...
@@ -212,19 +212,8 @@ $(function () {
return
false
;
return
false
;
});
});
/* notification read */
$
(
"#notification-button"
).
click
(
function
()
{
$
(
"#notification-button"
).
click
(
function
()
{
$
.
ajax
({
$
(
'.notification-messages'
).
load
(
"/dashboard/notifications/"
);
type
:
"POST"
,
url
:
"/dashboard/notifications/"
,
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)},
success
:
function
(
re
,
textStatus
,
xhr
)
{
//console.log("success");
},
error
:
function
(
xhr
,
textStatus
,
error
)
{
addMessage
(
'Uh oh :('
,
'danger'
)
}
});
});
});
});
});
...
...
circle/dashboard/templates/dashboard/_notifications-timeline.html
View file @
42dd7983
{% load i18n %}
{% for n in notifications %}
{% for n in notifications %}
<li
class=
"notification-message"
>
<li
class=
"notification-message"
>
<span
class=
"notification-message-subject"
>
<span
class=
"notification-message-subject"
>
...
@@ -12,4 +13,8 @@
...
@@ -12,4 +13,8 @@
{{ n.message }}
{{ n.message }}
</div>
</div>
</li>
</li>
{% empty %}
<li
class=
"notification-message"
>
{% trans "You have no notifications." %}
</li>
{% endfor %}
{% endfor %}
circle/dashboard/templates/dashboard/index.html
View file @
42dd7983
...
@@ -6,10 +6,10 @@
...
@@ -6,10 +6,10 @@
{% block navbar-ul %}
{% block navbar-ul %}
<li
class=
"dropdown"
id=
"notification-button"
>
<li
class=
"dropdown"
id=
"notification-button"
>
<a
href=
"{% url "
dashboard
.
views
.
notifications
"
%}"
style=
"color: white; font-size: 12px;"
class=
"dropdown-toggle"
data-toggle=
"dropdown"
>
<a
href=
"{% url "
dashboard
.
views
.
notifications
"
%}"
style=
"color: white; font-size: 12px;"
class=
"dropdown-toggle"
data-toggle=
"dropdown"
>
Notifications{% if new_notifications
> 0
%}
<span
class=
"badge"
>
{{ new_notifications }}
</span>
{% endif %}
Notifications{% if new_notifications %}
<span
class=
"badge"
>
{{ new_notifications }}
</span>
{% endif %}
</a>
</a>
<ul
class=
"dropdown-menu notification-messages"
>
<ul
class=
"dropdown-menu notification-messages"
>
{% include "dashboard/_notifications-timeline.html" %}
<li>
{% trans "Loading..." %}
</li>
</ul>
</ul>
</li>
</li>
{% endblock %}
{% endblock %}
...
...
circle/dashboard/views.py
View file @
42dd7983
...
@@ -82,7 +82,6 @@ class IndexView(LoginRequiredMixin, TemplateView):
...
@@ -82,7 +82,6 @@ class IndexView(LoginRequiredMixin, TemplateView):
})
})
if
user
is
not
None
:
if
user
is
not
None
:
context
[
'notifications'
]
=
user
.
notification_set
.
all
()[:
10
]
context
[
'new_notifications'
]
=
user
.
notification_set
.
filter
(
context
[
'new_notifications'
]
=
user
.
notification_set
.
filter
(
status
=
"new"
)
.
count
()
status
=
"new"
)
.
count
()
...
@@ -1660,7 +1659,12 @@ class NodeGraphView(SuperuserRequiredMixin, GraphViewBase):
...
@@ -1660,7 +1659,12 @@ class NodeGraphView(SuperuserRequiredMixin, GraphViewBase):
class
NotificationView
(
LoginRequiredMixin
,
TemplateView
):
class
NotificationView
(
LoginRequiredMixin
,
TemplateView
):
template_name
=
"dashboard/notifications.html"
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/_notifications-timeline.html'
]
else
:
return
[
'dashboard/notifications.html'
]
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
NotificationView
,
self
)
.
get_context_data
(
context
=
super
(
NotificationView
,
self
)
.
get_context_data
(
...
@@ -1668,8 +1672,9 @@ class NotificationView(LoginRequiredMixin, TemplateView):
...
@@ -1668,8 +1672,9 @@ class NotificationView(LoginRequiredMixin, TemplateView):
# we need to convert it to list, otherwise it's gonna be
# we need to convert it to list, otherwise it's gonna be
# similar to a QuerySet and update everything to
# similar to a QuerySet and update everything to
# read status after get
# read status after get
n
=
10
if
self
.
request
.
is_ajax
()
else
1000
context
[
'notifications'
]
=
list
(
context
[
'notifications'
]
=
list
(
self
.
request
.
user
.
notification_set
.
values
())
self
.
request
.
user
.
notification_set
.
values
()
[:
n
]
)
return
context
return
context
def
get
(
self
,
*
args
,
**
kwargs
):
def
get
(
self
,
*
args
,
**
kwargs
):
...
@@ -1679,15 +1684,3 @@ class NotificationView(LoginRequiredMixin, TemplateView):
...
@@ -1679,15 +1684,3 @@ class NotificationView(LoginRequiredMixin, TemplateView):
u
.
status
=
"read"
u
.
status
=
"read"
u
.
save
()
u
.
save
()
return
response
return
response
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# unread notifications
un
=
request
.
user
.
notification_set
.
filter
(
status
=
"new"
)
for
u
in
un
:
u
.
status
=
"read"
u
.
save
()
if
request
.
is_ajax
():
return
HttpResponse
({
'result'
:
'ok'
})
else
:
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment