def test_confirm_view(self): """ Test the "confirm" view """ url = get_confirm_url_for_object(self.model_without_author) # not authenticated resp = self.client.get(url) self.assertTrue(isinstance(resp, HttpResponseRedirect)) self.assertTrue('?next=%s' % url in resp['Location']) # authenticated user self.client.login(username=self.user.username, password=self.USER_BASE) resp = self.client.get(url) self.assertEqual(resp.status_code, 200) self.assertTrue(isinstance(resp.context['form'], FlagForm)) self.assertEqual(resp.context['next'], url) # already flagged object FlagInstance.objects.add(self.user, self.model_without_author, comment='comment') resp = self.client.get(url) self.assertEqual(resp.status_code, 200) # with limit flag_settings.LIMIT_SAME_OBJECT_FOR_USER = 1 resp = self.client.get(url) self.assertEqual(resp.status_code, 302) flag_settings.LIMIT_SAME_OBJECT_FOR_USER = 0 # bad content object resp = self.client.get('/flag/foo/bar/1000/') self.assertTrue(isinstance(resp, FlagBadRequest)) # test with_status url_with_status = get_confirm_url_for_object(self.model_without_author, with_status=True) # user is not staff resp = self.client.get(url_with_status) self.assertEqual(resp.status_code, 400) # user is staff self.client.logout() self.client.login(username=self.staff_user, password=self.USER_BASE) resp = self.client.get(url_with_status) self.assertEqual(resp.status_code, 200)
def flag_confirm_url(content_object, creator_field=None): """ This filter will return the url of the flag confirm page for the given object Usage: {{ some_object|flag_confirm_url }} Or, with a creator_field : {{ some_object|flag_confirm_url:"some_field" }} """ try: return get_confirm_url_for_object(content_object, creator_field, False) except: return ""
def flag_confirm_url_with_status(content_object, creator_field=None): """ This filter will return the url of the flag confirm page for the given object. The difference with `flag_confirm_url` is that in this form the user will ne able to choose the flag's status Usage: {{ some_object|flag_confirm_url_with_status }} Or, with a creator_field : {{ some_object|flag_confirm_url_with_status:"some_field" }} """ try: return get_confirm_url_for_object(content_object, creator_field, True) except: return ""