Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Removed __call__ from FlashScope in order to avoid problems in Django…
Browse files Browse the repository at this point in the history
… 1.3.
  • Loading branch information
danielfm committed Feb 12, 2011
1 parent f169786 commit 8567a66
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
20 changes: 1 addition & 19 deletions src/djangoflash/models.py
Expand Up @@ -99,12 +99,6 @@ def __delitem__(self, key):
if key in self._used:
del self._used[key]

def __call__(self, **kwargs):
"""Puts one or more values into this flash.
"""
for key, value in kwargs.items():
self[key] = value

def __len__(self):
"""Returns the number of values inside this flash.
"""
Expand Down Expand Up @@ -178,9 +172,6 @@ def pop(self, key, default=None):

def put(self, **kwargs):
"""Puts one or more values into this flash.
.. deprecated :: 1.7.1
:meth:`put` is deprecated in favor of ``flash(key=value)``.
"""
for key, value in kwargs.items():
self[key] = value
Expand All @@ -205,15 +196,6 @@ def clear(self):
self._session.clear()
self._used.clear()

def put_immediate(self, key, value):
"""Puts a value inside this flash and marks it as *used*.
.. deprecated :: 1.7.1
:meth:`put_immediate` is deprecated in favor of ``flash.now[key] = value``.
"""
self[key] = value
self._update_status(key)

def discard(self, *keys):
"""Marks the entire current flash or a single value as *used*, so when
the next request hit the server, those values will be automatically
Expand Down Expand Up @@ -296,7 +278,7 @@ def __setitem__(self, key, value):
self.delegate[key] = value
self.delegate.discard(key)

def __call__(self, **kwargs):
def put(self, **kwargs):
"""Puts one or more values into this flash.
"""
for key, value in kwargs.items():
Expand Down
9 changes: 1 addition & 8 deletions src/djangoflash/tests/models.py
Expand Up @@ -195,13 +195,6 @@ def test_put(self):
self.assertEqual('Warning', self.flash['warn'])
self.assertEqual('Error', self.flash['error'])

def test_new_put(self):
"""FlashScope: Should put several keys into the flash scope at the same time (new way).
"""
self.flash(warn='Warning', error='Error')
self.assertEqual('Warning', self.flash['warn'])
self.assertEqual('Error', self.flash['error'])

def test_discard(self):
"""FlashScope: Should mark a value for removal.
"""
Expand Down Expand Up @@ -287,7 +280,7 @@ def test_now(self):
def test_alternative_now(self):
"""FlashScope.now: Immediate values (flash.now) should be supported.
"""
self.flash.now(error='Error')
self.flash.now.put(error='Error')
self.assertEqual('Error', self.flash['error'])
self.flash.update()
self.assertFalse('error' in self.flash)
Expand Down
17 changes: 17 additions & 0 deletions src/djangoflash/tests/testproj/app/tests.py
Expand Up @@ -36,6 +36,23 @@ def test_default_lifecycle(self):
self.response = self.client.get(reverse(views.render_template))
self.assertFalse('message' in self._flash())

def test_value_in_template(self):
"""Integration: a value should be accessible by the templating system.
"""
def _assert_content(content, exists=True):
matcher = self.assertTrue if exists else self.assertFalse
matcher(self.response.content.find(content) > 0)

self.response = self.client.get(reverse(views.set_flash_var))
_assert_content('Flash context: Message', exists=True)

self.response = self.client.get(reverse(views.render_template))
_assert_content('Flash context: Message', exists=True)

# Flash value will be removed when this request hits the app
self.response = self.client.get(reverse(views.render_template))
_assert_content('Flash context: Message', exists=False)

def test_keep_lifecycle(self):
"""Integration: a value shouldn't be removed from the flash when it is kept.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/djangoflash/tests/testproj/templates/simple.html
Expand Up @@ -3,7 +3,7 @@
<title>Simple template</title>
</head>
<body>
<!-- Just some content, not used in unittests -->
<!-- Used in unittest, do not change -->
Flash context: {{ flash.message }}
</body>
</html>

2 comments on commit 8567a66

@nicpottier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bummer, I really loved the old syntax. What was the problem caused by Django 1.3?

@danielfm
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the issue that caused this change: http://code.djangoproject.com/ticket/15265

Please sign in to comment.