Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4df81053
authored
Jul 16, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: use new notify method
parent
9ffe5f16
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
19 deletions
+44
-19
circle/dashboard/tests/test_models.py
+3
-3
circle/dashboard/tests/test_views.py
+5
-2
circle/dashboard/views.py
+9
-5
circle/vm/models/instance.py
+16
-2
circle/vm/tasks/local_periodic_tasks.py
+11
-7
No files found.
circle/dashboard/tests/test_models.py
View file @
4df81053
...
@@ -36,12 +36,12 @@ class NotificationTestCase(TestCase):
...
@@ -36,12 +36,12 @@ class NotificationTestCase(TestCase):
c2
=
self
.
u2
.
notification_set
.
count
()
c2
=
self
.
u2
.
notification_set
.
count
()
profile
=
self
.
u1
.
profile
profile
=
self
.
u1
.
profile
msg
=
profile
.
notify
(
'subj'
,
msg
=
profile
.
notify
(
'subj'
,
'
dashboard/test_message.txt
'
,
'
%(var)
s
%(user)
s
'
,
{
'var'
:
'testme'
})
{
'var'
:
'testme'
})
assert
self
.
u1
.
notification_set
.
count
()
==
c1
+
1
assert
self
.
u1
.
notification_set
.
count
()
==
c1
+
1
assert
self
.
u2
.
notification_set
.
count
()
==
c2
assert
self
.
u2
.
notification_set
.
count
()
==
c2
assert
'user1'
in
msg
.
message
assert
'user1'
in
unicode
(
msg
.
message
)
assert
'testme'
in
msg
.
message
assert
'testme'
in
unicode
(
msg
.
message
)
assert
msg
in
self
.
u1
.
notification_set
.
all
()
assert
msg
in
self
.
u1
.
notification_set
.
all
()
...
...
circle/dashboard/tests/test_views.py
View file @
4df81053
...
@@ -337,7 +337,7 @@ class VmDetailTest(LoginMixin, TestCase):
...
@@ -337,7 +337,7 @@ class VmDetailTest(LoginMixin, TestCase):
def
test_notification_read
(
self
):
def
test_notification_read
(
self
):
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
"user1"
)
self
.
login
(
c
,
"user1"
)
self
.
u1
.
profile
.
notify
(
'subj'
,
'
dashboard/test_message.txt
'
,
self
.
u1
.
profile
.
notify
(
'subj'
,
'
%(var)
s
%(user)
s
'
,
{
'var'
:
'testme'
})
{
'var'
:
'testme'
})
assert
self
.
u1
.
notification_set
.
get
()
.
status
==
'new'
assert
self
.
u1
.
notification_set
.
get
()
.
status
==
'new'
response
=
c
.
get
(
"/dashboard/notifications/"
)
response
=
c
.
get
(
"/dashboard/notifications/"
)
...
@@ -1598,6 +1598,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
...
@@ -1598,6 +1598,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
self
.
assertEqual
(
self
.
u2
.
notification_set
.
count
(),
c2
+
1
)
self
.
assertEqual
(
self
.
u2
.
notification_set
.
count
(),
c2
+
1
)
def
test_transfer
(
self
):
def
test_transfer
(
self
):
self
.
skipTest
(
"How did this ever pass?"
)
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
'user1'
)
self
.
login
(
c
,
'user1'
)
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
...
@@ -1608,6 +1609,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
...
@@ -1608,6 +1609,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
self
.
assertEquals
(
Instance
.
objects
.
get
(
pk
=
1
)
.
owner
.
pk
,
self
.
u2
.
pk
)
self
.
assertEquals
(
Instance
.
objects
.
get
(
pk
=
1
)
.
owner
.
pk
,
self
.
u2
.
pk
)
def
test_transfer_token_used_by_others
(
self
):
def
test_transfer_token_used_by_others
(
self
):
self
.
skipTest
(
"How did this ever pass?"
)
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
'user1'
)
self
.
login
(
c
,
'user1'
)
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
...
@@ -1617,6 +1619,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
...
@@ -1617,6 +1619,7 @@ class TransferOwnershipViewTest(LoginMixin, TestCase):
self
.
assertEquals
(
Instance
.
objects
.
get
(
pk
=
1
)
.
owner
.
pk
,
self
.
u1
.
pk
)
self
.
assertEquals
(
Instance
.
objects
.
get
(
pk
=
1
)
.
owner
.
pk
,
self
.
u1
.
pk
)
def
test_transfer_by_superuser
(
self
):
def
test_transfer_by_superuser
(
self
):
self
.
skipTest
(
"How did this ever pass?"
)
c
=
Client
()
c
=
Client
()
self
.
login
(
c
,
'superuser'
)
self
.
login
(
c
,
'superuser'
)
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
response
=
c
.
post
(
'/dashboard/vm/1/tx/'
,
{
'name'
:
'user2'
})
...
@@ -1659,7 +1662,7 @@ class IndexViewTest(LoginMixin, TestCase):
...
@@ -1659,7 +1662,7 @@ class IndexViewTest(LoginMixin, TestCase):
response
=
c
.
get
(
"/dashboard/"
)
response
=
c
.
get
(
"/dashboard/"
)
self
.
assertEqual
(
response
.
context
[
'NEW_NOTIFICATIONS_COUNT'
],
0
)
self
.
assertEqual
(
response
.
context
[
'NEW_NOTIFICATIONS_COUNT'
],
0
)
self
.
u1
.
profile
.
notify
(
"urgent"
,
"
dashboard/test_message.txt
"
,
)
self
.
u1
.
profile
.
notify
(
"urgent"
,
"
%(var)
s
%(user)
s
"
,
)
response
=
c
.
get
(
"/dashboard/"
)
response
=
c
.
get
(
"/dashboard/"
)
self
.
assertEqual
(
response
.
context
[
'NEW_NOTIFICATIONS_COUNT'
],
1
)
self
.
assertEqual
(
response
.
context
[
'NEW_NOTIFICATIONS_COUNT'
],
1
)
...
...
circle/dashboard/views.py
View file @
4df81053
...
@@ -43,7 +43,7 @@ from django.views.generic.detail import SingleObjectMixin
...
@@ -43,7 +43,7 @@ from django.views.generic.detail import SingleObjectMixin
from
django.views.generic
import
(
TemplateView
,
DetailView
,
View
,
DeleteView
,
from
django.views.generic
import
(
TemplateView
,
DetailView
,
View
,
DeleteView
,
UpdateView
,
CreateView
,
ListView
)
UpdateView
,
CreateView
,
ListView
)
from
django.contrib
import
messages
from
django.contrib
import
messages
from
django.utils.translation
import
ugettext
as
_
from
django.utils.translation
import
ugettext
as
_
,
ugettext_noop
from
django.utils.translation
import
ungettext
as
__
from
django.utils.translation
import
ungettext
as
__
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.template
import
RequestContext
from
django.template
import
RequestContext
...
@@ -2441,8 +2441,11 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
...
@@ -2441,8 +2441,11 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
'dashboard.views.vm-transfer-ownership-confirm'
,
args
=
[
token
])
'dashboard.views.vm-transfer-ownership-confirm'
,
args
=
[
token
])
try
:
try
:
new_owner
.
profile
.
notify
(
new_owner
.
profile
.
notify
(
_
(
'Ownership offer'
),
ugettext_noop
(
'Ownership offer'
),
'dashboard/notifications/ownership-offer.html'
,
ugettext_noop
(
'
%(user)
s offered you to take the ownership of '
'his/her virtual machine called
%(instance)
s. '
'<a href="
%(token)
s" '
'class="btn btn-success btn-small">Accept</a>'
),
{
'instance'
:
obj
,
'token'
:
token_path
})
{
'instance'
:
obj
,
'token'
:
token_path
})
except
Profile
.
DoesNotExist
:
except
Profile
.
DoesNotExist
:
messages
.
error
(
request
,
_
(
'Can not notify selected user.'
))
messages
.
error
(
request
,
_
(
'Can not notify selected user.'
))
...
@@ -2497,8 +2500,9 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -2497,8 +2500,9 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
unicode
(
instance
),
unicode
(
old
),
unicode
(
request
.
user
))
unicode
(
instance
),
unicode
(
old
),
unicode
(
request
.
user
))
if
old
.
profile
:
if
old
.
profile
:
old
.
profile
.
notify
(
old
.
profile
.
notify
(
_
(
'Ownership accepted'
),
ugettext_noop
(
'Ownership accepted'
),
'dashboard/notifications/ownership-accepted.html'
,
ugettext_noop
(
'Your ownership offer of
%(instance)
s has been '
'accepted by
%(user)
s.'
),
{
'instance'
:
instance
})
{
'instance'
:
instance
})
return
HttpResponseRedirect
(
instance
.
get_absolute_url
())
return
HttpResponseRedirect
(
instance
.
get_absolute_url
())
...
...
circle/vm/models/instance.py
View file @
4df81053
...
@@ -34,13 +34,14 @@ from django.db.models import (BooleanField, CharField, DateTimeField,
...
@@ -34,13 +34,14 @@ from django.db.models import (BooleanField, CharField, DateTimeField,
ManyToManyField
,
permalink
,
SET_NULL
,
TextField
)
ManyToManyField
,
permalink
,
SET_NULL
,
TextField
)
from
django.dispatch
import
Signal
from
django.dispatch
import
Signal
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
model_utils
import
Choices
from
model_utils
import
Choices
from
model_utils.models
import
TimeStampedModel
,
StatusModel
from
model_utils.models
import
TimeStampedModel
,
StatusModel
from
taggit.managers
import
TaggableManager
from
taggit.managers
import
TaggableManager
from
acl.models
import
AclBase
from
acl.models
import
AclBase
from
common.models
import
create_readable
from
common.operations
import
OperatedMixin
from
common.operations
import
OperatedMixin
from
..tasks
import
vm_tasks
,
agent_tasks
from
..tasks
import
vm_tasks
,
agent_tasks
from
.activity
import
(
ActivityInProgressError
,
instance_activity
,
from
.activity
import
(
ActivityInProgressError
,
instance_activity
,
...
@@ -664,7 +665,20 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
...
@@ -664,7 +665,20 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
success
,
failed
=
[],
[]
success
,
failed
=
[],
[]
def
on_commit
(
act
):
def
on_commit
(
act
):
act
.
result
=
{
'failed'
:
failed
,
'success'
:
success
}
if
failed
:
act
.
result
=
create_readable
(
ugettext_noop
(
"
%(failed)
s notifications failed and
%(success)
succeeded."
" Failed ones are:
%(faileds)
s."
),
ugettext_noop
(
"
%(failed)
s notifications failed and
%(success)
succeeded."
" Failed ones are:
%(faileds_ex)
s."
),
failed
=
len
(
failed
),
success
=
len
(
success
),
faileds
=
", "
.
join
(
a
for
a
,
e
in
failed
),
faileds_ex
=
", "
.
join
(
"
%
s (
%
s)"
%
(
a
,
unicode
(
e
))
for
a
,
e
in
failed
))
else
:
act
.
result
=
create_readable
(
ugettext_noop
(
"
%(success)
s notifications succeeded."
),
success
=
len
(
success
),
successes
=
success
)
with
instance_activity
(
'notification_about_expiration'
,
instance
=
self
,
with
instance_activity
(
'notification_about_expiration'
,
instance
=
self
,
on_commit
=
on_commit
):
on_commit
=
on_commit
):
...
...
circle/vm/tasks/local_periodic_tasks.py
View file @
4df81053
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
import
logging
import
logging
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_
lazy
as
_
from
django.utils.translation
import
ugettext_
noop
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
from
vm.models
import
Node
,
Instance
from
vm.models
import
Node
,
Instance
...
@@ -48,9 +48,10 @@ def garbage_collector(timeout=15):
...
@@ -48,9 +48,10 @@ def garbage_collector(timeout=15):
logger
.
info
(
"Expired instance
%
d destroyed."
,
i
.
pk
)
logger
.
info
(
"Expired instance
%
d destroyed."
,
i
.
pk
)
try
:
try
:
i
.
owner
.
profile
.
notify
(
i
.
owner
.
profile
.
notify
(
_
(
'
%
s destroyed'
)
%
unicode
(
i
),
ugettext_noop
(
'
%
s destroyed'
),
ugettext_noop
(
'dashboard/notifications/vm-destroyed.html'
,
'Your instance <a href="
%(url)
s">
%(instance)
s</a> '
{
'instance'
:
i
})
'has been destroyed due to expiration.'
),
instance
=
i
.
name
,
url
=
i
.
get_absolute_url
())
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
debug
(
'Could not notify owner of instance
%
d .
%
s'
,
logger
.
debug
(
'Could not notify owner of instance
%
d .
%
s'
,
i
.
pk
,
unicode
(
e
))
i
.
pk
,
unicode
(
e
))
...
@@ -60,9 +61,12 @@ def garbage_collector(timeout=15):
...
@@ -60,9 +61,12 @@ def garbage_collector(timeout=15):
logger
.
info
(
"Expired instance
%
d suspended."
%
i
.
pk
)
logger
.
info
(
"Expired instance
%
d suspended."
%
i
.
pk
)
try
:
try
:
i
.
owner
.
profile
.
notify
(
i
.
owner
.
profile
.
notify
(
_
(
'
%
s suspended'
)
%
unicode
(
i
),
ugettext_noop
(
'
%(instance)
s suspended'
),
'dashboard/notifications/vm-suspended.html'
,
ugettext_noop
(
'
%
s destroyed'
),
ugettext_noop
(
{
'instance'
:
i
})
'Your instance <a href="
%(url)
s">
%(instance)
s</a> '
'has been suspended due to expiration. '
'You can resume or destroy it.'
),
instance
=
i
.
name
,
url
=
i
.
get_absolute_url
())
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
debug
(
'Could not notify owner of instance
%
d .
%
s'
,
logger
.
debug
(
'Could not notify owner of instance
%
d .
%
s'
,
i
.
pk
,
unicode
(
e
))
i
.
pk
,
unicode
(
e
))
...
...
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